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
35 /* for MovePlayer() */
36 #define MF_NO_ACTION 0
40 /* for ScrollPlayer() */
42 #define SCROLL_GO_ON 1
45 #define EX_PHASE_START 0
46 #define EX_TYPE_NONE 0
47 #define EX_TYPE_NORMAL (1 << 0)
48 #define EX_TYPE_CENTER (1 << 1)
49 #define EX_TYPE_BORDER (1 << 2)
50 #define EX_TYPE_CROSS (1 << 3)
51 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
53 /* special positions in the game control window (relative to control window) */
56 #define XX_EMERALDS 29
57 #define YY_EMERALDS 54
58 #define XX_DYNAMITE 29
59 #define YY_DYNAMITE 89
68 /* special positions in the game control window (relative to main window) */
69 #define DX_LEVEL (DX + XX_LEVEL)
70 #define DY_LEVEL (DY + YY_LEVEL)
71 #define DX_EMERALDS (DX + XX_EMERALDS)
72 #define DY_EMERALDS (DY + YY_EMERALDS)
73 #define DX_DYNAMITE (DX + XX_DYNAMITE)
74 #define DY_DYNAMITE (DY + YY_DYNAMITE)
75 #define DX_KEYS (DX + XX_KEYS)
76 #define DY_KEYS (DY + YY_KEYS)
77 #define DX_SCORE (DX + XX_SCORE)
78 #define DY_SCORE (DY + YY_SCORE)
79 #define DX_TIME1 (DX + XX_TIME1)
80 #define DX_TIME2 (DX + XX_TIME2)
81 #define DY_TIME (DY + YY_TIME)
83 /* values for initial player move delay (initial delay counter value) */
84 #define INITIAL_MOVE_DELAY_OFF -1
85 #define INITIAL_MOVE_DELAY_ON 0
87 /* values for player movement speed (which is in fact a delay value) */
88 #define MOVE_DELAY_NORMAL_SPEED 8
89 #define MOVE_DELAY_HIGH_SPEED 4
91 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
92 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
93 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
94 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
96 /* values for other actions */
97 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
99 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
101 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
102 RND(element_info[e].push_delay_random))
103 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
104 RND(element_info[e].drop_delay_random))
105 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
106 RND(element_info[e].move_delay_random))
107 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
108 (element_info[e].move_delay_random))
110 #define GET_TARGET_ELEMENT(e, ch) \
111 ((e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
112 (e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : (e))
114 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
115 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
118 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
119 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
120 (CAN_MOVE_INTO_ACID(e) && \
121 Feld[x][y] == EL_ACID) || \
124 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
125 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
126 (CAN_MOVE_INTO_ACID(e) && \
127 Feld[x][y] == EL_ACID) || \
130 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
131 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
133 (CAN_MOVE_INTO_ACID(e) && \
134 Feld[x][y] == EL_ACID) || \
135 (DONT_COLLIDE_WITH(e) && \
137 !PLAYER_ENEMY_PROTECTED(x, y))))
140 #define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition) \
141 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
143 (DONT_COLLIDE_WITH(e) && \
145 !PLAYER_ENEMY_PROTECTED(x, y))))
148 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
149 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
152 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
153 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
155 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
156 ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, Feld[x][y] == EL_ACID)
160 #define ENEMY_CAN_ENTER_FIELD(e, x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
163 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
164 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
168 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
169 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
171 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
172 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
174 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
175 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
177 #define PIG_CAN_ENTER_FIELD(e, x, y) \
178 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
180 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
181 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
182 IS_FOOD_PENGUIN(Feld[x][y])))
183 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
184 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
186 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
187 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
189 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
190 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
194 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
195 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
196 (CAN_MOVE_INTO_ACID(e) && \
197 Feld[x][y] == EL_ACID) || \
198 Feld[x][y] == EL_DIAMOND))
200 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
201 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
202 (CAN_MOVE_INTO_ACID(e) && \
203 Feld[x][y] == EL_ACID) || \
204 IS_FOOD_DARK_YAMYAM(Feld[x][y])))
206 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
207 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
208 (CAN_MOVE_INTO_ACID(e) && \
209 Feld[x][y] == EL_ACID) || \
210 IS_AMOEBOID(Feld[x][y])))
212 #define PIG_CAN_ENTER_FIELD(e, x, y) \
213 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
214 (CAN_MOVE_INTO_ACID(e) && \
215 Feld[x][y] == EL_ACID) || \
216 IS_FOOD_PIG(Feld[x][y])))
218 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
219 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
220 (CAN_MOVE_INTO_ACID(e) && \
221 Feld[x][y] == EL_ACID) || \
222 IS_FOOD_PENGUIN(Feld[x][y]) || \
223 Feld[x][y] == EL_EXIT_OPEN))
225 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
226 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
227 (CAN_MOVE_INTO_ACID(e) && \
228 Feld[x][y] == EL_ACID)))
230 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
231 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
232 (CAN_MOVE_INTO_ACID(e) && \
233 Feld[x][y] == EL_ACID) || \
236 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
237 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
238 (CAN_MOVE_INTO_ACID(e) && \
239 Feld[x][y] == EL_ACID)))
243 #define GROUP_NR(e) ((e) - EL_GROUP_START)
244 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
245 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
246 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
248 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
249 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
252 #define CE_ENTER_FIELD_COND(e, x, y) \
253 (!IS_PLAYER(x, y) && \
254 (Feld[x][y] == EL_ACID || \
255 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e))))
257 #define CE_ENTER_FIELD_COND(e, x, y) \
258 (!IS_PLAYER(x, y) && \
259 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
262 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
263 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
265 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
266 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
268 /* game button identifiers */
269 #define GAME_CTRL_ID_STOP 0
270 #define GAME_CTRL_ID_PAUSE 1
271 #define GAME_CTRL_ID_PLAY 2
272 #define SOUND_CTRL_ID_MUSIC 3
273 #define SOUND_CTRL_ID_LOOPS 4
274 #define SOUND_CTRL_ID_SIMPLE 5
276 #define NUM_GAME_BUTTONS 6
279 /* forward declaration for internal use */
281 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
282 static boolean MovePlayer(struct PlayerInfo *, int, int);
283 static void ScrollPlayer(struct PlayerInfo *, int);
284 static void ScrollScreen(struct PlayerInfo *, int);
286 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
288 static void InitBeltMovement(void);
289 static void CloseAllOpenTimegates(void);
290 static void CheckGravityMovement(struct PlayerInfo *);
291 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
292 static void KillHeroUnlessEnemyProtected(int, int);
293 static void KillHeroUnlessExplosionProtected(int, int);
295 static void TestIfPlayerTouchesCustomElement(int, int);
296 static void TestIfElementTouchesCustomElement(int, int);
297 static void TestIfElementHitsCustomElement(int, int, int);
299 static void TestIfElementSmashesCustomElement(int, int, int);
302 static void ChangeElement(int, int, int);
304 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
305 #define CheckTriggeredElementChange(x, y, e, ev) \
306 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
308 #define CheckTriggeredElementChangePlayer(x, y, e, ev, p, s) \
309 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
310 #define CheckTriggeredElementChangeSide(x, y, e, ev, s) \
311 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
312 #define CheckTriggeredElementChangePage(x, y, e, ev, p) \
313 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, \
316 static boolean CheckElementChangeExt(int, int, int, int, int, int, int, int);
317 #define CheckElementChange(x, y, e, te, ev) \
318 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, -1)
319 #define CheckElementChangePlayer(x, y, e, ev, p, s) \
320 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s, CH_PAGE_ANY)
321 #define CheckElementChangeSide(x, y, e, te, ev, s) \
322 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s, CH_PAGE_ANY)
323 #define CheckElementChangePage(x, y, e, te, ev, p) \
324 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
326 static void PlayLevelSound(int, int, int);
327 static void PlayLevelSoundNearest(int, int, int);
328 static void PlayLevelSoundAction(int, int, int);
329 static void PlayLevelSoundElementAction(int, int, int, int);
330 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
331 static void PlayLevelSoundActionIfLoop(int, int, int);
332 static void StopLevelSoundActionIfLoop(int, int, int);
333 static void PlayLevelMusic();
335 static void MapGameButtons();
336 static void HandleGameButtons(struct GadgetInfo *);
338 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
341 /* ------------------------------------------------------------------------- */
342 /* definition of elements that automatically change to other elements after */
343 /* a specified time, eventually calling a function when changing */
344 /* ------------------------------------------------------------------------- */
346 /* forward declaration for changer functions */
347 static void InitBuggyBase(int x, int y);
348 static void WarnBuggyBase(int x, int y);
350 static void InitTrap(int x, int y);
351 static void ActivateTrap(int x, int y);
352 static void ChangeActiveTrap(int x, int y);
354 static void InitRobotWheel(int x, int y);
355 static void RunRobotWheel(int x, int y);
356 static void StopRobotWheel(int x, int y);
358 static void InitTimegateWheel(int x, int y);
359 static void RunTimegateWheel(int x, int y);
361 struct ChangingElementInfo
366 void (*pre_change_function)(int x, int y);
367 void (*change_function)(int x, int y);
368 void (*post_change_function)(int x, int y);
371 static struct ChangingElementInfo change_delay_list[] =
422 EL_SWITCHGATE_OPENING,
430 EL_SWITCHGATE_CLOSING,
431 EL_SWITCHGATE_CLOSED,
463 EL_ACID_SPLASH_RIGHT,
472 EL_SP_BUGGY_BASE_ACTIVATING,
479 EL_SP_BUGGY_BASE_ACTIVATING,
480 EL_SP_BUGGY_BASE_ACTIVE,
487 EL_SP_BUGGY_BASE_ACTIVE,
511 EL_ROBOT_WHEEL_ACTIVE,
519 EL_TIMEGATE_SWITCH_ACTIVE,
540 int push_delay_fixed, push_delay_random;
545 { EL_BALLOON, 0, 0 },
547 { EL_SOKOBAN_OBJECT, 2, 0 },
548 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
549 { EL_SATELLITE, 2, 0 },
550 { EL_SP_DISK_YELLOW, 2, 0 },
552 { EL_UNDEFINED, 0, 0 },
560 move_stepsize_list[] =
562 { EL_AMOEBA_DROP, 2 },
563 { EL_AMOEBA_DROPPING, 2 },
564 { EL_QUICKSAND_FILLING, 1 },
565 { EL_QUICKSAND_EMPTYING, 1 },
566 { EL_MAGIC_WALL_FILLING, 2 },
567 { EL_BD_MAGIC_WALL_FILLING, 2 },
568 { EL_MAGIC_WALL_EMPTYING, 2 },
569 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
579 collect_count_list[] =
582 { EL_BD_DIAMOND, 1 },
583 { EL_EMERALD_YELLOW, 1 },
584 { EL_EMERALD_RED, 1 },
585 { EL_EMERALD_PURPLE, 1 },
587 { EL_SP_INFOTRON, 1 },
601 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
602 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
603 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
604 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
605 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
606 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
607 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
608 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
609 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
610 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
611 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
616 static unsigned long trigger_events[MAX_NUM_ELEMENTS];
618 #define IS_AUTO_CHANGING(e) (element_info[e].change_events & \
619 CH_EVENT_BIT(CE_DELAY))
620 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
621 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
622 IS_JUST_CHANGING(x, y))
624 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
627 void GetPlayerConfig()
629 if (!audio.sound_available)
630 setup.sound_simple = FALSE;
632 if (!audio.loops_available)
633 setup.sound_loops = FALSE;
635 if (!audio.music_available)
636 setup.sound_music = FALSE;
638 if (!video.fullscreen_available)
639 setup.fullscreen = FALSE;
641 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
643 SetAudioMode(setup.sound);
647 static int getBeltNrFromBeltElement(int element)
649 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
650 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
651 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
654 static int getBeltNrFromBeltActiveElement(int element)
656 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
657 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
658 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
661 static int getBeltNrFromBeltSwitchElement(int element)
663 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
664 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
665 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
668 static int getBeltDirNrFromBeltSwitchElement(int element)
670 static int belt_base_element[4] =
672 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
673 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
674 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
675 EL_CONVEYOR_BELT_4_SWITCH_LEFT
678 int belt_nr = getBeltNrFromBeltSwitchElement(element);
679 int belt_dir_nr = element - belt_base_element[belt_nr];
681 return (belt_dir_nr % 3);
684 static int getBeltDirFromBeltSwitchElement(int element)
686 static int belt_move_dir[3] =
693 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
695 return belt_move_dir[belt_dir_nr];
698 static void InitPlayerField(int x, int y, int element, boolean init_game)
700 if (element == EL_SP_MURPHY)
704 if (stored_player[0].present)
706 Feld[x][y] = EL_SP_MURPHY_CLONE;
712 stored_player[0].use_murphy_graphic = TRUE;
715 Feld[x][y] = EL_PLAYER_1;
721 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
722 int jx = player->jx, jy = player->jy;
724 player->present = TRUE;
726 player->block_last_field = (element == EL_SP_MURPHY ?
727 level.sp_block_last_field :
728 level.block_last_field);
730 if (!options.network || player->connected)
732 player->active = TRUE;
734 /* remove potentially duplicate players */
735 if (StorePlayer[jx][jy] == Feld[x][y])
736 StorePlayer[jx][jy] = 0;
738 StorePlayer[x][y] = Feld[x][y];
742 printf("Player %d activated.\n", player->element_nr);
743 printf("[Local player is %d and currently %s.]\n",
744 local_player->element_nr,
745 local_player->active ? "active" : "not active");
749 Feld[x][y] = EL_EMPTY;
750 player->jx = player->last_jx = x;
751 player->jy = player->last_jy = y;
755 static void InitField(int x, int y, boolean init_game)
757 int element = Feld[x][y];
766 InitPlayerField(x, y, element, init_game);
769 case EL_SOKOBAN_FIELD_PLAYER:
770 element = Feld[x][y] = EL_PLAYER_1;
771 InitField(x, y, init_game);
773 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
774 InitField(x, y, init_game);
777 case EL_SOKOBAN_FIELD_EMPTY:
778 local_player->sokobanfields_still_needed++;
782 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
783 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
784 else if (x > 0 && Feld[x-1][y] == EL_ACID)
785 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
786 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
787 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
788 else if (y > 0 && Feld[x][y-1] == EL_ACID)
789 Feld[x][y] = EL_ACID_POOL_BOTTOM;
790 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
791 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
799 case EL_SPACESHIP_RIGHT:
800 case EL_SPACESHIP_UP:
801 case EL_SPACESHIP_LEFT:
802 case EL_SPACESHIP_DOWN:
804 case EL_BD_BUTTERFLY_RIGHT:
805 case EL_BD_BUTTERFLY_UP:
806 case EL_BD_BUTTERFLY_LEFT:
807 case EL_BD_BUTTERFLY_DOWN:
808 case EL_BD_BUTTERFLY:
809 case EL_BD_FIREFLY_RIGHT:
810 case EL_BD_FIREFLY_UP:
811 case EL_BD_FIREFLY_LEFT:
812 case EL_BD_FIREFLY_DOWN:
814 case EL_PACMAN_RIGHT:
838 if (y == lev_fieldy - 1)
840 Feld[x][y] = EL_AMOEBA_GROWING;
841 Store[x][y] = EL_AMOEBA_WET;
845 case EL_DYNAMITE_ACTIVE:
846 case EL_SP_DISK_RED_ACTIVE:
847 case EL_DYNABOMB_PLAYER_1_ACTIVE:
848 case EL_DYNABOMB_PLAYER_2_ACTIVE:
849 case EL_DYNABOMB_PLAYER_3_ACTIVE:
850 case EL_DYNABOMB_PLAYER_4_ACTIVE:
855 local_player->lights_still_needed++;
859 local_player->friends_still_needed++;
864 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
869 Feld[x][y] = EL_EMPTY;
874 case EL_EM_KEY_1_FILE:
875 Feld[x][y] = EL_EM_KEY_1;
877 case EL_EM_KEY_2_FILE:
878 Feld[x][y] = EL_EM_KEY_2;
880 case EL_EM_KEY_3_FILE:
881 Feld[x][y] = EL_EM_KEY_3;
883 case EL_EM_KEY_4_FILE:
884 Feld[x][y] = EL_EM_KEY_4;
888 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
889 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
890 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
891 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
892 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
893 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
894 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
895 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
896 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
897 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
898 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
899 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
902 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
903 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
904 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
906 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
908 game.belt_dir[belt_nr] = belt_dir;
909 game.belt_dir_nr[belt_nr] = belt_dir_nr;
911 else /* more than one switch -- set it like the first switch */
913 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
918 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
920 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
923 case EL_LIGHT_SWITCH_ACTIVE:
925 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
929 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
931 else if (IS_GROUP_ELEMENT(element))
933 struct ElementGroupInfo *group = element_info[element].group;
934 int last_anim_random_frame = gfx.anim_random_frame;
937 if (group->choice_mode == ANIM_RANDOM)
938 gfx.anim_random_frame = RND(group->num_elements_resolved);
940 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
941 group->choice_mode, 0,
944 if (group->choice_mode == ANIM_RANDOM)
945 gfx.anim_random_frame = last_anim_random_frame;
949 Feld[x][y] = group->element_resolved[element_pos];
951 InitField(x, y, init_game);
957 static inline void InitField_WithBug1(int x, int y, boolean init_game)
959 InitField(x, y, init_game);
961 /* not needed to call InitMovDir() -- already done by InitField()! */
962 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
963 CAN_MOVE(Feld[x][y]))
967 static inline void InitField_WithBug2(int x, int y, boolean init_game)
969 int old_element = Feld[x][y];
971 InitField(x, y, init_game);
973 /* not needed to call InitMovDir() -- already done by InitField()! */
974 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
975 CAN_MOVE(old_element) &&
976 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
979 /* this case is in fact a combination of not less than three bugs:
980 first, it calls InitMovDir() for elements that can move, although this is
981 already done by InitField(); then, it checks the element that was at this
982 field _before_ the call to InitField() (which can change it)
987 inline void DrawGameValue_Emeralds(int value)
989 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
992 inline void DrawGameValue_Dynamite(int value)
994 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
997 inline void DrawGameValue_Keys(struct PlayerInfo *player)
1001 for (i = 0; i < MAX_KEYS; i++)
1003 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1004 el2edimg(EL_KEY_1 + i));
1007 inline void DrawGameValue_Score(int value)
1009 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1012 inline void DrawGameValue_Time(int value)
1015 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1017 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1020 inline void DrawGameValue_Level(int value)
1023 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1026 /* misuse area for displaying emeralds to draw bigger level number */
1027 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1028 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1030 /* now copy it to the area for displaying level number */
1031 BlitBitmap(drawto, drawto,
1032 DX_EMERALDS, DY_EMERALDS + 1,
1033 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1034 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1035 DX_LEVEL - 1, DY_LEVEL + 1);
1037 /* restore the area for displaying emeralds */
1038 DrawGameValue_Emeralds(local_player->gems_still_needed);
1040 /* yes, this is all really ugly :-) */
1044 void DrawGameDoorValues()
1048 DrawGameValue_Level(level_nr);
1050 for (i = 0; i < MAX_PLAYERS; i++)
1051 DrawGameValue_Keys(&stored_player[i]);
1053 DrawGameValue_Emeralds(local_player->gems_still_needed);
1054 DrawGameValue_Dynamite(local_player->inventory_size);
1055 DrawGameValue_Score(local_player->score);
1056 DrawGameValue_Time(TimeLeft);
1059 static void resolve_group_element(int group_element, int recursion_depth)
1061 static int group_nr;
1062 static struct ElementGroupInfo *group;
1063 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1066 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1068 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1069 group_element - EL_GROUP_START + 1);
1071 /* replace element which caused too deep recursion by question mark */
1072 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1077 if (recursion_depth == 0) /* initialization */
1079 group = element_info[group_element].group;
1080 group_nr = group_element - EL_GROUP_START;
1082 group->num_elements_resolved = 0;
1083 group->choice_pos = 0;
1086 for (i = 0; i < actual_group->num_elements; i++)
1088 int element = actual_group->element[i];
1090 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1093 if (IS_GROUP_ELEMENT(element))
1094 resolve_group_element(element, recursion_depth + 1);
1097 group->element_resolved[group->num_elements_resolved++] = element;
1098 element_info[element].in_group[group_nr] = TRUE;
1103 if (recursion_depth == 0 && group_element <= EL_GROUP_4)
1105 printf("::: group %d: %d resolved elements\n",
1106 group_element - EL_GROUP_START, group->num_elements_resolved);
1107 for (i = 0; i < group->num_elements_resolved; i++)
1108 printf("::: - %d ['%s']\n", group->element_resolved[i],
1109 element_info[group->element_resolved[i]].token_name);
1116 =============================================================================
1118 -----------------------------------------------------------------------------
1119 initialize game engine due to level / tape version number
1120 =============================================================================
1123 static void InitGameEngine()
1127 /* set game engine from tape file when re-playing, else from level file */
1128 game.engine_version = (tape.playing ? tape.engine_version :
1129 level.game_version);
1131 /* dynamically adjust element properties according to game engine version */
1132 InitElementPropertiesEngine(game.engine_version);
1135 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1136 printf(" tape version == %06d [%s] [file: %06d]\n",
1137 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1139 printf(" => game.engine_version == %06d\n", game.engine_version);
1142 /* ---------- recursively resolve group elements ------------------------- */
1144 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1145 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1146 element_info[i].in_group[j] = FALSE;
1148 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1149 resolve_group_element(EL_GROUP_START + i, 0);
1151 /* ---------- initialize player's initial move delay --------------------- */
1153 /* dynamically adjust player properties according to game engine version */
1154 game.initial_move_delay =
1155 (game.engine_version <= VERSION_IDENT(2,0,1,0) ? INITIAL_MOVE_DELAY_ON :
1156 INITIAL_MOVE_DELAY_OFF);
1158 /* dynamically adjust player properties according to level information */
1159 game.initial_move_delay_value =
1160 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1162 /* ---------- initialize player's initial push delay --------------------- */
1164 /* dynamically adjust player properties according to game engine version */
1165 game.initial_push_delay_value =
1166 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1168 /* ---------- initialize changing elements ------------------------------- */
1170 /* initialize changing elements information */
1171 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1173 struct ElementInfo *ei = &element_info[i];
1175 /* this pointer might have been changed in the level editor */
1176 ei->change = &ei->change_page[0];
1178 if (!IS_CUSTOM_ELEMENT(i))
1180 ei->change->target_element = EL_EMPTY_SPACE;
1181 ei->change->delay_fixed = 0;
1182 ei->change->delay_random = 0;
1183 ei->change->delay_frames = 1;
1186 ei->change_events = CE_BITMASK_DEFAULT;
1187 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1189 ei->event_page_nr[j] = 0;
1190 ei->event_page[j] = &ei->change_page[0];
1194 /* add changing elements from pre-defined list */
1195 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1197 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1198 struct ElementInfo *ei = &element_info[ch_delay->element];
1200 ei->change->target_element = ch_delay->target_element;
1201 ei->change->delay_fixed = ch_delay->change_delay;
1203 ei->change->pre_change_function = ch_delay->pre_change_function;
1204 ei->change->change_function = ch_delay->change_function;
1205 ei->change->post_change_function = ch_delay->post_change_function;
1207 ei->change_events |= CH_EVENT_BIT(CE_DELAY);
1210 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1215 /* add change events from custom element configuration */
1216 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1218 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1220 for (j = 0; j < ei->num_change_pages; j++)
1222 if (!ei->change_page[j].can_change)
1225 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1227 /* only add event page for the first page found with this event */
1228 if (ei->change_page[j].events & CH_EVENT_BIT(k) &&
1229 !(ei->change_events & CH_EVENT_BIT(k)))
1231 ei->change_events |= CH_EVENT_BIT(k);
1232 ei->event_page_nr[k] = j;
1233 ei->event_page[k] = &ei->change_page[j];
1241 /* add change events from custom element configuration */
1242 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1244 int element = EL_CUSTOM_START + i;
1246 /* only add custom elements that change after fixed/random frame delay */
1247 if (CAN_CHANGE(element) && HAS_CHANGE_EVENT(element, CE_DELAY))
1248 element_info[element].change_events |= CH_EVENT_BIT(CE_DELAY);
1252 /* ---------- initialize run-time trigger player and element ------------- */
1254 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1256 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1258 for (j = 0; j < ei->num_change_pages; j++)
1260 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1261 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1265 /* ---------- initialize trigger events ---------------------------------- */
1267 /* initialize trigger events information */
1268 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1269 trigger_events[i] = EP_BITMASK_DEFAULT;
1272 /* add trigger events from element change event properties */
1273 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1275 struct ElementInfo *ei = &element_info[i];
1277 for (j = 0; j < ei->num_change_pages; j++)
1279 if (!ei->change_page[j].can_change)
1282 if (ei->change_page[j].events & CH_EVENT_BIT(CE_BY_OTHER_ACTION))
1284 int trigger_element = ei->change_page[j].trigger_element;
1286 if (IS_GROUP_ELEMENT(trigger_element))
1288 struct ElementGroupInfo *group = element_info[trigger_element].group;
1290 for (k = 0; k < group->num_elements_resolved; k++)
1291 trigger_events[group->element_resolved[k]]
1292 |= ei->change_page[j].events;
1295 trigger_events[trigger_element] |= ei->change_page[j].events;
1300 /* add trigger events from element change event properties */
1301 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1302 if (HAS_CHANGE_EVENT(i, CE_BY_OTHER_ACTION))
1303 trigger_events[element_info[i].change->trigger_element] |=
1304 element_info[i].change->events;
1307 /* ---------- initialize push delay -------------------------------------- */
1309 /* initialize push delay values to default */
1310 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1312 if (!IS_CUSTOM_ELEMENT(i))
1314 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1315 element_info[i].push_delay_random = game.default_push_delay_random;
1319 /* set push delay value for certain elements from pre-defined list */
1320 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1322 int e = push_delay_list[i].element;
1324 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1325 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1328 /* set push delay value for Supaplex elements for newer engine versions */
1329 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1331 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1333 if (IS_SP_ELEMENT(i))
1335 element_info[i].push_delay_fixed = 6; /* just enough to escape ... */
1336 element_info[i].push_delay_random = 0; /* ... from falling zonk */
1341 /* ---------- initialize move stepsize ----------------------------------- */
1343 /* initialize move stepsize values to default */
1344 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1345 if (!IS_CUSTOM_ELEMENT(i))
1346 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1348 /* set move stepsize value for certain elements from pre-defined list */
1349 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1351 int e = move_stepsize_list[i].element;
1353 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1357 /* ---------- initialize move dig/leave ---------------------------------- */
1359 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1361 element_info[i].can_leave_element = FALSE;
1362 element_info[i].can_leave_element_last = FALSE;
1366 /* ---------- initialize gem count --------------------------------------- */
1368 /* initialize gem count values for each element */
1369 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1370 if (!IS_CUSTOM_ELEMENT(i))
1371 element_info[i].collect_count = 0;
1373 /* add gem count values for all elements from pre-defined list */
1374 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1375 element_info[collect_count_list[i].element].collect_count =
1376 collect_count_list[i].count;
1378 /* ---------- initialize access direction -------------------------------- */
1380 /* initialize access direction values to default */
1381 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1382 if (!IS_CUSTOM_ELEMENT(i))
1383 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1385 /* set access direction value for certain elements from pre-defined list */
1386 for (i = 0; tube_access[i].element != EL_UNDEFINED; i++)
1387 element_info[tube_access[i].element].access_direction =
1388 tube_access[i].direction;
1393 =============================================================================
1395 -----------------------------------------------------------------------------
1396 initialize and start new game
1397 =============================================================================
1402 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1403 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1404 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1411 #if USE_NEW_AMOEBA_CODE
1412 printf("Using new amoeba code.\n");
1414 printf("Using old amoeba code.\n");
1419 /* don't play tapes over network */
1420 network_playing = (options.network && !tape.playing);
1422 for (i = 0; i < MAX_PLAYERS; i++)
1424 struct PlayerInfo *player = &stored_player[i];
1426 player->index_nr = i;
1427 player->index_bit = (1 << i);
1428 player->element_nr = EL_PLAYER_1 + i;
1430 player->present = FALSE;
1431 player->active = FALSE;
1434 player->effective_action = 0;
1435 player->programmed_action = 0;
1438 player->gems_still_needed = level.gems_needed;
1439 player->sokobanfields_still_needed = 0;
1440 player->lights_still_needed = 0;
1441 player->friends_still_needed = 0;
1443 for (j = 0; j < MAX_KEYS; j++)
1444 player->key[j] = FALSE;
1446 player->dynabomb_count = 0;
1447 player->dynabomb_size = 1;
1448 player->dynabombs_left = 0;
1449 player->dynabomb_xl = FALSE;
1451 player->MovDir = MV_NO_MOVING;
1454 player->GfxDir = MV_NO_MOVING;
1455 player->GfxAction = ACTION_DEFAULT;
1457 player->StepFrame = 0;
1459 player->use_murphy_graphic = FALSE;
1461 player->block_last_field = FALSE;
1462 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1464 player->actual_frame_counter = 0;
1466 player->step_counter = 0;
1468 player->last_move_dir = MV_NO_MOVING;
1470 player->is_waiting = FALSE;
1471 player->is_moving = FALSE;
1472 player->is_digging = FALSE;
1473 player->is_snapping = FALSE;
1474 player->is_collecting = FALSE;
1475 player->is_pushing = FALSE;
1476 player->is_switching = FALSE;
1477 player->is_dropping = FALSE;
1479 player->is_bored = FALSE;
1480 player->is_sleeping = FALSE;
1482 player->frame_counter_bored = -1;
1483 player->frame_counter_sleeping = -1;
1485 player->anim_delay_counter = 0;
1486 player->post_delay_counter = 0;
1488 player->action_waiting = ACTION_DEFAULT;
1489 player->last_action_waiting = ACTION_DEFAULT;
1490 player->special_action_bored = ACTION_DEFAULT;
1491 player->special_action_sleeping = ACTION_DEFAULT;
1493 player->num_special_action_bored = 0;
1494 player->num_special_action_sleeping = 0;
1496 /* determine number of special actions for bored and sleeping animation */
1497 for (j = ACTION_BORING_1; j <= ACTION_BORING_LAST; j++)
1499 boolean found = FALSE;
1501 for (k = 0; k < NUM_DIRECTIONS; k++)
1502 if (el_act_dir2img(player->element_nr, j, k) !=
1503 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1507 player->num_special_action_bored++;
1511 for (j = ACTION_SLEEPING_1; j <= ACTION_SLEEPING_LAST; j++)
1513 boolean found = FALSE;
1515 for (k = 0; k < NUM_DIRECTIONS; k++)
1516 if (el_act_dir2img(player->element_nr, j, k) !=
1517 el_act_dir2img(player->element_nr, ACTION_DEFAULT, k))
1521 player->num_special_action_sleeping++;
1526 player->switch_x = -1;
1527 player->switch_y = -1;
1529 player->show_envelope = 0;
1531 player->move_delay = game.initial_move_delay;
1532 player->move_delay_value = game.initial_move_delay_value;
1534 player->move_delay_reset_counter = 0;
1536 player->push_delay = 0;
1537 player->push_delay_value = game.initial_push_delay_value;
1539 player->drop_delay = 0;
1541 player->last_jx = player->last_jy = 0;
1542 player->jx = player->jy = 0;
1544 player->shield_normal_time_left = 0;
1545 player->shield_deadly_time_left = 0;
1547 player->inventory_infinite_element = EL_UNDEFINED;
1548 player->inventory_size = 0;
1550 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1551 SnapField(player, 0, 0);
1553 player->LevelSolved = FALSE;
1554 player->GameOver = FALSE;
1557 network_player_action_received = FALSE;
1559 #if defined(PLATFORM_UNIX)
1560 /* initial null action */
1561 if (network_playing)
1562 SendToServer_MovePlayer(MV_NO_MOVING);
1570 TimeLeft = level.time;
1573 ScreenMovDir = MV_NO_MOVING;
1577 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1579 AllPlayersGone = FALSE;
1581 game.yamyam_content_nr = 0;
1582 game.magic_wall_active = FALSE;
1583 game.magic_wall_time_left = 0;
1584 game.light_time_left = 0;
1585 game.timegate_time_left = 0;
1586 game.switchgate_pos = 0;
1587 game.balloon_dir = MV_NO_MOVING;
1588 game.gravity = level.initial_gravity;
1589 game.explosions_delayed = TRUE;
1591 game.envelope_active = FALSE;
1593 for (i = 0; i < NUM_BELTS; i++)
1595 game.belt_dir[i] = MV_NO_MOVING;
1596 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1599 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1600 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1602 for (x = 0; x < lev_fieldx; x++)
1604 for (y = 0; y < lev_fieldy; y++)
1606 Feld[x][y] = level.field[x][y];
1607 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1608 ChangeDelay[x][y] = 0;
1609 ChangePage[x][y] = -1;
1610 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1612 WasJustMoving[x][y] = 0;
1613 WasJustFalling[x][y] = 0;
1615 Pushed[x][y] = FALSE;
1617 Changed[x][y] = CE_BITMASK_DEFAULT;
1618 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
1620 ExplodePhase[x][y] = 0;
1621 ExplodeDelay[x][y] = 0;
1622 ExplodeField[x][y] = EX_TYPE_NONE;
1624 RunnerVisit[x][y] = 0;
1625 PlayerVisit[x][y] = 0;
1628 GfxRandom[x][y] = INIT_GFX_RANDOM();
1629 GfxElement[x][y] = EL_UNDEFINED;
1630 GfxAction[x][y] = ACTION_DEFAULT;
1631 GfxDir[x][y] = MV_NO_MOVING;
1635 for (y = 0; y < lev_fieldy; y++)
1637 for (x = 0; x < lev_fieldx; x++)
1639 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1641 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1643 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1646 InitField(x, y, TRUE);
1652 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1653 emulate_sb ? EMU_SOKOBAN :
1654 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1656 /* initialize explosion and ignition delay */
1657 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1659 if (!IS_CUSTOM_ELEMENT(i))
1662 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1663 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1664 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1665 int last_phase = (num_phase + 1) * delay;
1666 int half_phase = (num_phase / 2) * delay;
1668 element_info[i].explosion_delay = last_phase - 1;
1669 element_info[i].ignition_delay = half_phase;
1672 if (i == EL_BLACK_ORB)
1673 element_info[i].ignition_delay = 0;
1675 if (i == EL_BLACK_ORB)
1676 element_info[i].ignition_delay = 1;
1681 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1682 element_info[i].explosion_delay = 1;
1684 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1685 element_info[i].ignition_delay = 1;
1689 /* correct non-moving belts to start moving left */
1690 for (i = 0; i < NUM_BELTS; i++)
1691 if (game.belt_dir[i] == MV_NO_MOVING)
1692 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1694 /* check if any connected player was not found in playfield */
1695 for (i = 0; i < MAX_PLAYERS; i++)
1697 struct PlayerInfo *player = &stored_player[i];
1699 if (player->connected && !player->present)
1701 for (j = 0; j < MAX_PLAYERS; j++)
1703 struct PlayerInfo *some_player = &stored_player[j];
1704 int jx = some_player->jx, jy = some_player->jy;
1706 /* assign first free player found that is present in the playfield */
1707 if (some_player->present && !some_player->connected)
1709 player->present = TRUE;
1710 player->active = TRUE;
1712 some_player->present = FALSE;
1713 some_player->active = FALSE;
1716 player->element_nr = some_player->element_nr;
1719 StorePlayer[jx][jy] = player->element_nr;
1720 player->jx = player->last_jx = jx;
1721 player->jy = player->last_jy = jy;
1731 /* when playing a tape, eliminate all players which do not participate */
1733 for (i = 0; i < MAX_PLAYERS; i++)
1735 if (stored_player[i].active && !tape.player_participates[i])
1737 struct PlayerInfo *player = &stored_player[i];
1738 int jx = player->jx, jy = player->jy;
1740 player->active = FALSE;
1741 StorePlayer[jx][jy] = 0;
1742 Feld[jx][jy] = EL_EMPTY;
1746 else if (!options.network && !setup.team_mode) /* && !tape.playing */
1748 /* when in single player mode, eliminate all but the first active player */
1750 for (i = 0; i < MAX_PLAYERS; i++)
1752 if (stored_player[i].active)
1754 for (j = i + 1; j < MAX_PLAYERS; j++)
1756 if (stored_player[j].active)
1758 struct PlayerInfo *player = &stored_player[j];
1759 int jx = player->jx, jy = player->jy;
1761 player->active = FALSE;
1762 player->present = FALSE;
1764 StorePlayer[jx][jy] = 0;
1765 Feld[jx][jy] = EL_EMPTY;
1772 /* when recording the game, store which players take part in the game */
1775 for (i = 0; i < MAX_PLAYERS; i++)
1776 if (stored_player[i].active)
1777 tape.player_participates[i] = TRUE;
1782 for (i = 0; i < MAX_PLAYERS; i++)
1784 struct PlayerInfo *player = &stored_player[i];
1786 printf("Player %d: present == %d, connected == %d, active == %d.\n",
1791 if (local_player == player)
1792 printf("Player %d is local player.\n", i+1);
1796 if (BorderElement == EL_EMPTY)
1799 SBX_Right = lev_fieldx - SCR_FIELDX;
1801 SBY_Lower = lev_fieldy - SCR_FIELDY;
1806 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
1808 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
1811 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
1812 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
1814 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
1815 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
1817 /* if local player not found, look for custom element that might create
1818 the player (make some assumptions about the right custom element) */
1819 if (!local_player->present)
1821 int start_x = 0, start_y = 0;
1822 int found_rating = 0;
1823 int found_element = EL_UNDEFINED;
1825 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1827 int element = Feld[x][y];
1832 if (!IS_CUSTOM_ELEMENT(element))
1835 if (CAN_CHANGE(element))
1837 for (i = 0; i < element_info[element].num_change_pages; i++)
1839 content = element_info[element].change_page[i].target_element;
1840 is_player = ELEM_IS_PLAYER(content);
1842 if (is_player && (found_rating < 3 || element < found_element))
1848 found_element = element;
1853 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
1855 content = element_info[element].content[xx][yy];
1856 is_player = ELEM_IS_PLAYER(content);
1858 if (is_player && (found_rating < 2 || element < found_element))
1860 start_x = x + xx - 1;
1861 start_y = y + yy - 1;
1864 found_element = element;
1867 if (!CAN_CHANGE(element))
1870 for (i = 0; i < element_info[element].num_change_pages; i++)
1872 content= element_info[element].change_page[i].target_content[xx][yy];
1873 is_player = ELEM_IS_PLAYER(content);
1875 if (is_player && (found_rating < 1 || element < found_element))
1877 start_x = x + xx - 1;
1878 start_y = y + yy - 1;
1881 found_element = element;
1887 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
1888 start_x > SBX_Right + MIDPOSX ? SBX_Right :
1891 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
1892 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
1898 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
1899 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
1900 local_player->jx - MIDPOSX);
1902 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
1903 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
1904 local_player->jy - MIDPOSY);
1906 scroll_x = SBX_Left;
1907 scroll_y = SBY_Upper;
1908 if (local_player->jx >= SBX_Left + MIDPOSX)
1909 scroll_x = (local_player->jx <= SBX_Right + MIDPOSX ?
1910 local_player->jx - MIDPOSX :
1912 if (local_player->jy >= SBY_Upper + MIDPOSY)
1913 scroll_y = (local_player->jy <= SBY_Lower + MIDPOSY ?
1914 local_player->jy - MIDPOSY :
1919 CloseDoor(DOOR_CLOSE_1);
1924 /* after drawing the level, correct some elements */
1925 if (game.timegate_time_left == 0)
1926 CloseAllOpenTimegates();
1928 if (setup.soft_scrolling)
1929 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
1931 redraw_mask |= REDRAW_FROM_BACKBUFFER;
1934 /* copy default game door content to main double buffer */
1935 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1936 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
1938 DrawGameDoorValues();
1942 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
1943 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
1944 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
1948 /* copy actual game door content to door double buffer for OpenDoor() */
1949 BlitBitmap(drawto, bitmap_db_door,
1950 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
1952 OpenDoor(DOOR_OPEN_ALL);
1954 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
1956 if (setup.sound_music)
1959 KeyboardAutoRepeatOffUnlessAutoplay();
1963 for (i = 0; i < MAX_PLAYERS; i++)
1964 printf("Player %d %sactive.\n",
1965 i + 1, (stored_player[i].active ? "" : "not "));
1969 printf("::: starting game [%d]\n", FrameCounter);
1973 void InitMovDir(int x, int y)
1975 int i, element = Feld[x][y];
1976 static int xy[4][2] =
1983 static int direction[3][4] =
1985 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
1986 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
1987 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
1996 Feld[x][y] = EL_BUG;
1997 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2000 case EL_SPACESHIP_RIGHT:
2001 case EL_SPACESHIP_UP:
2002 case EL_SPACESHIP_LEFT:
2003 case EL_SPACESHIP_DOWN:
2004 Feld[x][y] = EL_SPACESHIP;
2005 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2008 case EL_BD_BUTTERFLY_RIGHT:
2009 case EL_BD_BUTTERFLY_UP:
2010 case EL_BD_BUTTERFLY_LEFT:
2011 case EL_BD_BUTTERFLY_DOWN:
2012 Feld[x][y] = EL_BD_BUTTERFLY;
2013 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2016 case EL_BD_FIREFLY_RIGHT:
2017 case EL_BD_FIREFLY_UP:
2018 case EL_BD_FIREFLY_LEFT:
2019 case EL_BD_FIREFLY_DOWN:
2020 Feld[x][y] = EL_BD_FIREFLY;
2021 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2024 case EL_PACMAN_RIGHT:
2026 case EL_PACMAN_LEFT:
2027 case EL_PACMAN_DOWN:
2028 Feld[x][y] = EL_PACMAN;
2029 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2032 case EL_SP_SNIKSNAK:
2033 MovDir[x][y] = MV_UP;
2036 case EL_SP_ELECTRON:
2037 MovDir[x][y] = MV_LEFT;
2044 Feld[x][y] = EL_MOLE;
2045 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2049 if (IS_CUSTOM_ELEMENT(element))
2051 struct ElementInfo *ei = &element_info[element];
2052 int move_direction_initial = ei->move_direction_initial;
2053 int move_pattern = ei->move_pattern;
2055 if (move_direction_initial == MV_START_PREVIOUS)
2057 if (MovDir[x][y] != MV_NO_MOVING)
2060 move_direction_initial = MV_START_AUTOMATIC;
2063 if (move_direction_initial == MV_START_RANDOM)
2064 MovDir[x][y] = 1 << RND(4);
2065 else if (move_direction_initial & MV_ANY_DIRECTION)
2066 MovDir[x][y] = move_direction_initial;
2067 else if (move_pattern == MV_ALL_DIRECTIONS ||
2068 move_pattern == MV_TURNING_LEFT ||
2069 move_pattern == MV_TURNING_RIGHT ||
2070 move_pattern == MV_TURNING_LEFT_RIGHT ||
2071 move_pattern == MV_TURNING_RIGHT_LEFT ||
2072 move_pattern == MV_TURNING_RANDOM)
2073 MovDir[x][y] = 1 << RND(4);
2074 else if (move_pattern == MV_HORIZONTAL)
2075 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2076 else if (move_pattern == MV_VERTICAL)
2077 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2078 else if (move_pattern & MV_ANY_DIRECTION)
2079 MovDir[x][y] = element_info[element].move_pattern;
2080 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2081 move_pattern == MV_ALONG_RIGHT_SIDE)
2083 for (i = 0; i < NUM_DIRECTIONS; i++)
2085 int x1 = x + xy[i][0];
2086 int y1 = y + xy[i][1];
2088 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2090 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2091 MovDir[x][y] = direction[0][i];
2093 MovDir[x][y] = direction[1][i];
2099 if (MovDir[x][y] == MV_NO_MOVING) /* no start direction found */
2100 MovDir[x][y] = 1 << RND(4); /* => use random direction */
2107 MovDir[x][y] = 1 << RND(4);
2109 if (element != EL_BUG &&
2110 element != EL_SPACESHIP &&
2111 element != EL_BD_BUTTERFLY &&
2112 element != EL_BD_FIREFLY)
2115 for (i = 0; i < NUM_DIRECTIONS; i++)
2117 int x1 = x + xy[i][0];
2118 int y1 = y + xy[i][1];
2120 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2122 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2124 MovDir[x][y] = direction[0][i];
2127 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2128 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2130 MovDir[x][y] = direction[1][i];
2139 GfxDir[x][y] = MovDir[x][y];
2142 void InitAmoebaNr(int x, int y)
2145 int group_nr = AmoebeNachbarNr(x, y);
2149 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2151 if (AmoebaCnt[i] == 0)
2159 AmoebaNr[x][y] = group_nr;
2160 AmoebaCnt[group_nr]++;
2161 AmoebaCnt2[group_nr]++;
2167 boolean raise_level = FALSE;
2169 if (local_player->MovPos)
2173 if (tape.auto_play) /* tape might already be stopped here */
2174 tape.auto_play_level_solved = TRUE;
2176 if (tape.playing && tape.auto_play)
2177 tape.auto_play_level_solved = TRUE;
2180 local_player->LevelSolved = FALSE;
2182 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2186 if (!tape.playing && setup.sound_loops)
2187 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2188 SND_CTRL_PLAY_LOOP);
2190 while (TimeLeft > 0)
2192 if (!tape.playing && !setup.sound_loops)
2193 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2194 if (TimeLeft > 0 && !(TimeLeft % 10))
2195 RaiseScore(level.score[SC_TIME_BONUS]);
2196 if (TimeLeft > 100 && !(TimeLeft % 10))
2201 DrawGameValue_Time(TimeLeft);
2209 if (!tape.playing && setup.sound_loops)
2210 StopSound(SND_GAME_LEVELTIME_BONUS);
2212 else if (level.time == 0) /* level without time limit */
2214 if (!tape.playing && setup.sound_loops)
2215 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2216 SND_CTRL_PLAY_LOOP);
2218 while (TimePlayed < 999)
2220 if (!tape.playing && !setup.sound_loops)
2221 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2222 if (TimePlayed < 999 && !(TimePlayed % 10))
2223 RaiseScore(level.score[SC_TIME_BONUS]);
2224 if (TimePlayed < 900 && !(TimePlayed % 10))
2229 DrawGameValue_Time(TimePlayed);
2237 if (!tape.playing && setup.sound_loops)
2238 StopSound(SND_GAME_LEVELTIME_BONUS);
2241 /* close exit door after last player */
2242 if ((Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2243 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN) && AllPlayersGone)
2245 int element = Feld[ExitX][ExitY];
2247 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2248 EL_SP_EXIT_CLOSING);
2250 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2253 /* Hero disappears */
2254 DrawLevelField(ExitX, ExitY);
2260 CloseDoor(DOOR_CLOSE_1);
2265 SaveTape(tape.level_nr); /* Ask to save tape */
2268 if (level_nr == leveldir_current->handicap_level)
2270 leveldir_current->handicap_level++;
2271 SaveLevelSetup_SeriesInfo();
2274 if (level_editor_test_game)
2275 local_player->score = -1; /* no highscore when playing from editor */
2276 else if (level_nr < leveldir_current->last_level)
2277 raise_level = TRUE; /* advance to next level */
2279 if ((hi_pos = NewHiScore()) >= 0)
2281 game_status = GAME_MODE_SCORES;
2282 DrawHallOfFame(hi_pos);
2291 game_status = GAME_MODE_MAIN;
2308 LoadScore(level_nr);
2310 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2311 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2314 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2316 if (local_player->score > highscore[k].Score)
2318 /* player has made it to the hall of fame */
2320 if (k < MAX_SCORE_ENTRIES - 1)
2322 int m = MAX_SCORE_ENTRIES - 1;
2325 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2326 if (!strcmp(setup.player_name, highscore[l].Name))
2328 if (m == k) /* player's new highscore overwrites his old one */
2332 for (l = m; l > k; l--)
2334 strcpy(highscore[l].Name, highscore[l - 1].Name);
2335 highscore[l].Score = highscore[l - 1].Score;
2342 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2343 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2344 highscore[k].Score = local_player->score;
2350 else if (!strncmp(setup.player_name, highscore[k].Name,
2351 MAX_PLAYER_NAME_LEN))
2352 break; /* player already there with a higher score */
2358 SaveScore(level_nr);
2363 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2365 if (player->GfxAction != action || player->GfxDir != dir)
2368 printf("Player frame reset! (%d => %d, %d => %d)\n",
2369 player->GfxAction, action, player->GfxDir, dir);
2372 player->GfxAction = action;
2373 player->GfxDir = dir;
2375 player->StepFrame = 0;
2379 static void ResetRandomAnimationValue(int x, int y)
2381 GfxRandom[x][y] = INIT_GFX_RANDOM();
2384 static void ResetGfxAnimation(int x, int y)
2387 GfxAction[x][y] = ACTION_DEFAULT;
2388 GfxDir[x][y] = MovDir[x][y];
2391 void InitMovingField(int x, int y, int direction)
2393 int element = Feld[x][y];
2394 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2395 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2399 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2400 ResetGfxAnimation(x, y);
2402 MovDir[newx][newy] = MovDir[x][y] = direction;
2403 GfxDir[x][y] = direction;
2405 if (Feld[newx][newy] == EL_EMPTY)
2406 Feld[newx][newy] = EL_BLOCKED;
2408 if (direction == MV_DOWN && CAN_FALL(element))
2409 GfxAction[x][y] = ACTION_FALLING;
2411 GfxAction[x][y] = ACTION_MOVING;
2413 GfxFrame[newx][newy] = GfxFrame[x][y];
2414 GfxRandom[newx][newy] = GfxRandom[x][y];
2415 GfxAction[newx][newy] = GfxAction[x][y];
2416 GfxDir[newx][newy] = GfxDir[x][y];
2419 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2421 int direction = MovDir[x][y];
2422 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2423 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2429 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2431 int oldx = x, oldy = y;
2432 int direction = MovDir[x][y];
2434 if (direction == MV_LEFT)
2436 else if (direction == MV_RIGHT)
2438 else if (direction == MV_UP)
2440 else if (direction == MV_DOWN)
2443 *comes_from_x = oldx;
2444 *comes_from_y = oldy;
2447 int MovingOrBlocked2Element(int x, int y)
2449 int element = Feld[x][y];
2451 if (element == EL_BLOCKED)
2455 Blocked2Moving(x, y, &oldx, &oldy);
2456 return Feld[oldx][oldy];
2462 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2464 /* like MovingOrBlocked2Element(), but if element is moving
2465 and (x,y) is the field the moving element is just leaving,
2466 return EL_BLOCKED instead of the element value */
2467 int element = Feld[x][y];
2469 if (IS_MOVING(x, y))
2471 if (element == EL_BLOCKED)
2475 Blocked2Moving(x, y, &oldx, &oldy);
2476 return Feld[oldx][oldy];
2485 static void RemoveField(int x, int y)
2487 Feld[x][y] = EL_EMPTY;
2494 ChangeDelay[x][y] = 0;
2495 ChangePage[x][y] = -1;
2496 Pushed[x][y] = FALSE;
2498 GfxElement[x][y] = EL_UNDEFINED;
2499 GfxAction[x][y] = ACTION_DEFAULT;
2500 GfxDir[x][y] = MV_NO_MOVING;
2503 void RemoveMovingField(int x, int y)
2505 int oldx = x, oldy = y, newx = x, newy = y;
2506 int element = Feld[x][y];
2507 int next_element = EL_UNDEFINED;
2509 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2512 if (IS_MOVING(x, y))
2514 Moving2Blocked(x, y, &newx, &newy);
2516 if (Feld[newx][newy] != EL_BLOCKED)
2519 if (Feld[newx][newy] != EL_BLOCKED)
2521 /* element is moving, but target field is not free (blocked), but
2522 already occupied by something different (example: acid pool);
2523 in this case, only remove the moving field, but not the target */
2525 RemoveField(oldx, oldy);
2527 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2529 DrawLevelField(oldx, oldy);
2535 else if (element == EL_BLOCKED)
2537 Blocked2Moving(x, y, &oldx, &oldy);
2538 if (!IS_MOVING(oldx, oldy))
2542 if (element == EL_BLOCKED &&
2543 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2544 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2545 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2546 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2547 next_element = get_next_element(Feld[oldx][oldy]);
2549 RemoveField(oldx, oldy);
2550 RemoveField(newx, newy);
2552 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2554 if (next_element != EL_UNDEFINED)
2555 Feld[oldx][oldy] = next_element;
2557 DrawLevelField(oldx, oldy);
2558 DrawLevelField(newx, newy);
2561 void DrawDynamite(int x, int y)
2563 int sx = SCREENX(x), sy = SCREENY(y);
2564 int graphic = el2img(Feld[x][y]);
2567 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2570 if (IS_WALKABLE_INSIDE(Back[x][y]))
2574 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2575 else if (Store[x][y])
2576 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2578 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2581 if (Back[x][y] || Store[x][y])
2582 DrawGraphicThruMask(sx, sy, graphic, frame);
2584 DrawGraphic(sx, sy, graphic, frame);
2586 if (game.emulation == EMU_SUPAPLEX)
2587 DrawGraphic(sx, sy, IMG_SP_DISK_RED, frame);
2588 else if (Store[x][y])
2589 DrawGraphicThruMask(sx, sy, graphic, frame);
2591 DrawGraphic(sx, sy, graphic, frame);
2595 void CheckDynamite(int x, int y)
2597 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2601 if (MovDelay[x][y] != 0)
2604 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2611 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
2613 if (Feld[x][y] == EL_DYNAMITE_ACTIVE ||
2614 Feld[x][y] == EL_SP_DISK_RED_ACTIVE)
2615 StopSound(SND_DYNAMITE_ACTIVE);
2617 StopSound(SND_DYNABOMB_ACTIVE);
2623 void RelocatePlayer(int x, int y, int element_raw)
2625 int element = (element_raw == EL_SP_MURPHY ? EL_PLAYER_1 : element_raw);
2626 struct PlayerInfo *player = &stored_player[element - EL_PLAYER_1];
2627 boolean ffwd_delay = (tape.playing && tape.fast_forward);
2628 boolean no_delay = (tape.warp_forward);
2629 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
2630 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
2633 if (player->GameOver) /* do not reanimate dead player */
2636 RemoveField(x, y); /* temporarily remove newly placed player */
2637 DrawLevelField(x, y);
2639 if (player->present)
2641 while (player->MovPos)
2643 ScrollPlayer(player, SCROLL_GO_ON);
2644 ScrollScreen(NULL, SCROLL_GO_ON);
2650 Delay(wait_delay_value);
2653 DrawPlayer(player); /* needed here only to cleanup last field */
2654 DrawLevelField(player->jx, player->jy); /* remove player graphic */
2656 player->is_moving = FALSE;
2659 old_jx = player->jx;
2660 old_jy = player->jy;
2662 Feld[x][y] = element;
2663 InitPlayerField(x, y, element, TRUE);
2665 if (player != local_player) /* do not visually relocate other players */
2668 if (level.instant_relocation)
2671 int offset = (setup.scroll_delay ? 3 : 0);
2672 int jx = local_player->jx;
2673 int jy = local_player->jy;
2675 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
2677 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2678 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2679 local_player->jx - MIDPOSX);
2681 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2682 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2683 local_player->jy - MIDPOSY);
2687 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
2688 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
2689 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
2691 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
2692 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
2693 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
2695 /* don't scroll over playfield boundaries */
2696 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2697 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2699 /* don't scroll over playfield boundaries */
2700 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2701 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2704 scroll_x += (local_player->jx - old_jx);
2705 scroll_y += (local_player->jy - old_jy);
2707 /* don't scroll over playfield boundaries */
2708 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
2709 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
2711 /* don't scroll over playfield boundaries */
2712 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
2713 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
2716 RedrawPlayfield(TRUE, 0,0,0,0);
2722 int offset = (setup.scroll_delay ? 3 : 0);
2723 int jx = local_player->jx;
2724 int jy = local_player->jy;
2726 int scroll_xx = -999, scroll_yy = -999;
2728 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2730 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2733 int fx = FX, fy = FY;
2735 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2736 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2737 local_player->jx - MIDPOSX);
2739 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2740 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2741 local_player->jy - MIDPOSY);
2743 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2744 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2747 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2750 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2757 fx += dx * TILEX / 2;
2758 fy += dy * TILEY / 2;
2760 ScrollLevel(dx, dy);
2763 /* scroll in two steps of half tile size to make things smoother */
2764 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2766 Delay(wait_delay_value);
2768 /* scroll second step to align at full tile size */
2770 Delay(wait_delay_value);
2773 int scroll_xx = -999, scroll_yy = -999;
2775 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
2777 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
2780 int fx = FX, fy = FY;
2782 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2783 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2784 local_player->jx - MIDPOSX);
2786 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2787 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2788 local_player->jy - MIDPOSY);
2790 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
2791 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
2794 if (dx == 0 && dy == 0) /* no scrolling needed at all */
2797 if (scroll_xx == scroll_x && scroll_yy == scroll_y)
2804 fx += dx * TILEX / 2;
2805 fy += dy * TILEY / 2;
2807 ScrollLevel(dx, dy);
2810 /* scroll in two steps of half tile size to make things smoother */
2811 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
2813 Delay(wait_delay_value);
2815 /* scroll second step to align at full tile size */
2817 Delay(wait_delay_value);
2823 void Explode(int ex, int ey, int phase, int mode)
2830 /* !!! eliminate this variable !!! */
2831 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
2836 int last_phase = num_phase * delay;
2837 int half_phase = (num_phase / 2) * delay;
2838 int first_phase_after_start = EX_PHASE_START + 1;
2842 if (game.explosions_delayed)
2844 ExplodeField[ex][ey] = mode;
2848 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
2850 int center_element = Feld[ex][ey];
2853 printf("::: start explosion %d,%d [%d]\n", ex, ey, FrameCounter);
2857 /* --- This is only really needed (and now handled) in "Impact()". --- */
2858 /* do not explode moving elements that left the explode field in time */
2859 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
2860 center_element == EL_EMPTY &&
2861 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
2865 if (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER)
2866 PlayLevelSoundAction(ex, ey, ACTION_EXPLODING);
2868 /* remove things displayed in background while burning dynamite */
2869 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
2872 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
2874 /* put moving element to center field (and let it explode there) */
2875 center_element = MovingOrBlocked2Element(ex, ey);
2876 RemoveMovingField(ex, ey);
2877 Feld[ex][ey] = center_element;
2883 last_phase = element_info[center_element].explosion_delay + 1;
2885 last_phase = element_info[center_element].explosion_delay;
2889 printf("::: %d -> %d\n", center_element, last_phase);
2893 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
2895 int xx = x - ex + 1;
2896 int yy = y - ey + 1;
2901 if (!IN_LEV_FIELD(x, y) ||
2902 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
2903 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
2906 if (!IN_LEV_FIELD(x, y) ||
2907 (mode != EX_TYPE_NORMAL && (x != ex || y != ey)))
2911 if (!IN_LEV_FIELD(x, y) ||
2912 ((mode != EX_TYPE_NORMAL ||
2913 center_element == EL_AMOEBA_TO_DIAMOND) &&
2914 (x != ex || y != ey)))
2918 element = Feld[x][y];
2920 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
2922 element = MovingOrBlocked2Element(x, y);
2924 if (!IS_EXPLOSION_PROOF(element))
2925 RemoveMovingField(x, y);
2931 if (IS_EXPLOSION_PROOF(element))
2934 /* indestructible elements can only explode in center (but not flames) */
2935 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey)) ||
2936 element == EL_FLAMES)
2941 if ((IS_INDESTRUCTIBLE(element) &&
2942 (game.engine_version < VERSION_IDENT(2,2,0,0) ||
2943 (!IS_WALKABLE_OVER(element) && !IS_WALKABLE_UNDER(element)))) ||
2944 element == EL_FLAMES)
2948 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
2950 if (IS_ACTIVE_BOMB(element))
2952 /* re-activate things under the bomb like gate or penguin */
2953 Feld[x][y] = (Store[x][y] ? Store[x][y] : EL_EMPTY);
2960 /* save walkable background elements while explosion on same tile */
2962 if (IS_INDESTRUCTIBLE(element))
2963 Back[x][y] = element;
2965 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element))
2966 Back[x][y] = element;
2969 /* ignite explodable elements reached by other explosion */
2970 if (element == EL_EXPLOSION)
2971 element = Store2[x][y];
2974 if (AmoebaNr[x][y] &&
2975 (element == EL_AMOEBA_FULL ||
2976 element == EL_BD_AMOEBA ||
2977 element == EL_AMOEBA_GROWING))
2979 AmoebaCnt[AmoebaNr[x][y]]--;
2980 AmoebaCnt2[AmoebaNr[x][y]]--;
2986 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
2988 switch(StorePlayer[ex][ey])
2991 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
2994 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
2997 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3001 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3006 if (PLAYERINFO(ex, ey)->use_murphy_graphic)
3007 Store[x][y] = EL_EMPTY;
3009 if (game.emulation == EMU_SUPAPLEX)
3010 Store[x][y] = EL_EMPTY;
3013 else if (center_element == EL_MOLE)
3014 Store[x][y] = EL_EMERALD_RED;
3015 else if (center_element == EL_PENGUIN)
3016 Store[x][y] = EL_EMERALD_PURPLE;
3017 else if (center_element == EL_BUG)
3018 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3019 else if (center_element == EL_BD_BUTTERFLY)
3020 Store[x][y] = EL_BD_DIAMOND;
3021 else if (center_element == EL_SP_ELECTRON)
3022 Store[x][y] = EL_SP_INFOTRON;
3023 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3024 Store[x][y] = level.amoeba_content;
3025 else if (center_element == EL_YAMYAM)
3026 Store[x][y] = level.yamyam_content[game.yamyam_content_nr][xx][yy];
3027 else if (IS_CUSTOM_ELEMENT(center_element) &&
3028 element_info[center_element].content[xx][yy] != EL_EMPTY)
3029 Store[x][y] = element_info[center_element].content[xx][yy];
3030 else if (element == EL_WALL_EMERALD)
3031 Store[x][y] = EL_EMERALD;
3032 else if (element == EL_WALL_DIAMOND)
3033 Store[x][y] = EL_DIAMOND;
3034 else if (element == EL_WALL_BD_DIAMOND)
3035 Store[x][y] = EL_BD_DIAMOND;
3036 else if (element == EL_WALL_EMERALD_YELLOW)
3037 Store[x][y] = EL_EMERALD_YELLOW;
3038 else if (element == EL_WALL_EMERALD_RED)
3039 Store[x][y] = EL_EMERALD_RED;
3040 else if (element == EL_WALL_EMERALD_PURPLE)
3041 Store[x][y] = EL_EMERALD_PURPLE;
3042 else if (element == EL_WALL_PEARL)
3043 Store[x][y] = EL_PEARL;
3044 else if (element == EL_WALL_CRYSTAL)
3045 Store[x][y] = EL_CRYSTAL;
3046 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3047 Store[x][y] = element_info[element].content[1][1];
3049 Store[x][y] = EL_EMPTY;
3051 if (x != ex || y != ey ||
3052 center_element == EL_AMOEBA_TO_DIAMOND || mode == EX_TYPE_BORDER)
3053 Store2[x][y] = element;
3056 if (AmoebaNr[x][y] &&
3057 (element == EL_AMOEBA_FULL ||
3058 element == EL_BD_AMOEBA ||
3059 element == EL_AMOEBA_GROWING))
3061 AmoebaCnt[AmoebaNr[x][y]]--;
3062 AmoebaCnt2[AmoebaNr[x][y]]--;
3068 MovDir[x][y] = MovPos[x][y] = 0;
3069 GfxDir[x][y] = MovDir[x][y];
3074 Feld[x][y] = EL_EXPLOSION;
3076 GfxElement[x][y] = center_element;
3078 GfxElement[x][y] = EL_UNDEFINED;
3081 ExplodePhase[x][y] = 1;
3083 ExplodeDelay[x][y] = last_phase;
3088 GfxFrame[x][y] = 0; /* animation does not start until next frame */
3090 GfxFrame[x][y] = -1; /* animation does not start until next frame */
3097 if (center_element == EL_YAMYAM)
3098 game.yamyam_content_nr =
3099 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3112 GfxFrame[x][y] = 0; /* restart explosion animation */
3116 printf(":X: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3120 last_phase = ExplodeDelay[x][y];
3123 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3127 /* activate this even in non-DEBUG version until cause for crash in
3128 getGraphicAnimationFrame() (see below) is found and eliminated */
3132 if (GfxElement[x][y] == EL_UNDEFINED)
3135 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3136 printf("Explode(): This should never happen!\n");
3139 GfxElement[x][y] = EL_EMPTY;
3145 border_element = Store2[x][y];
3146 if (IS_PLAYER(x, y))
3147 border_element = StorePlayer[x][y];
3150 printf("::: phase == %d\n", phase);
3153 if (phase == element_info[border_element].ignition_delay ||
3154 phase == last_phase)
3156 boolean border_explosion = FALSE;
3159 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present)
3161 if (IS_PLAYER(x, y))
3164 KillHeroUnlessExplosionProtected(x, y);
3165 border_explosion = TRUE;
3168 if (phase == last_phase)
3169 printf("::: IS_PLAYER\n");
3172 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3174 Feld[x][y] = Store2[x][y];
3177 border_explosion = TRUE;
3180 if (phase == last_phase)
3181 printf("::: CAN_EXPLODE_BY_EXPLOSION\n");
3184 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3186 AmoebeUmwandeln(x, y);
3188 border_explosion = TRUE;
3191 if (phase == last_phase)
3192 printf("::: EL_AMOEBA_TO_DIAMOND [%d, %d] [%d]\n",
3193 element_info[border_element].explosion_delay,
3194 element_info[border_element].ignition_delay,
3200 /* if an element just explodes due to another explosion (chain-reaction),
3201 do not immediately end the new explosion when it was the last frame of
3202 the explosion (as it would be done in the following "if"-statement!) */
3203 if (border_explosion && phase == last_phase)
3210 if (phase == first_phase_after_start)
3212 int element = Store2[x][y];
3214 if (element == EL_BLACK_ORB)
3216 Feld[x][y] = Store2[x][y];
3221 else if (phase == half_phase)
3223 int element = Store2[x][y];
3225 if (IS_PLAYER(x, y))
3226 KillHeroUnlessExplosionProtected(x, y);
3227 else if (CAN_EXPLODE_BY_EXPLOSION(element))
3229 Feld[x][y] = Store2[x][y];
3233 else if (element == EL_AMOEBA_TO_DIAMOND)
3234 AmoebeUmwandeln(x, y);
3238 if (phase == last_phase)
3243 printf("::: done: phase == %d\n", phase);
3247 printf("::: explosion %d,%d done [%d]\n", x, y, FrameCounter);
3250 element = Feld[x][y] = Store[x][y];
3251 Store[x][y] = Store2[x][y] = 0;
3252 GfxElement[x][y] = EL_UNDEFINED;
3254 /* player can escape from explosions and might therefore be still alive */
3255 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3256 element <= EL_PLAYER_IS_EXPLODING_4)
3257 Feld[x][y] = (stored_player[element - EL_PLAYER_IS_EXPLODING_1].active ?
3259 element == EL_PLAYER_IS_EXPLODING_1 ? EL_EMERALD_YELLOW :
3260 element == EL_PLAYER_IS_EXPLODING_2 ? EL_EMERALD_RED :
3261 element == EL_PLAYER_IS_EXPLODING_3 ? EL_EMERALD :
3264 /* restore probably existing indestructible background element */
3265 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3266 element = Feld[x][y] = Back[x][y];
3269 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3270 GfxDir[x][y] = MV_NO_MOVING;
3271 ChangeDelay[x][y] = 0;
3272 ChangePage[x][y] = -1;
3275 InitField_WithBug2(x, y, FALSE);
3277 InitField(x, y, FALSE);
3279 /* !!! not needed !!! */
3281 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
3282 CAN_MOVE(Feld[x][y]) && Feld[x][y] != EL_MOLE)
3285 if (CAN_MOVE(element))
3290 DrawLevelField(x, y);
3292 TestIfElementTouchesCustomElement(x, y);
3294 if (GFX_CRUMBLED(element))
3295 DrawLevelFieldCrumbledSandNeighbours(x, y);
3297 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3298 StorePlayer[x][y] = 0;
3300 if (ELEM_IS_PLAYER(element))
3301 RelocatePlayer(x, y, element);
3304 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3306 else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3310 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3312 int stored = Store[x][y];
3313 int graphic = (game.emulation != EMU_SUPAPLEX ? IMG_EXPLOSION :
3314 stored == EL_SP_INFOTRON ? IMG_SP_EXPLOSION_INFOTRON :
3318 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3320 int frame = getGraphicAnimationFrame(graphic, phase - delay);
3324 printf("::: phase == %d [%d]\n", phase, GfxFrame[x][y]);
3328 printf("::: %d / %d [%d - %d]\n",
3329 GfxFrame[x][y], phase - delay, phase, delay);
3333 printf("::: %d ['%s'] -> %d\n", GfxElement[x][y],
3334 element_info[GfxElement[x][y]].token_name,
3339 DrawLevelFieldCrumbledSand(x, y);
3341 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3343 DrawLevelElement(x, y, Back[x][y]);
3344 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3346 else if (IS_WALKABLE_UNDER(Back[x][y]))
3348 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3349 DrawLevelElementThruMask(x, y, Back[x][y]);
3351 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3352 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3356 void DynaExplode(int ex, int ey)
3359 int dynabomb_element = Feld[ex][ey];
3360 int dynabomb_size = 1;
3361 boolean dynabomb_xl = FALSE;
3362 struct PlayerInfo *player;
3363 static int xy[4][2] =
3371 if (IS_ACTIVE_BOMB(dynabomb_element))
3373 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3374 dynabomb_size = player->dynabomb_size;
3375 dynabomb_xl = player->dynabomb_xl;
3376 player->dynabombs_left++;
3379 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3381 for (i = 0; i < NUM_DIRECTIONS; i++)
3383 for (j = 1; j <= dynabomb_size; j++)
3385 int x = ex + j * xy[i][0];
3386 int y = ey + j * xy[i][1];
3389 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3392 element = Feld[x][y];
3394 /* do not restart explosions of fields with active bombs */
3395 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3398 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3400 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
3401 if (element != EL_EMPTY &&
3402 element != EL_SAND &&
3403 element != EL_EXPLOSION &&
3410 void Bang(int x, int y)
3413 int element = MovingOrBlocked2Element(x, y);
3415 int element = Feld[x][y];
3419 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3421 if (IS_PLAYER(x, y))
3424 struct PlayerInfo *player = PLAYERINFO(x, y);
3426 element = Feld[x][y] = (player->use_murphy_graphic ? EL_SP_MURPHY :
3427 player->element_nr);
3432 PlayLevelSoundAction(x, y, ACTION_EXPLODING);
3434 if (game.emulation == EMU_SUPAPLEX)
3435 PlayLevelSound(x, y, SND_SP_ELEMENT_EXPLODING);
3437 PlayLevelSound(x, y, SND_ELEMENT_EXPLODING);
3442 if (IS_PLAYER(x, y)) /* remove objects that might cause smaller explosion */
3450 case EL_BD_BUTTERFLY:
3453 case EL_DARK_YAMYAM:
3457 RaiseScoreElement(element);
3458 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3460 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3461 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3462 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3463 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3464 case EL_DYNABOMB_INCREASE_NUMBER:
3465 case EL_DYNABOMB_INCREASE_SIZE:
3466 case EL_DYNABOMB_INCREASE_POWER:
3471 case EL_LAMP_ACTIVE:
3473 case EL_AMOEBA_TO_DIAMOND:
3475 if (IS_PLAYER(x, y))
3476 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3478 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3481 if (CAN_EXPLODE_CROSS(element))
3483 Explode(x, y, EX_PHASE_START, EX_TYPE_CROSS);
3487 else if (CAN_EXPLODE_1X1(element))
3488 Explode(x, y, EX_PHASE_START, EX_TYPE_CENTER);
3490 Explode(x, y, EX_PHASE_START, EX_TYPE_NORMAL);
3494 CheckTriggeredElementChange(x, y, element, CE_OTHER_IS_EXPLODING);
3497 void SplashAcid(int x, int y)
3500 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3501 (!IN_LEV_FIELD(x - 1, y - 2) ||
3502 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3503 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3505 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3506 (!IN_LEV_FIELD(x + 1, y - 2) ||
3507 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3508 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3510 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3512 /* input: position of element entering acid (obsolete) */
3514 int element = Feld[x][y];
3516 if (!IN_LEV_FIELD(x, y + 1) || Feld[x][y + 1] != EL_ACID)
3519 if (element != EL_ACID_SPLASH_LEFT &&
3520 element != EL_ACID_SPLASH_RIGHT)
3522 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3524 if (IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y) &&
3525 (!IN_LEV_FIELD(x - 1, y - 1) ||
3526 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 1))))
3527 Feld[x - 1][y] = EL_ACID_SPLASH_LEFT;
3529 if (IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y) &&
3530 (!IN_LEV_FIELD(x + 1, y - 1) ||
3531 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 1))))
3532 Feld[x + 1][y] = EL_ACID_SPLASH_RIGHT;
3537 static void InitBeltMovement()
3539 static int belt_base_element[4] =
3541 EL_CONVEYOR_BELT_1_LEFT,
3542 EL_CONVEYOR_BELT_2_LEFT,
3543 EL_CONVEYOR_BELT_3_LEFT,
3544 EL_CONVEYOR_BELT_4_LEFT
3546 static int belt_base_active_element[4] =
3548 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3549 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3550 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3551 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3556 /* set frame order for belt animation graphic according to belt direction */
3557 for (i = 0; i < NUM_BELTS; i++)
3561 for (j = 0; j < NUM_BELT_PARTS; j++)
3563 int element = belt_base_active_element[belt_nr] + j;
3564 int graphic = el2img(element);
3566 if (game.belt_dir[i] == MV_LEFT)
3567 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3569 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3573 for (y = 0; y < lev_fieldy; y++)
3575 for (x = 0; x < lev_fieldx; x++)
3577 int element = Feld[x][y];
3579 for (i = 0; i < NUM_BELTS; i++)
3581 if (IS_BELT(element) && game.belt_dir[i] != MV_NO_MOVING)
3583 int e_belt_nr = getBeltNrFromBeltElement(element);
3586 if (e_belt_nr == belt_nr)
3588 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3590 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3598 static void ToggleBeltSwitch(int x, int y)
3600 static int belt_base_element[4] =
3602 EL_CONVEYOR_BELT_1_LEFT,
3603 EL_CONVEYOR_BELT_2_LEFT,
3604 EL_CONVEYOR_BELT_3_LEFT,
3605 EL_CONVEYOR_BELT_4_LEFT
3607 static int belt_base_active_element[4] =
3609 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3610 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3611 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3612 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3614 static int belt_base_switch_element[4] =
3616 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3617 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3618 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3619 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3621 static int belt_move_dir[4] =
3629 int element = Feld[x][y];
3630 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3631 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3632 int belt_dir = belt_move_dir[belt_dir_nr];
3635 if (!IS_BELT_SWITCH(element))
3638 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3639 game.belt_dir[belt_nr] = belt_dir;
3641 if (belt_dir_nr == 3)
3644 /* set frame order for belt animation graphic according to belt direction */
3645 for (i = 0; i < NUM_BELT_PARTS; i++)
3647 int element = belt_base_active_element[belt_nr] + i;
3648 int graphic = el2img(element);
3650 if (belt_dir == MV_LEFT)
3651 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3653 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3656 for (yy = 0; yy < lev_fieldy; yy++)
3658 for (xx = 0; xx < lev_fieldx; xx++)
3660 int element = Feld[xx][yy];
3662 if (IS_BELT_SWITCH(element))
3664 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3666 if (e_belt_nr == belt_nr)
3668 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3669 DrawLevelField(xx, yy);
3672 else if (IS_BELT(element) && belt_dir != MV_NO_MOVING)
3674 int e_belt_nr = getBeltNrFromBeltElement(element);
3676 if (e_belt_nr == belt_nr)
3678 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3680 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3681 DrawLevelField(xx, yy);
3684 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NO_MOVING)
3686 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3688 if (e_belt_nr == belt_nr)
3690 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
3692 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
3693 DrawLevelField(xx, yy);
3700 static void ToggleSwitchgateSwitch(int x, int y)
3704 game.switchgate_pos = !game.switchgate_pos;
3706 for (yy = 0; yy < lev_fieldy; yy++)
3708 for (xx = 0; xx < lev_fieldx; xx++)
3710 int element = Feld[xx][yy];
3712 if (element == EL_SWITCHGATE_SWITCH_UP ||
3713 element == EL_SWITCHGATE_SWITCH_DOWN)
3715 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
3716 DrawLevelField(xx, yy);
3718 else if (element == EL_SWITCHGATE_OPEN ||
3719 element == EL_SWITCHGATE_OPENING)
3721 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
3723 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
3725 PlayLevelSound(xx, yy, SND_SWITCHGATE_CLOSING);
3728 else if (element == EL_SWITCHGATE_CLOSED ||
3729 element == EL_SWITCHGATE_CLOSING)
3731 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
3733 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
3735 PlayLevelSound(xx, yy, SND_SWITCHGATE_OPENING);
3742 static int getInvisibleActiveFromInvisibleElement(int element)
3744 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
3745 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
3746 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
3750 static int getInvisibleFromInvisibleActiveElement(int element)
3752 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
3753 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
3754 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
3758 static void RedrawAllLightSwitchesAndInvisibleElements()
3762 for (y = 0; y < lev_fieldy; y++)
3764 for (x = 0; x < lev_fieldx; x++)
3766 int element = Feld[x][y];
3768 if (element == EL_LIGHT_SWITCH &&
3769 game.light_time_left > 0)
3771 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
3772 DrawLevelField(x, y);
3774 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
3775 game.light_time_left == 0)
3777 Feld[x][y] = EL_LIGHT_SWITCH;
3778 DrawLevelField(x, y);
3780 else if (element == EL_INVISIBLE_STEELWALL ||
3781 element == EL_INVISIBLE_WALL ||
3782 element == EL_INVISIBLE_SAND)
3784 if (game.light_time_left > 0)
3785 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
3787 DrawLevelField(x, y);
3789 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
3790 element == EL_INVISIBLE_WALL_ACTIVE ||
3791 element == EL_INVISIBLE_SAND_ACTIVE)
3793 if (game.light_time_left == 0)
3794 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
3796 DrawLevelField(x, y);
3802 static void ToggleLightSwitch(int x, int y)
3804 int element = Feld[x][y];
3806 game.light_time_left =
3807 (element == EL_LIGHT_SWITCH ?
3808 level.time_light * FRAMES_PER_SECOND : 0);
3810 RedrawAllLightSwitchesAndInvisibleElements();
3813 static void ActivateTimegateSwitch(int x, int y)
3817 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
3819 for (yy = 0; yy < lev_fieldy; yy++)
3821 for (xx = 0; xx < lev_fieldx; xx++)
3823 int element = Feld[xx][yy];
3825 if (element == EL_TIMEGATE_CLOSED ||
3826 element == EL_TIMEGATE_CLOSING)
3828 Feld[xx][yy] = EL_TIMEGATE_OPENING;
3829 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
3833 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
3835 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
3836 DrawLevelField(xx, yy);
3843 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
3846 inline static int getElementMoveStepsize(int x, int y)
3848 int element = Feld[x][y];
3849 int direction = MovDir[x][y];
3850 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
3851 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
3852 int horiz_move = (dx != 0);
3853 int sign = (horiz_move ? dx : dy);
3854 int step = sign * element_info[element].move_stepsize;
3856 /* special values for move stepsize for spring and things on conveyor belt */
3860 if (element == EL_SPRING)
3861 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3862 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
3863 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3864 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3866 if (CAN_FALL(element) &&
3867 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
3868 step = sign * MOVE_STEPSIZE_NORMAL / 2;
3869 else if (element == EL_SPRING)
3870 step = sign * MOVE_STEPSIZE_NORMAL * 2;
3877 void Impact(int x, int y)
3879 boolean lastline = (y == lev_fieldy-1);
3880 boolean object_hit = FALSE;
3881 boolean impact = (lastline || object_hit);
3882 int element = Feld[x][y];
3883 int smashed = EL_STEELWALL;
3885 if (!lastline) /* check if element below was hit */
3887 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
3890 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
3891 MovDir[x][y + 1] != MV_DOWN ||
3892 MovPos[x][y + 1] <= TILEY / 2));
3895 object_hit = !IS_FREE(x, y + 1);
3898 /* do not smash moving elements that left the smashed field in time */
3899 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
3900 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
3904 smashed = MovingOrBlocked2Element(x, y + 1);
3906 impact = (lastline || object_hit);
3909 if (!lastline && smashed == EL_ACID) /* element falls into acid */
3911 SplashAcid(x, y + 1);
3915 /* only reset graphic animation if graphic really changes after impact */
3917 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
3919 ResetGfxAnimation(x, y);
3920 DrawLevelField(x, y);
3923 if (impact && CAN_EXPLODE_IMPACT(element))
3928 else if (impact && element == EL_PEARL)
3930 Feld[x][y] = EL_PEARL_BREAKING;
3931 PlayLevelSound(x, y, SND_PEARL_BREAKING);
3934 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
3936 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
3941 if (impact && element == EL_AMOEBA_DROP)
3943 if (object_hit && IS_PLAYER(x, y + 1))
3944 KillHeroUnlessEnemyProtected(x, y + 1);
3945 else if (object_hit && smashed == EL_PENGUIN)
3949 Feld[x][y] = EL_AMOEBA_GROWING;
3950 Store[x][y] = EL_AMOEBA_WET;
3952 ResetRandomAnimationValue(x, y);
3957 if (object_hit) /* check which object was hit */
3959 if (CAN_PASS_MAGIC_WALL(element) &&
3960 (smashed == EL_MAGIC_WALL ||
3961 smashed == EL_BD_MAGIC_WALL))
3964 int activated_magic_wall =
3965 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
3966 EL_BD_MAGIC_WALL_ACTIVE);
3968 /* activate magic wall / mill */
3969 for (yy = 0; yy < lev_fieldy; yy++)
3970 for (xx = 0; xx < lev_fieldx; xx++)
3971 if (Feld[xx][yy] == smashed)
3972 Feld[xx][yy] = activated_magic_wall;
3974 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
3975 game.magic_wall_active = TRUE;
3977 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
3978 SND_MAGIC_WALL_ACTIVATING :
3979 SND_BD_MAGIC_WALL_ACTIVATING));
3982 if (IS_PLAYER(x, y + 1))
3984 if (CAN_SMASH_PLAYER(element))
3986 KillHeroUnlessEnemyProtected(x, y + 1);
3990 else if (smashed == EL_PENGUIN)
3992 if (CAN_SMASH_PLAYER(element))
3998 else if (element == EL_BD_DIAMOND)
4000 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4006 else if (((element == EL_SP_INFOTRON ||
4007 element == EL_SP_ZONK) &&
4008 (smashed == EL_SP_SNIKSNAK ||
4009 smashed == EL_SP_ELECTRON ||
4010 smashed == EL_SP_DISK_ORANGE)) ||
4011 (element == EL_SP_INFOTRON &&
4012 smashed == EL_SP_DISK_YELLOW))
4018 else if (CAN_SMASH_ENEMIES(element) && IS_CLASSIC_ENEMY(smashed))
4024 else if (CAN_SMASH_EVERYTHING(element))
4026 if (IS_CLASSIC_ENEMY(smashed) ||
4027 CAN_EXPLODE_SMASHED(smashed))
4032 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4034 if (smashed == EL_LAMP ||
4035 smashed == EL_LAMP_ACTIVE)
4040 else if (smashed == EL_NUT)
4042 Feld[x][y + 1] = EL_NUT_BREAKING;
4043 PlayLevelSound(x, y, SND_NUT_BREAKING);
4044 RaiseScoreElement(EL_NUT);
4047 else if (smashed == EL_PEARL)
4049 Feld[x][y + 1] = EL_PEARL_BREAKING;
4050 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4053 else if (smashed == EL_DIAMOND)
4055 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4056 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4059 else if (IS_BELT_SWITCH(smashed))
4061 ToggleBeltSwitch(x, y + 1);
4063 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4064 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4066 ToggleSwitchgateSwitch(x, y + 1);
4068 else if (smashed == EL_LIGHT_SWITCH ||
4069 smashed == EL_LIGHT_SWITCH_ACTIVE)
4071 ToggleLightSwitch(x, y + 1);
4076 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4079 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4081 CheckTriggeredElementChangeSide(x, y + 1, smashed,
4082 CE_OTHER_IS_SWITCHING, CH_SIDE_TOP);
4083 CheckElementChangeSide(x, y + 1, smashed, element,
4084 CE_SWITCHED, CH_SIDE_TOP);
4089 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4094 /* play sound of magic wall / mill */
4096 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4097 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4099 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4100 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4101 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4102 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4107 /* play sound of object that hits the ground */
4108 if (lastline || object_hit)
4109 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4112 inline static void TurnRoundExt(int x, int y)
4124 { 0, 0 }, { 0, 0 }, { 0, 0 },
4129 int left, right, back;
4133 { MV_DOWN, MV_UP, MV_RIGHT },
4134 { MV_UP, MV_DOWN, MV_LEFT },
4136 { MV_LEFT, MV_RIGHT, MV_DOWN },
4140 { MV_RIGHT, MV_LEFT, MV_UP }
4143 int element = Feld[x][y];
4144 int move_pattern = element_info[element].move_pattern;
4146 int old_move_dir = MovDir[x][y];
4147 int left_dir = turn[old_move_dir].left;
4148 int right_dir = turn[old_move_dir].right;
4149 int back_dir = turn[old_move_dir].back;
4151 int left_dx = move_xy[left_dir].x, left_dy = move_xy[left_dir].y;
4152 int right_dx = move_xy[right_dir].x, right_dy = move_xy[right_dir].y;
4153 int move_dx = move_xy[old_move_dir].x, move_dy = move_xy[old_move_dir].y;
4154 int back_dx = move_xy[back_dir].x, back_dy = move_xy[back_dir].y;
4156 int left_x = x + left_dx, left_y = y + left_dy;
4157 int right_x = x + right_dx, right_y = y + right_dy;
4158 int move_x = x + move_dx, move_y = y + move_dy;
4162 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4164 TestIfBadThingTouchesOtherBadThing(x, y);
4166 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4167 MovDir[x][y] = right_dir;
4168 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4169 MovDir[x][y] = left_dir;
4171 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4173 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4177 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
4178 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4180 TestIfBadThingTouchesOtherBadThing(x, y);
4182 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4183 MovDir[x][y] = left_dir;
4184 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4185 MovDir[x][y] = right_dir;
4187 if ((element == EL_SPACESHIP ||
4188 element == EL_SP_SNIKSNAK ||
4189 element == EL_SP_ELECTRON)
4190 && MovDir[x][y] != old_move_dir)
4192 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4196 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4198 TestIfBadThingTouchesOtherBadThing(x, y);
4200 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4201 MovDir[x][y] = left_dir;
4202 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4203 MovDir[x][y] = right_dir;
4205 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4207 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4210 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4212 TestIfBadThingTouchesOtherBadThing(x, y);
4214 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4215 MovDir[x][y] = left_dir;
4216 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4217 MovDir[x][y] = right_dir;
4219 if (MovDir[x][y] != old_move_dir)
4223 else if (element == EL_YAMYAM)
4225 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4226 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4228 if (can_turn_left && can_turn_right)
4229 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4230 else if (can_turn_left)
4231 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4232 else if (can_turn_right)
4233 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4235 MovDir[x][y] = back_dir;
4237 MovDelay[x][y] = 16 + 16 * RND(3);
4239 else if (element == EL_DARK_YAMYAM)
4241 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4243 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4246 if (can_turn_left && can_turn_right)
4247 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4248 else if (can_turn_left)
4249 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4250 else if (can_turn_right)
4251 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4253 MovDir[x][y] = back_dir;
4255 MovDelay[x][y] = 16 + 16 * RND(3);
4257 else if (element == EL_PACMAN)
4259 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4260 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4262 if (can_turn_left && can_turn_right)
4263 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4264 else if (can_turn_left)
4265 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4266 else if (can_turn_right)
4267 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4269 MovDir[x][y] = back_dir;
4271 MovDelay[x][y] = 6 + RND(40);
4273 else if (element == EL_PIG)
4275 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4276 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4277 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4278 boolean should_turn_left, should_turn_right, should_move_on;
4280 int rnd = RND(rnd_value);
4282 should_turn_left = (can_turn_left &&
4284 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4285 y + back_dy + left_dy)));
4286 should_turn_right = (can_turn_right &&
4288 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4289 y + back_dy + right_dy)));
4290 should_move_on = (can_move_on &&
4293 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4294 y + move_dy + left_dy) ||
4295 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4296 y + move_dy + right_dy)));
4298 if (should_turn_left || should_turn_right || should_move_on)
4300 if (should_turn_left && should_turn_right && should_move_on)
4301 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4302 rnd < 2 * rnd_value / 3 ? right_dir :
4304 else if (should_turn_left && should_turn_right)
4305 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4306 else if (should_turn_left && should_move_on)
4307 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4308 else if (should_turn_right && should_move_on)
4309 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4310 else if (should_turn_left)
4311 MovDir[x][y] = left_dir;
4312 else if (should_turn_right)
4313 MovDir[x][y] = right_dir;
4314 else if (should_move_on)
4315 MovDir[x][y] = old_move_dir;
4317 else if (can_move_on && rnd > rnd_value / 8)
4318 MovDir[x][y] = old_move_dir;
4319 else if (can_turn_left && can_turn_right)
4320 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4321 else if (can_turn_left && rnd > rnd_value / 8)
4322 MovDir[x][y] = left_dir;
4323 else if (can_turn_right && rnd > rnd_value/8)
4324 MovDir[x][y] = right_dir;
4326 MovDir[x][y] = back_dir;
4328 xx = x + move_xy[MovDir[x][y]].x;
4329 yy = y + move_xy[MovDir[x][y]].y;
4331 if (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy]))
4332 MovDir[x][y] = old_move_dir;
4336 else if (element == EL_DRAGON)
4338 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4339 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4340 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4342 int rnd = RND(rnd_value);
4345 if (FrameCounter < 1 && x == 0 && y == 29)
4346 printf(":2: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4349 if (can_move_on && rnd > rnd_value / 8)
4350 MovDir[x][y] = old_move_dir;
4351 else if (can_turn_left && can_turn_right)
4352 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4353 else if (can_turn_left && rnd > rnd_value / 8)
4354 MovDir[x][y] = left_dir;
4355 else if (can_turn_right && rnd > rnd_value / 8)
4356 MovDir[x][y] = right_dir;
4358 MovDir[x][y] = back_dir;
4360 xx = x + move_xy[MovDir[x][y]].x;
4361 yy = y + move_xy[MovDir[x][y]].y;
4364 if (FrameCounter < 1 && x == 0 && y == 29)
4365 printf(":3: %d/%d: %d (%d/%d: %d) [%d]\n", x, y, MovDir[x][y],
4366 xx, yy, Feld[xx][yy],
4371 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4372 MovDir[x][y] = old_move_dir;
4374 if (!IS_FREE(xx, yy))
4375 MovDir[x][y] = old_move_dir;
4379 if (FrameCounter < 1 && x == 0 && y == 29)
4380 printf(":4: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
4385 else if (element == EL_MOLE)
4387 boolean can_move_on =
4388 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4389 IS_AMOEBOID(Feld[move_x][move_y]) ||
4390 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4393 boolean can_turn_left =
4394 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4395 IS_AMOEBOID(Feld[left_x][left_y])));
4397 boolean can_turn_right =
4398 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4399 IS_AMOEBOID(Feld[right_x][right_y])));
4401 if (can_turn_left && can_turn_right)
4402 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4403 else if (can_turn_left)
4404 MovDir[x][y] = left_dir;
4406 MovDir[x][y] = right_dir;
4409 if (MovDir[x][y] != old_move_dir)
4412 else if (element == EL_BALLOON)
4414 MovDir[x][y] = game.balloon_dir;
4417 else if (element == EL_SPRING)
4420 if (MovDir[x][y] & MV_HORIZONTAL &&
4421 !SPRING_CAN_ENTER_FIELD(element, move_x, move_y))
4422 MovDir[x][y] = MV_NO_MOVING;
4424 if (MovDir[x][y] & MV_HORIZONTAL &&
4425 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4426 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4427 MovDir[x][y] = MV_NO_MOVING;
4432 else if (element == EL_ROBOT ||
4433 element == EL_SATELLITE ||
4434 element == EL_PENGUIN)
4436 int attr_x = -1, attr_y = -1;
4447 for (i = 0; i < MAX_PLAYERS; i++)
4449 struct PlayerInfo *player = &stored_player[i];
4450 int jx = player->jx, jy = player->jy;
4452 if (!player->active)
4456 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4464 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0)
4470 if (element == EL_PENGUIN)
4473 static int xy[4][2] =
4481 for (i = 0; i < NUM_DIRECTIONS; i++)
4483 int ex = x + xy[i][0];
4484 int ey = y + xy[i][1];
4486 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4495 MovDir[x][y] = MV_NO_MOVING;
4497 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4498 else if (attr_x > x)
4499 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4501 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4502 else if (attr_y > y)
4503 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4505 if (element == EL_ROBOT)
4509 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4510 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4511 Moving2Blocked(x, y, &newx, &newy);
4513 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4514 MovDelay[x][y] = 8 + 8 * !RND(3);
4516 MovDelay[x][y] = 16;
4518 else if (element == EL_PENGUIN)
4524 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4526 boolean first_horiz = RND(2);
4527 int new_move_dir = MovDir[x][y];
4530 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4531 Moving2Blocked(x, y, &newx, &newy);
4533 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4537 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4538 Moving2Blocked(x, y, &newx, &newy);
4540 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4543 MovDir[x][y] = old_move_dir;
4547 else /* (element == EL_SATELLITE) */
4553 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4555 boolean first_horiz = RND(2);
4556 int new_move_dir = MovDir[x][y];
4559 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4560 Moving2Blocked(x, y, &newx, &newy);
4562 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4566 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4567 Moving2Blocked(x, y, &newx, &newy);
4569 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4572 MovDir[x][y] = old_move_dir;
4577 else if (move_pattern == MV_TURNING_LEFT ||
4578 move_pattern == MV_TURNING_RIGHT ||
4579 move_pattern == MV_TURNING_LEFT_RIGHT ||
4580 move_pattern == MV_TURNING_RIGHT_LEFT ||
4581 move_pattern == MV_TURNING_RANDOM ||
4582 move_pattern == MV_ALL_DIRECTIONS)
4584 boolean can_turn_left =
4585 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4586 boolean can_turn_right =
4587 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4589 if (move_pattern == MV_TURNING_LEFT)
4590 MovDir[x][y] = left_dir;
4591 else if (move_pattern == MV_TURNING_RIGHT)
4592 MovDir[x][y] = right_dir;
4593 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4594 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4595 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4596 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4597 else if (move_pattern == MV_TURNING_RANDOM)
4598 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4599 can_turn_right && !can_turn_left ? right_dir :
4600 RND(2) ? left_dir : right_dir);
4601 else if (can_turn_left && can_turn_right)
4602 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4603 else if (can_turn_left)
4604 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4605 else if (can_turn_right)
4606 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4608 MovDir[x][y] = back_dir;
4610 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4612 else if (move_pattern == MV_HORIZONTAL ||
4613 move_pattern == MV_VERTICAL)
4615 if (move_pattern & old_move_dir)
4616 MovDir[x][y] = back_dir;
4617 else if (move_pattern == MV_HORIZONTAL)
4618 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
4619 else if (move_pattern == MV_VERTICAL)
4620 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
4622 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4624 else if (move_pattern & MV_ANY_DIRECTION)
4626 MovDir[x][y] = move_pattern;
4627 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4629 else if (move_pattern == MV_ALONG_LEFT_SIDE)
4631 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
4632 MovDir[x][y] = left_dir;
4633 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4634 MovDir[x][y] = right_dir;
4636 if (MovDir[x][y] != old_move_dir)
4637 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4639 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
4641 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
4642 MovDir[x][y] = right_dir;
4643 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4644 MovDir[x][y] = left_dir;
4646 if (MovDir[x][y] != old_move_dir)
4647 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4649 else if (move_pattern == MV_TOWARDS_PLAYER ||
4650 move_pattern == MV_AWAY_FROM_PLAYER)
4652 int attr_x = -1, attr_y = -1;
4654 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
4665 for (i = 0; i < MAX_PLAYERS; i++)
4667 struct PlayerInfo *player = &stored_player[i];
4668 int jx = player->jx, jy = player->jy;
4670 if (!player->active)
4674 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4682 MovDir[x][y] = MV_NO_MOVING;
4684 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
4685 else if (attr_x > x)
4686 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
4688 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
4689 else if (attr_y > y)
4690 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
4692 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4694 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4696 boolean first_horiz = RND(2);
4697 int new_move_dir = MovDir[x][y];
4700 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4701 Moving2Blocked(x, y, &newx, &newy);
4703 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4707 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4708 Moving2Blocked(x, y, &newx, &newy);
4710 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4713 MovDir[x][y] = old_move_dir;
4716 else if (move_pattern == MV_WHEN_PUSHED ||
4717 move_pattern == MV_WHEN_DROPPED)
4719 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4720 MovDir[x][y] = MV_NO_MOVING;
4724 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
4726 static int test_xy[7][2] =
4736 static int test_dir[7] =
4746 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
4747 int move_preference = -1000000; /* start with very low preference */
4748 int new_move_dir = MV_NO_MOVING;
4749 int start_test = RND(4);
4752 for (i = 0; i < NUM_DIRECTIONS; i++)
4754 int move_dir = test_dir[start_test + i];
4755 int move_dir_preference;
4757 xx = x + test_xy[start_test + i][0];
4758 yy = y + test_xy[start_test + i][1];
4760 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
4761 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
4763 new_move_dir = move_dir;
4768 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
4771 move_dir_preference = -1 * RunnerVisit[xx][yy];
4772 if (hunter_mode && PlayerVisit[xx][yy] > 0)
4773 move_dir_preference = PlayerVisit[xx][yy];
4775 if (move_dir_preference > move_preference)
4777 /* prefer field that has not been visited for the longest time */
4778 move_preference = move_dir_preference;
4779 new_move_dir = move_dir;
4781 else if (move_dir_preference == move_preference &&
4782 move_dir == old_move_dir)
4784 /* prefer last direction when all directions are preferred equally */
4785 move_preference = move_dir_preference;
4786 new_move_dir = move_dir;
4790 MovDir[x][y] = new_move_dir;
4791 if (old_move_dir != new_move_dir)
4796 static void TurnRound(int x, int y)
4798 int direction = MovDir[x][y];
4801 GfxDir[x][y] = MovDir[x][y];
4807 GfxDir[x][y] = MovDir[x][y];
4810 if (direction != MovDir[x][y])
4815 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
4818 GfxAction[x][y] = ACTION_WAITING;
4822 static boolean JustBeingPushed(int x, int y)
4826 for (i = 0; i < MAX_PLAYERS; i++)
4828 struct PlayerInfo *player = &stored_player[i];
4830 if (player->active && player->is_pushing && player->MovPos)
4832 int next_jx = player->jx + (player->jx - player->last_jx);
4833 int next_jy = player->jy + (player->jy - player->last_jy);
4835 if (x == next_jx && y == next_jy)
4843 void StartMoving(int x, int y)
4846 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
4848 boolean started_moving = FALSE; /* some elements can fall _and_ move */
4849 int element = Feld[x][y];
4855 if (MovDelay[x][y] == 0)
4856 GfxAction[x][y] = ACTION_DEFAULT;
4858 /* !!! this should be handled more generic (not only for mole) !!! */
4859 if (element != EL_MOLE && GfxAction[x][y] != ACTION_DIGGING)
4860 GfxAction[x][y] = ACTION_DEFAULT;
4863 if (CAN_FALL(element) && y < lev_fieldy - 1)
4865 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
4866 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
4867 if (JustBeingPushed(x, y))
4870 if (element == EL_QUICKSAND_FULL)
4872 if (IS_FREE(x, y + 1))
4874 InitMovingField(x, y, MV_DOWN);
4875 started_moving = TRUE;
4877 Feld[x][y] = EL_QUICKSAND_EMPTYING;
4878 Store[x][y] = EL_ROCK;
4880 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
4882 PlayLevelSound(x, y, SND_QUICKSAND_EMPTYING);
4885 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
4887 if (!MovDelay[x][y])
4888 MovDelay[x][y] = TILEY + 1;
4897 Feld[x][y] = EL_QUICKSAND_EMPTY;
4898 Feld[x][y + 1] = EL_QUICKSAND_FULL;
4899 Store[x][y + 1] = Store[x][y];
4902 PlayLevelSoundAction(x, y, ACTION_FILLING);
4904 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
4908 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
4909 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
4911 InitMovingField(x, y, MV_DOWN);
4912 started_moving = TRUE;
4914 Feld[x][y] = EL_QUICKSAND_FILLING;
4915 Store[x][y] = element;
4917 PlayLevelSoundAction(x, y, ACTION_FILLING);
4919 PlayLevelSound(x, y, SND_QUICKSAND_FILLING);
4922 else if (element == EL_MAGIC_WALL_FULL)
4924 if (IS_FREE(x, y + 1))
4926 InitMovingField(x, y, MV_DOWN);
4927 started_moving = TRUE;
4929 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
4930 Store[x][y] = EL_CHANGED(Store[x][y]);
4932 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4934 if (!MovDelay[x][y])
4935 MovDelay[x][y] = TILEY/4 + 1;
4944 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
4945 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
4946 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
4950 else if (element == EL_BD_MAGIC_WALL_FULL)
4952 if (IS_FREE(x, y + 1))
4954 InitMovingField(x, y, MV_DOWN);
4955 started_moving = TRUE;
4957 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
4958 Store[x][y] = EL_CHANGED2(Store[x][y]);
4960 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4962 if (!MovDelay[x][y])
4963 MovDelay[x][y] = TILEY/4 + 1;
4972 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
4973 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
4974 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
4978 else if (CAN_PASS_MAGIC_WALL(element) &&
4979 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4980 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4982 InitMovingField(x, y, MV_DOWN);
4983 started_moving = TRUE;
4986 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
4987 EL_BD_MAGIC_WALL_FILLING);
4988 Store[x][y] = element;
4991 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_ACID)
4993 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
4996 SplashAcid(x, y + 1);
4998 InitMovingField(x, y, MV_DOWN);
4999 started_moving = TRUE;
5001 Store[x][y] = EL_ACID;
5003 /* !!! TEST !!! better use "_FALLING" etc. !!! */
5004 GfxAction[x][y + 1] = ACTION_ACTIVE;
5008 else if ((game.engine_version < VERSION_IDENT(2,2,0,7) &&
5009 CAN_SMASH(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5010 (Feld[x][y + 1] == EL_BLOCKED)) ||
5011 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5012 CAN_SMASH(element) && WasJustFalling[x][y] &&
5013 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))))
5017 else if (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5018 CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5019 WasJustMoving[x][y] && !Pushed[x][y + 1])
5021 else if (CAN_SMASH(element) && Feld[x][y + 1] == EL_BLOCKED &&
5022 WasJustMoving[x][y])
5027 /* this is needed for a special case not covered by calling "Impact()"
5028 from "ContinueMoving()": if an element moves to a tile directly below
5029 another element which was just falling on that tile (which was empty
5030 in the previous frame), the falling element above would just stop
5031 instead of smashing the element below (in previous version, the above
5032 element was just checked for "moving" instead of "falling", resulting
5033 in incorrect smashes caused by horizontal movement of the above
5034 element; also, the case of the player being the element to smash was
5035 simply not covered here... :-/ ) */
5038 WasJustMoving[x][y] = 0;
5039 WasJustFalling[x][y] = 0;
5044 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5046 if (MovDir[x][y] == MV_NO_MOVING)
5048 InitMovingField(x, y, MV_DOWN);
5049 started_moving = TRUE;
5052 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5054 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5055 MovDir[x][y] = MV_DOWN;
5057 InitMovingField(x, y, MV_DOWN);
5058 started_moving = TRUE;
5060 else if (element == EL_AMOEBA_DROP)
5062 Feld[x][y] = EL_AMOEBA_GROWING;
5063 Store[x][y] = EL_AMOEBA_WET;
5065 /* Store[x][y + 1] must be zero, because:
5066 (EL_QUICKSAND_FULL -> EL_ROCK): Store[x][y + 1] == EL_QUICKSAND_EMPTY
5069 #if OLD_GAME_BEHAVIOUR
5070 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1])
5072 else if (IS_SLIPPERY(Feld[x][y + 1]) && !Store[x][y + 1] &&
5073 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5074 element != EL_DX_SUPABOMB)
5077 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5078 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5079 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5080 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5083 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5084 (IS_FREE(x - 1, y + 1) ||
5085 Feld[x - 1][y + 1] == EL_ACID));
5086 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5087 (IS_FREE(x + 1, y + 1) ||
5088 Feld[x + 1][y + 1] == EL_ACID));
5089 boolean can_fall_any = (can_fall_left || can_fall_right);
5090 boolean can_fall_both = (can_fall_left && can_fall_right);
5092 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5094 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5096 if (slippery_type == SLIPPERY_ONLY_LEFT)
5097 can_fall_right = FALSE;
5098 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5099 can_fall_left = FALSE;
5100 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5101 can_fall_right = FALSE;
5102 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5103 can_fall_left = FALSE;
5105 can_fall_any = (can_fall_left || can_fall_right);
5106 can_fall_both = (can_fall_left && can_fall_right);
5111 if (can_fall_both &&
5112 (game.emulation != EMU_BOULDERDASH &&
5113 element != EL_BD_ROCK && element != EL_BD_DIAMOND))
5114 can_fall_left = !(can_fall_right = RND(2));
5116 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5117 started_moving = TRUE;
5121 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5123 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5126 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5127 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5128 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5129 int belt_dir = game.belt_dir[belt_nr];
5131 if ((belt_dir == MV_LEFT && left_is_free) ||
5132 (belt_dir == MV_RIGHT && right_is_free))
5135 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5138 InitMovingField(x, y, belt_dir);
5139 started_moving = TRUE;
5142 Pushed[x][y] = TRUE;
5143 Pushed[nextx][y] = TRUE;
5146 GfxAction[x][y] = ACTION_DEFAULT;
5150 MovDir[x][y] = 0; /* if element was moving, stop it */
5155 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5156 if (CAN_MOVE(element) && !started_moving)
5158 int move_pattern = element_info[element].move_pattern;
5161 Moving2Blocked(x, y, &newx, &newy);
5164 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5167 if ((element == EL_SATELLITE ||
5168 element == EL_BALLOON ||
5169 element == EL_SPRING)
5170 && JustBeingPushed(x, y))
5175 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5176 WasJustMoving[x][y] && IN_LEV_FIELD(newx, newy) &&
5177 (Feld[newx][newy] == EL_BLOCKED || IS_PLAYER(newx, newy)))
5180 printf("::: element %d '%s' WasJustMoving %d [%d, %d, %d, %d]\n",
5181 element, element_info[element].token_name,
5182 WasJustMoving[x][y],
5183 HAS_ANY_CHANGE_EVENT(element, CE_HITTING_SOMETHING),
5184 HAS_ANY_CHANGE_EVENT(element, CE_HIT_BY_SOMETHING),
5185 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_IS_HITTING),
5186 HAS_ANY_CHANGE_EVENT(element, CE_OTHER_GETS_HIT));
5190 WasJustMoving[x][y] = 0;
5193 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5196 if (Feld[x][y] != element) /* element has changed */
5198 element = Feld[x][y];
5199 move_pattern = element_info[element].move_pattern;
5201 if (!CAN_MOVE(element))
5205 if (Feld[x][y] != element) /* element has changed */
5213 if (element == EL_SPRING && MovDir[x][y] == MV_DOWN)
5214 Feld[x][y + 1] = EL_EMPTY; /* was set to EL_BLOCKED above */
5216 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
5218 Moving2Blocked(x, y, &newx, &newy);
5219 if (Feld[newx][newy] == EL_BLOCKED)
5220 Feld[newx][newy] = EL_EMPTY; /* was set to EL_BLOCKED above */
5226 if (FrameCounter < 1 && x == 0 && y == 29)
5227 printf(":1: %d/%d: %d [%d]\n", x, y, MovDir[x][y], FrameCounter);
5230 if (!MovDelay[x][y]) /* start new movement phase */
5232 /* all objects that can change their move direction after each step
5233 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5235 if (element != EL_YAMYAM &&
5236 element != EL_DARK_YAMYAM &&
5237 element != EL_PACMAN &&
5238 !(move_pattern & MV_ANY_DIRECTION) &&
5239 move_pattern != MV_TURNING_LEFT &&
5240 move_pattern != MV_TURNING_RIGHT &&
5241 move_pattern != MV_TURNING_LEFT_RIGHT &&
5242 move_pattern != MV_TURNING_RIGHT_LEFT &&
5243 move_pattern != MV_TURNING_RANDOM)
5248 if (FrameCounter < 1 && x == 0 && y == 29)
5249 printf(":9: %d: %d [%d]\n", y, MovDir[x][y], FrameCounter);
5252 if (MovDelay[x][y] && (element == EL_BUG ||
5253 element == EL_SPACESHIP ||
5254 element == EL_SP_SNIKSNAK ||
5255 element == EL_SP_ELECTRON ||
5256 element == EL_MOLE))
5257 DrawLevelField(x, y);
5261 if (MovDelay[x][y]) /* wait some time before next movement */
5266 if (element == EL_YAMYAM)
5269 el_act_dir2img(EL_YAMYAM, ACTION_WAITING, MV_LEFT));
5270 DrawLevelElementAnimation(x, y, element);
5274 if (MovDelay[x][y]) /* element still has to wait some time */
5277 /* !!! PLACE THIS SOMEWHERE AFTER "TurnRound()" !!! */
5278 ResetGfxAnimation(x, y);
5282 if (GfxAction[x][y] != ACTION_WAITING)
5283 printf("::: %d: %d != ACTION_WAITING\n", element, GfxAction[x][y]);
5285 GfxAction[x][y] = ACTION_WAITING;
5289 if (element == EL_ROBOT ||
5291 element == EL_PACMAN ||
5293 element == EL_YAMYAM ||
5294 element == EL_DARK_YAMYAM)
5297 DrawLevelElementAnimation(x, y, element);
5299 DrawLevelElementAnimationIfNeeded(x, y, element);
5301 PlayLevelSoundAction(x, y, ACTION_WAITING);
5303 else if (element == EL_SP_ELECTRON)
5304 DrawLevelElementAnimationIfNeeded(x, y, element);
5305 else if (element == EL_DRAGON)
5308 int dir = MovDir[x][y];
5309 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5310 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5311 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5312 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5313 dir == MV_UP ? IMG_FLAMES_1_UP :
5314 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5315 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5318 printf("::: %d, %d\n", GfxAction[x][y], GfxFrame[x][y]);
5321 GfxAction[x][y] = ACTION_ATTACKING;
5323 if (IS_PLAYER(x, y))
5324 DrawPlayerField(x, y);
5326 DrawLevelField(x, y);
5328 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5330 for (i = 1; i <= 3; i++)
5332 int xx = x + i * dx;
5333 int yy = y + i * dy;
5334 int sx = SCREENX(xx);
5335 int sy = SCREENY(yy);
5336 int flame_graphic = graphic + (i - 1);
5338 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5343 int flamed = MovingOrBlocked2Element(xx, yy);
5347 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5349 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5350 RemoveMovingField(xx, yy);
5352 RemoveField(xx, yy);
5354 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5357 RemoveMovingField(xx, yy);
5361 if (ChangeDelay[xx][yy])
5362 printf("::: !!! [%d]\n", (IS_MOVING(xx, yy) ||
5363 Feld[xx][yy] == EL_BLOCKED));
5367 ChangeDelay[xx][yy] = 0;
5369 Feld[xx][yy] = EL_FLAMES;
5370 if (IN_SCR_FIELD(sx, sy))
5372 DrawLevelFieldCrumbledSand(xx, yy);
5373 DrawGraphic(sx, sy, flame_graphic, frame);
5378 if (Feld[xx][yy] == EL_FLAMES)
5379 Feld[xx][yy] = EL_EMPTY;
5380 DrawLevelField(xx, yy);
5385 if (MovDelay[x][y]) /* element still has to wait some time */
5387 PlayLevelSoundAction(x, y, ACTION_WAITING);
5393 /* special case of "moving" animation of waiting elements (FIX THIS !!!);
5394 for all other elements GfxAction will be set by InitMovingField() */
5395 if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
5396 GfxAction[x][y] = ACTION_MOVING;
5400 /* now make next step */
5402 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5404 if (DONT_COLLIDE_WITH(element) &&
5405 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5406 !PLAYER_ENEMY_PROTECTED(newx, newy))
5409 TestIfBadThingRunsIntoHero(x, y, MovDir[x][y]);
5413 /* player killed by element which is deadly when colliding with */
5415 KillHero(PLAYERINFO(newx, newy));
5422 else if (CAN_MOVE_INTO_ACID(element) &&
5423 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5424 (MovDir[x][y] == MV_DOWN ||
5425 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5427 else if (CAN_MOVE_INTO_ACID(element) && MovDir[x][y] == MV_DOWN &&
5428 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID)
5432 else if ((element == EL_PENGUIN ||
5433 element == EL_ROBOT ||
5434 element == EL_SATELLITE ||
5435 element == EL_BALLOON ||
5436 IS_CUSTOM_ELEMENT(element)) &&
5437 IN_LEV_FIELD(newx, newy) &&
5438 MovDir[x][y] == MV_DOWN && Feld[newx][newy] == EL_ACID)
5441 SplashAcid(newx, newy);
5442 Store[x][y] = EL_ACID;
5444 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5446 if (Feld[newx][newy] == EL_EXIT_OPEN)
5450 DrawLevelField(x, y);
5452 Feld[x][y] = EL_EMPTY;
5453 DrawLevelField(x, y);
5456 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5457 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5458 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5460 local_player->friends_still_needed--;
5461 if (!local_player->friends_still_needed &&
5462 !local_player->GameOver && AllPlayersGone)
5463 local_player->LevelSolved = local_player->GameOver = TRUE;
5467 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5469 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5470 DrawLevelField(newx, newy);
5472 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
5474 else if (!IS_FREE(newx, newy))
5476 GfxAction[x][y] = ACTION_WAITING;
5478 if (IS_PLAYER(x, y))
5479 DrawPlayerField(x, y);
5481 DrawLevelField(x, y);
5486 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5488 if (IS_FOOD_PIG(Feld[newx][newy]))
5490 if (IS_MOVING(newx, newy))
5491 RemoveMovingField(newx, newy);
5494 Feld[newx][newy] = EL_EMPTY;
5495 DrawLevelField(newx, newy);
5498 PlayLevelSound(x, y, SND_PIG_DIGGING);
5500 else if (!IS_FREE(newx, newy))
5502 if (IS_PLAYER(x, y))
5503 DrawPlayerField(x, y);
5505 DrawLevelField(x, y);
5514 else if (move_pattern & MV_MAZE_RUNNER_STYLE && IN_LEV_FIELD(newx, newy))
5517 else if (IS_CUSTOM_ELEMENT(element) &&
5518 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy)
5522 !IS_FREE(newx, newy)
5527 int new_element = Feld[newx][newy];
5530 printf("::: '%s' digs '%s' [%d]\n",
5531 element_info[element].token_name,
5532 element_info[Feld[newx][newy]].token_name,
5533 StorePlayer[newx][newy]);
5536 if (!IS_FREE(newx, newy))
5538 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5539 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5542 /* no element can dig solid indestructible elements */
5543 if (IS_INDESTRUCTIBLE(new_element) &&
5544 !IS_DIGGABLE(new_element) &&
5545 !IS_COLLECTIBLE(new_element))
5548 if (AmoebaNr[newx][newy] &&
5549 (new_element == EL_AMOEBA_FULL ||
5550 new_element == EL_BD_AMOEBA ||
5551 new_element == EL_AMOEBA_GROWING))
5553 AmoebaCnt[AmoebaNr[newx][newy]]--;
5554 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5557 if (IS_MOVING(newx, newy))
5558 RemoveMovingField(newx, newy);
5561 RemoveField(newx, newy);
5562 DrawLevelField(newx, newy);
5565 PlayLevelSoundAction(x, y, action);
5570 Store[newx][newy] = EL_EMPTY;
5571 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5572 Store[newx][newy] = element_info[element].move_leave_element;
5574 Store[newx][newy] = EL_EMPTY;
5575 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)) ||
5576 element_info[element].move_leave_type == LEAVE_TYPE_UNLIMITED)
5577 Store[newx][newy] = element_info[element].move_leave_element;
5580 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5581 element_info[element].can_leave_element = TRUE;
5584 if (move_pattern & MV_MAZE_RUNNER_STYLE)
5586 RunnerVisit[x][y] = FrameCounter;
5587 PlayerVisit[x][y] /= 8; /* expire player visit path */
5593 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
5595 if (!IS_FREE(newx, newy))
5597 if (IS_PLAYER(x, y))
5598 DrawPlayerField(x, y);
5600 DrawLevelField(x, y);
5606 boolean wanna_flame = !RND(10);
5607 int dx = newx - x, dy = newy - y;
5608 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
5609 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
5610 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
5611 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
5612 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
5613 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
5616 IS_CLASSIC_ENEMY(element1) ||
5617 IS_CLASSIC_ENEMY(element2)) &&
5618 element1 != EL_DRAGON && element2 != EL_DRAGON &&
5619 element1 != EL_FLAMES && element2 != EL_FLAMES)
5622 ResetGfxAnimation(x, y);
5623 GfxAction[x][y] = ACTION_ATTACKING;
5626 if (IS_PLAYER(x, y))
5627 DrawPlayerField(x, y);
5629 DrawLevelField(x, y);
5631 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
5633 MovDelay[x][y] = 50;
5637 RemoveField(newx, newy);
5639 Feld[newx][newy] = EL_FLAMES;
5640 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
5643 RemoveField(newx1, newy1);
5645 Feld[newx1][newy1] = EL_FLAMES;
5647 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
5650 RemoveField(newx2, newy2);
5652 Feld[newx2][newy2] = EL_FLAMES;
5659 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5660 Feld[newx][newy] == EL_DIAMOND)
5662 if (IS_MOVING(newx, newy))
5663 RemoveMovingField(newx, newy);
5666 Feld[newx][newy] = EL_EMPTY;
5667 DrawLevelField(newx, newy);
5670 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
5672 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5673 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
5675 if (AmoebaNr[newx][newy])
5677 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5678 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5679 Feld[newx][newy] == EL_BD_AMOEBA)
5680 AmoebaCnt[AmoebaNr[newx][newy]]--;
5685 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
5687 if (IS_MOVING(newx, newy))
5690 RemoveMovingField(newx, newy);
5694 Feld[newx][newy] = EL_EMPTY;
5695 DrawLevelField(newx, newy);
5698 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
5700 else if ((element == EL_PACMAN || element == EL_MOLE)
5701 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
5703 if (AmoebaNr[newx][newy])
5705 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5706 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5707 Feld[newx][newy] == EL_BD_AMOEBA)
5708 AmoebaCnt[AmoebaNr[newx][newy]]--;
5711 if (element == EL_MOLE)
5713 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
5714 PlayLevelSound(x, y, SND_MOLE_DIGGING);
5716 ResetGfxAnimation(x, y);
5717 GfxAction[x][y] = ACTION_DIGGING;
5718 DrawLevelField(x, y);
5720 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
5722 return; /* wait for shrinking amoeba */
5724 else /* element == EL_PACMAN */
5726 Feld[newx][newy] = EL_EMPTY;
5727 DrawLevelField(newx, newy);
5728 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
5731 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
5732 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
5733 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
5735 /* wait for shrinking amoeba to completely disappear */
5738 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
5740 /* object was running against a wall */
5745 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
5746 DrawLevelElementAnimation(x, y, element);
5748 if (element == EL_BUG ||
5749 element == EL_SPACESHIP ||
5750 element == EL_SP_SNIKSNAK)
5751 DrawLevelField(x, y);
5752 else if (element == EL_MOLE)
5753 DrawLevelField(x, y);
5754 else if (element == EL_BD_BUTTERFLY ||
5755 element == EL_BD_FIREFLY)
5756 DrawLevelElementAnimationIfNeeded(x, y, element);
5757 else if (element == EL_SATELLITE)
5758 DrawLevelElementAnimationIfNeeded(x, y, element);
5759 else if (element == EL_SP_ELECTRON)
5760 DrawLevelElementAnimationIfNeeded(x, y, element);
5763 if (DONT_TOUCH(element))
5764 TestIfBadThingTouchesHero(x, y);
5767 PlayLevelSoundAction(x, y, ACTION_WAITING);
5773 InitMovingField(x, y, MovDir[x][y]);
5775 PlayLevelSoundAction(x, y, ACTION_MOVING);
5779 ContinueMoving(x, y);
5782 void ContinueMoving(int x, int y)
5784 int element = Feld[x][y];
5785 struct ElementInfo *ei = &element_info[element];
5786 int direction = MovDir[x][y];
5787 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
5788 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
5789 int newx = x + dx, newy = y + dy;
5791 int nextx = newx + dx, nexty = newy + dy;
5794 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
5795 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
5797 boolean pushed_by_player = Pushed[x][y];
5800 MovPos[x][y] += getElementMoveStepsize(x, y);
5803 if (pushed_by_player && IS_PLAYER(x, y))
5805 /* special case: moving object pushed by player */
5806 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
5809 if (pushed_by_player) /* special case: moving object pushed by player */
5810 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
5813 if (ABS(MovPos[x][y]) < TILEX)
5815 DrawLevelField(x, y);
5817 return; /* element is still moving */
5820 /* element reached destination field */
5822 Feld[x][y] = EL_EMPTY;
5823 Feld[newx][newy] = element;
5824 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
5826 if (element == EL_MOLE)
5828 Feld[x][y] = EL_SAND;
5830 DrawLevelFieldCrumbledSandNeighbours(x, y);
5832 else if (element == EL_QUICKSAND_FILLING)
5834 element = Feld[newx][newy] = get_next_element(element);
5835 Store[newx][newy] = Store[x][y];
5837 else if (element == EL_QUICKSAND_EMPTYING)
5839 Feld[x][y] = get_next_element(element);
5840 element = Feld[newx][newy] = Store[x][y];
5842 else if (element == EL_MAGIC_WALL_FILLING)
5844 element = Feld[newx][newy] = get_next_element(element);
5845 if (!game.magic_wall_active)
5846 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
5847 Store[newx][newy] = Store[x][y];
5849 else if (element == EL_MAGIC_WALL_EMPTYING)
5851 Feld[x][y] = get_next_element(element);
5852 if (!game.magic_wall_active)
5853 Feld[x][y] = EL_MAGIC_WALL_DEAD;
5854 element = Feld[newx][newy] = Store[x][y];
5856 else if (element == EL_BD_MAGIC_WALL_FILLING)
5858 element = Feld[newx][newy] = get_next_element(element);
5859 if (!game.magic_wall_active)
5860 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
5861 Store[newx][newy] = Store[x][y];
5863 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
5865 Feld[x][y] = get_next_element(element);
5866 if (!game.magic_wall_active)
5867 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
5868 element = Feld[newx][newy] = Store[x][y];
5870 else if (element == EL_AMOEBA_DROPPING)
5872 Feld[x][y] = get_next_element(element);
5873 element = Feld[newx][newy] = Store[x][y];
5875 else if (element == EL_SOKOBAN_OBJECT)
5878 Feld[x][y] = Back[x][y];
5880 if (Back[newx][newy])
5881 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
5883 Back[x][y] = Back[newx][newy] = 0;
5885 else if (Store[x][y] == EL_ACID)
5887 element = Feld[newx][newy] = EL_ACID;
5890 else if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
5891 ei->move_leave_element != EL_EMPTY &&
5892 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
5893 Store[x][y] != EL_EMPTY))
5895 /* some elements can leave other elements behind after moving */
5897 Feld[x][y] = ei->move_leave_element;
5898 InitField(x, y, FALSE);
5900 if (GFX_CRUMBLED(Feld[x][y]))
5901 DrawLevelFieldCrumbledSandNeighbours(x, y);
5905 Store[x][y] = EL_EMPTY;
5906 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
5907 MovDelay[newx][newy] = 0;
5909 if (CAN_CHANGE(element))
5911 /* copy element change control values to new field */
5912 ChangeDelay[newx][newy] = ChangeDelay[x][y];
5913 ChangePage[newx][newy] = ChangePage[x][y];
5914 Changed[newx][newy] = Changed[x][y];
5915 ChangeEvent[newx][newy] = ChangeEvent[x][y];
5918 ChangeDelay[x][y] = 0;
5919 ChangePage[x][y] = -1;
5920 Changed[x][y] = CE_BITMASK_DEFAULT;
5921 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
5923 /* copy animation control values to new field */
5924 GfxFrame[newx][newy] = GfxFrame[x][y];
5925 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
5926 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
5927 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
5929 Pushed[x][y] = Pushed[newx][newy] = FALSE;
5931 ResetGfxAnimation(x, y); /* reset animation values for old field */
5934 /* some elements can leave other elements behind after moving */
5935 if (IS_CUSTOM_ELEMENT(element) && !IS_PLAYER(x, y) &&
5936 ei->move_leave_element != EL_EMPTY &&
5937 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED ||
5938 ei->can_leave_element_last))
5940 Feld[x][y] = ei->move_leave_element;
5941 InitField(x, y, FALSE);
5943 if (GFX_CRUMBLED(Feld[x][y]))
5944 DrawLevelFieldCrumbledSandNeighbours(x, y);
5947 ei->can_leave_element_last = ei->can_leave_element;
5948 ei->can_leave_element = FALSE;
5952 /* 2.1.1 (does not work correctly for spring) */
5953 if (!CAN_MOVE(element))
5954 MovDir[newx][newy] = 0;
5958 /* (does not work for falling objects that slide horizontally) */
5959 if (CAN_FALL(element) && MovDir[newx][newy] == MV_DOWN)
5960 MovDir[newx][newy] = 0;
5963 if (!CAN_MOVE(element) ||
5964 (element == EL_SPRING && MovDir[newx][newy] == MV_DOWN))
5965 MovDir[newx][newy] = 0;
5968 if (!CAN_MOVE(element) ||
5969 (CAN_FALL(element) && direction == MV_DOWN))
5970 GfxDir[x][y] = MovDir[newx][newy] = 0;
5975 DrawLevelField(x, y);
5976 DrawLevelField(newx, newy);
5978 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
5980 /* prevent pushed element from moving on in pushed direction */
5981 if (pushed_by_player && CAN_MOVE(element) &&
5982 element_info[element].move_pattern & MV_ANY_DIRECTION &&
5983 !(element_info[element].move_pattern & direction))
5984 TurnRound(newx, newy);
5987 /* prevent elements on conveyor belt from moving on in last direction */
5988 if (pushed_by_conveyor && CAN_FALL(element) &&
5989 direction & MV_HORIZONTAL)
5990 MovDir[newx][newy] = 0;
5993 if (!pushed_by_player)
5995 WasJustMoving[newx][newy] = 3;
5997 if (CAN_FALL(element) && direction == MV_DOWN)
5998 WasJustFalling[newx][newy] = 3;
6001 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6003 TestIfBadThingTouchesHero(newx, newy);
6004 TestIfBadThingTouchesFriend(newx, newy);
6006 if (!IS_CUSTOM_ELEMENT(element))
6007 TestIfBadThingTouchesOtherBadThing(newx, newy);
6009 else if (element == EL_PENGUIN)
6010 TestIfFriendTouchesBadThing(newx, newy);
6012 if (CAN_FALL(element) && direction == MV_DOWN &&
6013 (newy == lev_fieldy - 1 || !IS_FREE(x, newy + 1)))
6017 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6021 if (ChangePage[newx][newy] != -1) /* delayed change */
6022 ChangeElement(newx, newy, ChangePage[newx][newy]);
6027 TestIfElementHitsCustomElement(newx, newy, direction);
6031 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
6033 int hitting_element = Feld[newx][newy];
6035 /* !!! fix side (direction) orientation here and elsewhere !!! */
6036 CheckElementChangeSide(newx, newy, hitting_element, CE_HITTING_SOMETHING,
6040 if (IN_LEV_FIELD(nextx, nexty))
6042 int opposite_direction = MV_DIR_OPPOSITE(direction);
6043 int hitting_side = direction;
6044 int touched_side = opposite_direction;
6045 int touched_element = MovingOrBlocked2Element(nextx, nexty);
6046 boolean object_hit = (!IS_MOVING(nextx, nexty) ||
6047 MovDir[nextx][nexty] != direction ||
6048 ABS(MovPos[nextx][nexty]) <= TILEY / 2);
6054 CheckElementChangeSide(nextx, nexty, touched_element,
6055 CE_HIT_BY_SOMETHING, opposite_direction);
6057 if (IS_CUSTOM_ELEMENT(hitting_element) &&
6058 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
6060 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
6062 struct ElementChangeInfo *change =
6063 &element_info[hitting_element].change_page[i];
6065 if (change->can_change &&
6066 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
6067 change->trigger_side & touched_side &&
6068 change->trigger_element == touched_element)
6070 CheckElementChangePage(newx, newy, hitting_element,
6071 touched_element, CE_OTHER_IS_HITTING, i);
6077 if (IS_CUSTOM_ELEMENT(touched_element) &&
6078 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
6080 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
6082 struct ElementChangeInfo *change =
6083 &element_info[touched_element].change_page[i];
6085 if (change->can_change &&
6086 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
6087 change->trigger_side & hitting_side &&
6088 change->trigger_element == hitting_element)
6090 CheckElementChangePage(nextx, nexty, touched_element,
6091 hitting_element, CE_OTHER_GETS_HIT, i);
6102 TestIfPlayerTouchesCustomElement(newx, newy);
6103 TestIfElementTouchesCustomElement(newx, newy);
6106 int AmoebeNachbarNr(int ax, int ay)
6109 int element = Feld[ax][ay];
6111 static int xy[4][2] =
6119 for (i = 0; i < NUM_DIRECTIONS; i++)
6121 int x = ax + xy[i][0];
6122 int y = ay + xy[i][1];
6124 if (!IN_LEV_FIELD(x, y))
6127 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6128 group_nr = AmoebaNr[x][y];
6134 void AmoebenVereinigen(int ax, int ay)
6136 int i, x, y, xx, yy;
6137 int new_group_nr = AmoebaNr[ax][ay];
6138 static int xy[4][2] =
6146 if (new_group_nr == 0)
6149 for (i = 0; i < NUM_DIRECTIONS; i++)
6154 if (!IN_LEV_FIELD(x, y))
6157 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6158 Feld[x][y] == EL_BD_AMOEBA ||
6159 Feld[x][y] == EL_AMOEBA_DEAD) &&
6160 AmoebaNr[x][y] != new_group_nr)
6162 int old_group_nr = AmoebaNr[x][y];
6164 if (old_group_nr == 0)
6167 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6168 AmoebaCnt[old_group_nr] = 0;
6169 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6170 AmoebaCnt2[old_group_nr] = 0;
6172 for (yy = 0; yy < lev_fieldy; yy++)
6174 for (xx = 0; xx < lev_fieldx; xx++)
6176 if (AmoebaNr[xx][yy] == old_group_nr)
6177 AmoebaNr[xx][yy] = new_group_nr;
6184 void AmoebeUmwandeln(int ax, int ay)
6188 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6190 int group_nr = AmoebaNr[ax][ay];
6195 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6196 printf("AmoebeUmwandeln(): This should never happen!\n");
6201 for (y = 0; y < lev_fieldy; y++)
6203 for (x = 0; x < lev_fieldx; x++)
6205 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6208 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6212 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6213 SND_AMOEBA_TURNING_TO_GEM :
6214 SND_AMOEBA_TURNING_TO_ROCK));
6219 static int xy[4][2] =
6227 for (i = 0; i < NUM_DIRECTIONS; i++)
6232 if (!IN_LEV_FIELD(x, y))
6235 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6237 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6238 SND_AMOEBA_TURNING_TO_GEM :
6239 SND_AMOEBA_TURNING_TO_ROCK));
6246 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6249 int group_nr = AmoebaNr[ax][ay];
6250 boolean done = FALSE;
6255 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6256 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6261 for (y = 0; y < lev_fieldy; y++)
6263 for (x = 0; x < lev_fieldx; x++)
6265 if (AmoebaNr[x][y] == group_nr &&
6266 (Feld[x][y] == EL_AMOEBA_DEAD ||
6267 Feld[x][y] == EL_BD_AMOEBA ||
6268 Feld[x][y] == EL_AMOEBA_GROWING))
6271 Feld[x][y] = new_element;
6272 InitField(x, y, FALSE);
6273 DrawLevelField(x, y);
6280 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6281 SND_BD_AMOEBA_TURNING_TO_ROCK :
6282 SND_BD_AMOEBA_TURNING_TO_GEM));
6285 void AmoebeWaechst(int x, int y)
6287 static unsigned long sound_delay = 0;
6288 static unsigned long sound_delay_value = 0;
6290 if (!MovDelay[x][y]) /* start new growing cycle */
6294 if (DelayReached(&sound_delay, sound_delay_value))
6297 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6299 if (Store[x][y] == EL_BD_AMOEBA)
6300 PlayLevelSound(x, y, SND_BD_AMOEBA_GROWING);
6302 PlayLevelSound(x, y, SND_AMOEBA_GROWING);
6304 sound_delay_value = 30;
6308 if (MovDelay[x][y]) /* wait some time before growing bigger */
6311 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6313 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6314 6 - MovDelay[x][y]);
6316 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6319 if (!MovDelay[x][y])
6321 Feld[x][y] = Store[x][y];
6323 DrawLevelField(x, y);
6328 void AmoebaDisappearing(int x, int y)
6330 static unsigned long sound_delay = 0;
6331 static unsigned long sound_delay_value = 0;
6333 if (!MovDelay[x][y]) /* start new shrinking cycle */
6337 if (DelayReached(&sound_delay, sound_delay_value))
6338 sound_delay_value = 30;
6341 if (MovDelay[x][y]) /* wait some time before shrinking */
6344 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6346 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6347 6 - MovDelay[x][y]);
6349 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6352 if (!MovDelay[x][y])
6354 Feld[x][y] = EL_EMPTY;
6355 DrawLevelField(x, y);
6357 /* don't let mole enter this field in this cycle;
6358 (give priority to objects falling to this field from above) */
6364 void AmoebeAbleger(int ax, int ay)
6367 int element = Feld[ax][ay];
6368 int graphic = el2img(element);
6369 int newax = ax, neway = ay;
6370 static int xy[4][2] =
6378 if (!level.amoeba_speed)
6380 Feld[ax][ay] = EL_AMOEBA_DEAD;
6381 DrawLevelField(ax, ay);
6385 if (IS_ANIMATED(graphic))
6386 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6388 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6389 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6391 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6394 if (MovDelay[ax][ay])
6398 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6401 int x = ax + xy[start][0];
6402 int y = ay + xy[start][1];
6404 if (!IN_LEV_FIELD(x, y))
6407 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6408 if (IS_FREE(x, y) ||
6409 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
6415 if (newax == ax && neway == ay)
6418 else /* normal or "filled" (BD style) amoeba */
6421 boolean waiting_for_player = FALSE;
6423 for (i = 0; i < NUM_DIRECTIONS; i++)
6425 int j = (start + i) % 4;
6426 int x = ax + xy[j][0];
6427 int y = ay + xy[j][1];
6429 if (!IN_LEV_FIELD(x, y))
6432 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6433 if (IS_FREE(x, y) ||
6434 Feld[x][y] == EL_SAND || Feld[x][y] == EL_QUICKSAND_EMPTY)
6440 else if (IS_PLAYER(x, y))
6441 waiting_for_player = TRUE;
6444 if (newax == ax && neway == ay) /* amoeba cannot grow */
6446 if (i == 4 && (!waiting_for_player || game.emulation == EMU_BOULDERDASH))
6448 Feld[ax][ay] = EL_AMOEBA_DEAD;
6449 DrawLevelField(ax, ay);
6450 AmoebaCnt[AmoebaNr[ax][ay]]--;
6452 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6454 if (element == EL_AMOEBA_FULL)
6455 AmoebeUmwandeln(ax, ay);
6456 else if (element == EL_BD_AMOEBA)
6457 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6462 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6464 /* amoeba gets larger by growing in some direction */
6466 int new_group_nr = AmoebaNr[ax][ay];
6469 if (new_group_nr == 0)
6471 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6472 printf("AmoebeAbleger(): This should never happen!\n");
6477 AmoebaNr[newax][neway] = new_group_nr;
6478 AmoebaCnt[new_group_nr]++;
6479 AmoebaCnt2[new_group_nr]++;
6481 /* if amoeba touches other amoeba(s) after growing, unify them */
6482 AmoebenVereinigen(newax, neway);
6484 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6486 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6492 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
6493 (neway == lev_fieldy - 1 && newax != ax))
6495 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6496 Store[newax][neway] = element;
6498 else if (neway == ay)
6500 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6502 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6504 PlayLevelSound(newax, neway, SND_AMOEBA_GROWING);
6509 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6510 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6511 Store[ax][ay] = EL_AMOEBA_DROP;
6512 ContinueMoving(ax, ay);
6516 DrawLevelField(newax, neway);
6519 void Life(int ax, int ay)
6522 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
6524 int element = Feld[ax][ay];
6525 int graphic = el2img(element);
6526 boolean changed = FALSE;
6528 if (IS_ANIMATED(graphic))
6529 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6534 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
6535 MovDelay[ax][ay] = life_time;
6537 if (MovDelay[ax][ay]) /* wait some time before next cycle */
6540 if (MovDelay[ax][ay])
6544 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
6546 int xx = ax+x1, yy = ay+y1;
6549 if (!IN_LEV_FIELD(xx, yy))
6552 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
6554 int x = xx+x2, y = yy+y2;
6556 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
6559 if (((Feld[x][y] == element ||
6560 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
6562 (IS_FREE(x, y) && Stop[x][y]))
6566 if (xx == ax && yy == ay) /* field in the middle */
6568 if (nachbarn < life[0] || nachbarn > life[1])
6570 Feld[xx][yy] = EL_EMPTY;
6572 DrawLevelField(xx, yy);
6573 Stop[xx][yy] = TRUE;
6577 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
6578 else if (IS_FREE(xx, yy) || Feld[xx][yy] == EL_SAND)
6579 { /* free border field */
6580 if (nachbarn >= life[2] && nachbarn <= life[3])
6582 Feld[xx][yy] = element;
6583 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
6585 DrawLevelField(xx, yy);
6586 Stop[xx][yy] = TRUE;
6593 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
6594 SND_GAME_OF_LIFE_GROWING);
6597 static void InitRobotWheel(int x, int y)
6599 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
6602 static void RunRobotWheel(int x, int y)
6604 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
6607 static void StopRobotWheel(int x, int y)
6609 if (ZX == x && ZY == y)
6613 static void InitTimegateWheel(int x, int y)
6615 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
6618 static void RunTimegateWheel(int x, int y)
6620 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
6623 void CheckExit(int x, int y)
6625 if (local_player->gems_still_needed > 0 ||
6626 local_player->sokobanfields_still_needed > 0 ||
6627 local_player->lights_still_needed > 0)
6629 int element = Feld[x][y];
6630 int graphic = el2img(element);
6632 if (IS_ANIMATED(graphic))
6633 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6638 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6641 Feld[x][y] = EL_EXIT_OPENING;
6643 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
6646 void CheckExitSP(int x, int y)
6648 if (local_player->gems_still_needed > 0)
6650 int element = Feld[x][y];
6651 int graphic = el2img(element);
6653 if (IS_ANIMATED(graphic))
6654 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6659 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6662 Feld[x][y] = EL_SP_EXIT_OPENING;
6664 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
6667 static void CloseAllOpenTimegates()
6671 for (y = 0; y < lev_fieldy; y++)
6673 for (x = 0; x < lev_fieldx; x++)
6675 int element = Feld[x][y];
6677 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
6679 Feld[x][y] = EL_TIMEGATE_CLOSING;
6681 PlayLevelSoundAction(x, y, ACTION_CLOSING);
6683 PlayLevelSound(x, y, SND_TIMEGATE_CLOSING);
6690 void EdelsteinFunkeln(int x, int y)
6692 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
6695 if (Feld[x][y] == EL_BD_DIAMOND)
6698 if (MovDelay[x][y] == 0) /* next animation frame */
6699 MovDelay[x][y] = 11 * !SimpleRND(500);
6701 if (MovDelay[x][y] != 0) /* wait some time before next frame */
6705 if (setup.direct_draw && MovDelay[x][y])
6706 SetDrawtoField(DRAW_BUFFERED);
6708 DrawLevelElementAnimation(x, y, Feld[x][y]);
6710 if (MovDelay[x][y] != 0)
6712 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
6713 10 - MovDelay[x][y]);
6715 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
6717 if (setup.direct_draw)
6721 dest_x = FX + SCREENX(x) * TILEX;
6722 dest_y = FY + SCREENY(y) * TILEY;
6724 BlitBitmap(drawto_field, window,
6725 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
6726 SetDrawtoField(DRAW_DIRECT);
6732 void MauerWaechst(int x, int y)
6736 if (!MovDelay[x][y]) /* next animation frame */
6737 MovDelay[x][y] = 3 * delay;
6739 if (MovDelay[x][y]) /* wait some time before next frame */
6743 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6745 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
6746 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
6748 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
6751 if (!MovDelay[x][y])
6753 if (MovDir[x][y] == MV_LEFT)
6755 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
6756 DrawLevelField(x - 1, y);
6758 else if (MovDir[x][y] == MV_RIGHT)
6760 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
6761 DrawLevelField(x + 1, y);
6763 else if (MovDir[x][y] == MV_UP)
6765 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
6766 DrawLevelField(x, y - 1);
6770 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
6771 DrawLevelField(x, y + 1);
6774 Feld[x][y] = Store[x][y];
6776 GfxDir[x][y] = MovDir[x][y] = MV_NO_MOVING;
6777 DrawLevelField(x, y);
6782 void MauerAbleger(int ax, int ay)
6784 int element = Feld[ax][ay];
6785 int graphic = el2img(element);
6786 boolean oben_frei = FALSE, unten_frei = FALSE;
6787 boolean links_frei = FALSE, rechts_frei = FALSE;
6788 boolean oben_massiv = FALSE, unten_massiv = FALSE;
6789 boolean links_massiv = FALSE, rechts_massiv = FALSE;
6790 boolean new_wall = FALSE;
6792 if (IS_ANIMATED(graphic))
6793 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6795 if (!MovDelay[ax][ay]) /* start building new wall */
6796 MovDelay[ax][ay] = 6;
6798 if (MovDelay[ax][ay]) /* wait some time before building new wall */
6801 if (MovDelay[ax][ay])
6805 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
6807 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
6809 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
6811 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
6814 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
6815 element == EL_EXPANDABLE_WALL_ANY)
6819 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
6820 Store[ax][ay-1] = element;
6821 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
6822 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
6823 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
6824 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
6829 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
6830 Store[ax][ay+1] = element;
6831 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
6832 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
6833 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
6834 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
6839 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6840 element == EL_EXPANDABLE_WALL_ANY ||
6841 element == EL_EXPANDABLE_WALL)
6845 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
6846 Store[ax-1][ay] = element;
6847 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
6848 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
6849 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
6850 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
6856 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
6857 Store[ax+1][ay] = element;
6858 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
6859 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
6860 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
6861 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
6866 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
6867 DrawLevelField(ax, ay);
6869 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
6871 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
6872 unten_massiv = TRUE;
6873 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
6874 links_massiv = TRUE;
6875 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
6876 rechts_massiv = TRUE;
6878 if (((oben_massiv && unten_massiv) ||
6879 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6880 element == EL_EXPANDABLE_WALL) &&
6881 ((links_massiv && rechts_massiv) ||
6882 element == EL_EXPANDABLE_WALL_VERTICAL))
6883 Feld[ax][ay] = EL_WALL;
6887 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
6889 PlayLevelSound(ax, ay, SND_EXPANDABLE_WALL_GROWING);
6893 void CheckForDragon(int x, int y)
6896 boolean dragon_found = FALSE;
6897 static int xy[4][2] =
6905 for (i = 0; i < NUM_DIRECTIONS; i++)
6907 for (j = 0; j < 4; j++)
6909 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
6911 if (IN_LEV_FIELD(xx, yy) &&
6912 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
6914 if (Feld[xx][yy] == EL_DRAGON)
6915 dragon_found = TRUE;
6924 for (i = 0; i < NUM_DIRECTIONS; i++)
6926 for (j = 0; j < 3; j++)
6928 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
6930 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
6932 Feld[xx][yy] = EL_EMPTY;
6933 DrawLevelField(xx, yy);
6942 static void InitBuggyBase(int x, int y)
6944 int element = Feld[x][y];
6945 int activating_delay = FRAMES_PER_SECOND / 4;
6948 (element == EL_SP_BUGGY_BASE ?
6949 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
6950 element == EL_SP_BUGGY_BASE_ACTIVATING ?
6952 element == EL_SP_BUGGY_BASE_ACTIVE ?
6953 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
6956 static void WarnBuggyBase(int x, int y)
6959 static int xy[4][2] =
6967 for (i = 0; i < NUM_DIRECTIONS; i++)
6969 int xx = x + xy[i][0], yy = y + xy[i][1];
6971 if (IS_PLAYER(xx, yy))
6973 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
6980 static void InitTrap(int x, int y)
6982 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
6985 static void ActivateTrap(int x, int y)
6987 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
6990 static void ChangeActiveTrap(int x, int y)
6992 int graphic = IMG_TRAP_ACTIVE;
6994 /* if new animation frame was drawn, correct crumbled sand border */
6995 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
6996 DrawLevelFieldCrumbledSand(x, y);
6999 static void ChangeElementNowExt(int x, int y, int target_element)
7001 int previous_move_direction = MovDir[x][y];
7003 /* check if element under player changes from accessible to unaccessible
7004 (needed for special case of dropping element which then changes) */
7005 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7006 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(target_element))
7013 Feld[x][y] = target_element;
7015 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7017 ResetGfxAnimation(x, y);
7018 ResetRandomAnimationValue(x, y);
7020 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7021 MovDir[x][y] = previous_move_direction;
7024 InitField_WithBug1(x, y, FALSE);
7026 InitField(x, y, FALSE);
7027 if (CAN_MOVE(Feld[x][y]))
7031 DrawLevelField(x, y);
7033 if (GFX_CRUMBLED(Feld[x][y]))
7034 DrawLevelFieldCrumbledSandNeighbours(x, y);
7036 TestIfBadThingTouchesHero(x, y);
7037 TestIfPlayerTouchesCustomElement(x, y);
7038 TestIfElementTouchesCustomElement(x, y);
7040 if (ELEM_IS_PLAYER(target_element))
7041 RelocatePlayer(x, y, target_element);
7044 static boolean ChangeElementNow(int x, int y, int element, int page)
7046 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7049 /* always use default change event to prevent running into a loop */
7050 if (ChangeEvent[x][y] == CE_BITMASK_DEFAULT)
7051 ChangeEvent[x][y] = CH_EVENT_BIT(CE_DELAY);
7053 if (ChangeEvent[x][y] == CH_EVENT_BIT(CE_DELAY))
7055 /* reset actual trigger element and player */
7056 change->actual_trigger_element = EL_EMPTY;
7057 change->actual_trigger_player = EL_PLAYER_1;
7060 /* do not change already changed elements with same change event */
7062 if (Changed[x][y] & ChangeEvent[x][y])
7069 Changed[x][y] |= ChangeEvent[x][y]; /* ignore same changes in this frame */
7071 CheckTriggeredElementChangePage(x,y, Feld[x][y], CE_OTHER_IS_CHANGING, page);
7073 if (change->explode)
7080 if (change->use_target_content)
7082 boolean complete_replace = TRUE;
7083 boolean can_replace[3][3];
7086 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7089 boolean is_diggable;
7090 boolean is_destructible;
7091 int ex = x + xx - 1;
7092 int ey = y + yy - 1;
7093 int content_element = change->target_content[xx][yy];
7096 can_replace[xx][yy] = TRUE;
7098 if (ex == x && ey == y) /* do not check changing element itself */
7101 if (content_element == EL_EMPTY_SPACE)
7103 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7108 if (!IN_LEV_FIELD(ex, ey))
7110 can_replace[xx][yy] = FALSE;
7111 complete_replace = FALSE;
7118 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7119 e = MovingOrBlocked2Element(ex, ey);
7122 is_empty = (IS_FREE(ex, ey) || (IS_PLAYER(ex, ey) &&
7123 IS_WALKABLE(content_element)));
7124 is_diggable = (is_empty || IS_DIGGABLE(e));
7125 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7127 can_replace[xx][yy] =
7128 ((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7129 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7130 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible));
7132 if (!can_replace[xx][yy])
7133 complete_replace = FALSE;
7135 empty_for_element = (IS_FREE(ex, ey) || (IS_FREE_OR_PLAYER(ex, ey) &&
7136 IS_WALKABLE(content_element)));
7138 half_destructible = (empty_for_element || IS_DIGGABLE(e));
7140 half_destructible = (IS_FREE(ex, ey) || IS_DIGGABLE(e));
7143 if ((change->replace_when <= CP_WHEN_EMPTY && !empty_for_element) ||
7144 (change->replace_when <= CP_WHEN_DIGGABLE && !half_destructible) ||
7145 (change->replace_when <= CP_WHEN_DESTRUCTIBLE && IS_INDESTRUCTIBLE(e)))
7147 can_replace[xx][yy] = FALSE;
7148 complete_replace = FALSE;
7153 if (!change->only_if_complete || complete_replace)
7155 boolean something_has_changed = FALSE;
7157 if (change->only_if_complete && change->use_random_replace &&
7158 RND(100) < change->random_percentage)
7161 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7163 int ex = x + xx - 1;
7164 int ey = y + yy - 1;
7165 int content_element;
7167 if (can_replace[xx][yy] && (!change->use_random_replace ||
7168 RND(100) < change->random_percentage))
7170 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7171 RemoveMovingField(ex, ey);
7173 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7175 content_element = change->target_content[xx][yy];
7176 target_element = GET_TARGET_ELEMENT(content_element, change);
7178 ChangeElementNowExt(ex, ey, target_element);
7180 something_has_changed = TRUE;
7182 /* for symmetry reasons, freeze newly created border elements */
7183 if (ex != x || ey != y)
7184 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7188 if (something_has_changed)
7189 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7194 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7196 ChangeElementNowExt(x, y, target_element);
7198 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7204 static void ChangeElement(int x, int y, int page)
7206 int element = MovingOrBlocked2Element(x, y);
7207 struct ElementInfo *ei = &element_info[element];
7208 struct ElementChangeInfo *change = &ei->change_page[page];
7211 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7214 printf("ChangeElement(): %d,%d: element = %d ('%s')\n",
7215 x, y, element, element_info[element].token_name);
7216 printf("ChangeElement(): This should never happen!\n");
7221 /* this can happen with classic bombs on walkable, changing elements */
7222 if (!CAN_CHANGE(element))
7225 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7226 ChangeDelay[x][y] = 0;
7232 if (ChangeDelay[x][y] == 0) /* initialize element change */
7234 ChangeDelay[x][y] = ( change->delay_fixed * change->delay_frames +
7235 RND(change->delay_random * change->delay_frames)) + 1;
7237 ResetGfxAnimation(x, y);
7238 ResetRandomAnimationValue(x, y);
7240 if (change->pre_change_function)
7241 change->pre_change_function(x, y);
7244 ChangeDelay[x][y]--;
7246 if (ChangeDelay[x][y] != 0) /* continue element change */
7248 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7250 if (IS_ANIMATED(graphic))
7251 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7253 if (change->change_function)
7254 change->change_function(x, y);
7256 else /* finish element change */
7258 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7260 page = ChangePage[x][y];
7261 ChangePage[x][y] = -1;
7263 change = &ei->change_page[page];
7267 if (IS_MOVING(x, y) && !change->explode)
7269 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7272 ChangeDelay[x][y] = 1; /* try change after next move step */
7273 ChangePage[x][y] = page; /* remember page to use for change */
7278 if (ChangeElementNow(x, y, element, page))
7280 if (change->post_change_function)
7281 change->post_change_function(x, y);
7286 static boolean CheckTriggeredElementChangeExt(int lx, int ly,
7287 int trigger_element,
7294 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
7296 if (!(trigger_events[trigger_element] & CH_EVENT_BIT(trigger_event)))
7299 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7301 int element = EL_CUSTOM_START + i;
7303 boolean change_element = FALSE;
7306 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7309 for (j = 0; j < element_info[element].num_change_pages; j++)
7311 struct ElementChangeInfo *change = &element_info[element].change_page[j];
7313 if (change->can_change &&
7314 change->events & CH_EVENT_BIT(trigger_event) &&
7315 change->trigger_side & trigger_side &&
7316 change->trigger_player & trigger_player &&
7317 change->trigger_page & trigger_page_bits &&
7318 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
7321 if (!(change->events & CH_EVENT_BIT(trigger_event)))
7322 printf("::: !!! %d triggers %d: using wrong page %d [event %d]\n",
7323 trigger_element-EL_CUSTOM_START+1, i+1, j, trigger_event);
7326 change_element = TRUE;
7329 change->actual_trigger_element = trigger_element;
7330 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7336 if (!change_element)
7339 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7342 if (x == lx && y == ly) /* do not change trigger element itself */
7346 if (Feld[x][y] == element)
7348 ChangeDelay[x][y] = 1;
7349 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
7350 ChangeElement(x, y, page);
7358 static boolean CheckElementChangeExt(int x, int y,
7360 int trigger_element,
7366 if (!CAN_CHANGE(element) || !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7369 if (Feld[x][y] == EL_BLOCKED)
7371 Blocked2Moving(x, y, &x, &y);
7372 element = Feld[x][y];
7376 if (Feld[x][y] != element) /* check if element has already changed */
7379 printf("::: %d ('%s') != %d ('%s') [%d]\n",
7380 Feld[x][y], element_info[Feld[x][y]].token_name,
7381 element, element_info[element].token_name,
7390 if (trigger_page < 0)
7392 boolean change_element = FALSE;
7395 for (i = 0; i < element_info[element].num_change_pages; i++)
7397 struct ElementChangeInfo *change = &element_info[element].change_page[i];
7399 if (change->can_change &&
7400 change->events & CH_EVENT_BIT(trigger_event) &&
7401 change->trigger_side & trigger_side &&
7402 change->trigger_player & trigger_player)
7404 change_element = TRUE;
7407 change->actual_trigger_element = trigger_element;
7408 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7414 if (!change_element)
7419 struct ElementInfo *ei = &element_info[element];
7420 struct ElementChangeInfo *change = &ei->change_page[trigger_page];
7422 change->actual_trigger_element = trigger_element;
7423 change->actual_trigger_player = EL_PLAYER_1; /* unused */
7428 /* !!! this check misses pages with same event, but different side !!! */
7430 if (trigger_page < 0)
7431 trigger_page = element_info[element].event_page_nr[trigger_event];
7433 if (!(element_info[element].change_page[trigger_page].trigger_side & trigger_side))
7437 ChangeDelay[x][y] = 1;
7438 ChangeEvent[x][y] = CH_EVENT_BIT(trigger_event);
7439 ChangeElement(x, y, trigger_page);
7444 static void PlayPlayerSound(struct PlayerInfo *player)
7446 int jx = player->jx, jy = player->jy;
7447 int element = player->element_nr;
7448 int last_action = player->last_action_waiting;
7449 int action = player->action_waiting;
7451 if (player->is_waiting)
7453 if (action != last_action)
7454 PlayLevelSoundElementAction(jx, jy, element, action);
7456 PlayLevelSoundElementActionIfLoop(jx, jy, element, action);
7460 if (action != last_action)
7461 StopSound(element_info[element].sound[last_action]);
7463 if (last_action == ACTION_SLEEPING)
7464 PlayLevelSoundElementAction(jx, jy, element, ACTION_AWAKENING);
7468 static void PlayAllPlayersSound()
7472 for (i = 0; i < MAX_PLAYERS; i++)
7473 if (stored_player[i].active)
7474 PlayPlayerSound(&stored_player[i]);
7477 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
7479 boolean last_waiting = player->is_waiting;
7480 int move_dir = player->MovDir;
7482 player->last_action_waiting = player->action_waiting;
7486 if (!last_waiting) /* not waiting -> waiting */
7488 player->is_waiting = TRUE;
7490 player->frame_counter_bored =
7492 game.player_boring_delay_fixed +
7493 SimpleRND(game.player_boring_delay_random);
7494 player->frame_counter_sleeping =
7496 game.player_sleeping_delay_fixed +
7497 SimpleRND(game.player_sleeping_delay_random);
7499 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
7502 if (game.player_sleeping_delay_fixed +
7503 game.player_sleeping_delay_random > 0 &&
7504 player->anim_delay_counter == 0 &&
7505 player->post_delay_counter == 0 &&
7506 FrameCounter >= player->frame_counter_sleeping)
7507 player->is_sleeping = TRUE;
7508 else if (game.player_boring_delay_fixed +
7509 game.player_boring_delay_random > 0 &&
7510 FrameCounter >= player->frame_counter_bored)
7511 player->is_bored = TRUE;
7513 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
7514 player->is_bored ? ACTION_BORING :
7517 if (player->is_sleeping)
7519 if (player->num_special_action_sleeping > 0)
7521 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
7523 int last_special_action = player->special_action_sleeping;
7524 int num_special_action = player->num_special_action_sleeping;
7525 int special_action =
7526 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
7527 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
7528 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
7529 last_special_action + 1 : ACTION_SLEEPING);
7530 int special_graphic =
7531 el_act_dir2img(player->element_nr, special_action, move_dir);
7533 player->anim_delay_counter =
7534 graphic_info[special_graphic].anim_delay_fixed +
7535 SimpleRND(graphic_info[special_graphic].anim_delay_random);
7536 player->post_delay_counter =
7537 graphic_info[special_graphic].post_delay_fixed +
7538 SimpleRND(graphic_info[special_graphic].post_delay_random);
7540 player->special_action_sleeping = special_action;
7543 if (player->anim_delay_counter > 0)
7545 player->action_waiting = player->special_action_sleeping;
7546 player->anim_delay_counter--;
7548 else if (player->post_delay_counter > 0)
7550 player->post_delay_counter--;
7554 else if (player->is_bored)
7556 if (player->num_special_action_bored > 0)
7558 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
7560 int special_action =
7561 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
7562 int special_graphic =
7563 el_act_dir2img(player->element_nr, special_action, move_dir);
7565 player->anim_delay_counter =
7566 graphic_info[special_graphic].anim_delay_fixed +
7567 SimpleRND(graphic_info[special_graphic].anim_delay_random);
7568 player->post_delay_counter =
7569 graphic_info[special_graphic].post_delay_fixed +
7570 SimpleRND(graphic_info[special_graphic].post_delay_random);
7572 player->special_action_bored = special_action;
7575 if (player->anim_delay_counter > 0)
7577 player->action_waiting = player->special_action_bored;
7578 player->anim_delay_counter--;
7580 else if (player->post_delay_counter > 0)
7582 player->post_delay_counter--;
7587 else if (last_waiting) /* waiting -> not waiting */
7589 player->is_waiting = FALSE;
7590 player->is_bored = FALSE;
7591 player->is_sleeping = FALSE;
7593 player->frame_counter_bored = -1;
7594 player->frame_counter_sleeping = -1;
7596 player->anim_delay_counter = 0;
7597 player->post_delay_counter = 0;
7599 player->action_waiting = ACTION_DEFAULT;
7601 player->special_action_bored = ACTION_DEFAULT;
7602 player->special_action_sleeping = ACTION_DEFAULT;
7607 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
7610 static byte stored_player_action[MAX_PLAYERS];
7611 static int num_stored_actions = 0;
7613 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
7614 int left = player_action & JOY_LEFT;
7615 int right = player_action & JOY_RIGHT;
7616 int up = player_action & JOY_UP;
7617 int down = player_action & JOY_DOWN;
7618 int button1 = player_action & JOY_BUTTON_1;
7619 int button2 = player_action & JOY_BUTTON_2;
7620 int dx = (left ? -1 : right ? 1 : 0);
7621 int dy = (up ? -1 : down ? 1 : 0);
7624 stored_player_action[player->index_nr] = 0;
7625 num_stored_actions++;
7629 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
7632 if (!player->active || tape.pausing)
7636 printf("::: [%d %d %d %d] [%d %d]\n",
7637 left, right, up, down, button1, button2);
7643 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
7648 if (player->MovPos == 0)
7649 CheckGravityMovement(player);
7652 snapped = SnapField(player, dx, dy);
7656 dropped = DropElement(player);
7658 moved = MovePlayer(player, dx, dy);
7661 if (tape.single_step && tape.recording && !tape.pausing)
7663 if (button1 || (dropped && !moved))
7665 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
7666 SnapField(player, 0, 0); /* stop snapping */
7670 SetPlayerWaiting(player, FALSE);
7673 return player_action;
7675 stored_player_action[player->index_nr] = player_action;
7681 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
7684 /* no actions for this player (no input at player's configured device) */
7686 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
7687 SnapField(player, 0, 0);
7688 CheckGravityMovementWhenNotMoving(player);
7690 if (player->MovPos == 0)
7691 SetPlayerWaiting(player, TRUE);
7693 if (player->MovPos == 0) /* needed for tape.playing */
7694 player->is_moving = FALSE;
7696 player->is_dropping = FALSE;
7702 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
7704 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
7706 TapeRecordAction(stored_player_action);
7707 num_stored_actions = 0;
7714 static void PlayerActions(struct PlayerInfo *player, byte player_action)
7716 static byte stored_player_action[MAX_PLAYERS];
7717 static int num_stored_actions = 0;
7718 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
7719 int left = player_action & JOY_LEFT;
7720 int right = player_action & JOY_RIGHT;
7721 int up = player_action & JOY_UP;
7722 int down = player_action & JOY_DOWN;
7723 int button1 = player_action & JOY_BUTTON_1;
7724 int button2 = player_action & JOY_BUTTON_2;
7725 int dx = (left ? -1 : right ? 1 : 0);
7726 int dy = (up ? -1 : down ? 1 : 0);
7728 stored_player_action[player->index_nr] = 0;
7729 num_stored_actions++;
7731 printf("::: player %d [%d]\n", player->index_nr, FrameCounter);
7733 if (!player->active || tape.pausing)
7738 printf("::: player %d acts [%d]\n", player->index_nr, FrameCounter);
7741 snapped = SnapField(player, dx, dy);
7745 dropped = DropElement(player);
7747 moved = MovePlayer(player, dx, dy);
7750 if (tape.single_step && tape.recording && !tape.pausing)
7752 if (button1 || (dropped && !moved))
7754 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
7755 SnapField(player, 0, 0); /* stop snapping */
7759 stored_player_action[player->index_nr] = player_action;
7763 printf("::: player %d waits [%d]\n", player->index_nr, FrameCounter);
7765 /* no actions for this player (no input at player's configured device) */
7767 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
7768 SnapField(player, 0, 0);
7769 CheckGravityMovementWhenNotMoving(player);
7771 if (player->MovPos == 0)
7772 InitPlayerGfxAnimation(player, ACTION_DEFAULT, player->MovDir);
7774 if (player->MovPos == 0) /* needed for tape.playing */
7775 player->is_moving = FALSE;
7778 if (tape.recording && num_stored_actions >= MAX_PLAYERS)
7780 printf("::: player %d recorded [%d]\n", player->index_nr, FrameCounter);
7782 TapeRecordAction(stored_player_action);
7783 num_stored_actions = 0;
7790 static unsigned long action_delay = 0;
7791 unsigned long action_delay_value;
7792 int magic_wall_x = 0, magic_wall_y = 0;
7793 int i, x, y, element, graphic;
7794 byte *recorded_player_action;
7795 byte summarized_player_action = 0;
7797 byte tape_action[MAX_PLAYERS];
7800 if (game_status != GAME_MODE_PLAYING)
7803 action_delay_value =
7804 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
7806 if (tape.playing && tape.warp_forward && !tape.pausing)
7807 action_delay_value = 0;
7809 /* ---------- main game synchronization point ---------- */
7811 WaitUntilDelayReached(&action_delay, action_delay_value);
7813 if (network_playing && !network_player_action_received)
7817 printf("DEBUG: try to get network player actions in time\n");
7821 #if defined(PLATFORM_UNIX)
7822 /* last chance to get network player actions without main loop delay */
7826 if (game_status != GAME_MODE_PLAYING)
7829 if (!network_player_action_received)
7833 printf("DEBUG: failed to get network player actions in time\n");
7844 printf("::: getting new tape action [%d]\n", FrameCounter);
7847 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
7850 if (recorded_player_action == NULL && tape.pausing)
7855 printf("::: %d\n", stored_player[0].action);
7859 if (recorded_player_action != NULL)
7860 for (i = 0; i < MAX_PLAYERS; i++)
7861 stored_player[i].action = recorded_player_action[i];
7864 for (i = 0; i < MAX_PLAYERS; i++)
7866 summarized_player_action |= stored_player[i].action;
7868 if (!network_playing)
7869 stored_player[i].effective_action = stored_player[i].action;
7872 #if defined(PLATFORM_UNIX)
7873 if (network_playing)
7874 SendToServer_MovePlayer(summarized_player_action);
7877 if (!options.network && !setup.team_mode)
7878 local_player->effective_action = summarized_player_action;
7881 if (recorded_player_action != NULL)
7882 for (i = 0; i < MAX_PLAYERS; i++)
7883 stored_player[i].effective_action = recorded_player_action[i];
7887 for (i = 0; i < MAX_PLAYERS; i++)
7889 tape_action[i] = stored_player[i].effective_action;
7891 if (tape.recording && tape_action[i] && !tape.player_participates[i])
7892 tape.player_participates[i] = TRUE; /* player just appeared from CE */
7895 /* only save actions from input devices, but not programmed actions */
7897 TapeRecordAction(tape_action);
7900 for (i = 0; i < MAX_PLAYERS; i++)
7902 int actual_player_action = stored_player[i].effective_action;
7905 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
7906 - rnd_equinox_tetrachloride 048
7907 - rnd_equinox_tetrachloride_ii 096
7908 - rnd_emanuel_schmieg 002
7909 - doctor_sloan_ww 001, 020
7911 if (stored_player[i].MovPos == 0)
7912 CheckGravityMovement(&stored_player[i]);
7916 /* overwrite programmed action with tape action */
7917 if (stored_player[i].programmed_action)
7918 actual_player_action = stored_player[i].programmed_action;
7922 if (stored_player[i].programmed_action)
7923 printf("::: %d\n", stored_player[i].programmed_action);
7926 if (recorded_player_action)
7929 if (stored_player[i].programmed_action &&
7930 stored_player[i].programmed_action != recorded_player_action[i])
7931 printf("::: %d: %d <-> %d\n", i,
7932 stored_player[i].programmed_action, recorded_player_action[i]);
7936 actual_player_action = recorded_player_action[i];
7941 /* overwrite tape action with programmed action */
7942 if (stored_player[i].programmed_action)
7943 actual_player_action = stored_player[i].programmed_action;
7948 printf("::: action: %d: %x [%d]\n",
7949 stored_player[i].MovPos, actual_player_action, FrameCounter);
7953 PlayerActions(&stored_player[i], actual_player_action);
7955 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
7957 if (tape.recording && tape_action[i] && !tape.player_participates[i])
7958 tape.player_participates[i] = TRUE; /* player just appeared from CE */
7961 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
7966 TapeRecordAction(tape_action);
7969 network_player_action_received = FALSE;
7971 ScrollScreen(NULL, SCROLL_GO_ON);
7977 for (i = 0; i < MAX_PLAYERS; i++)
7978 stored_player[i].Frame++;
7982 /* for downwards compatibility, the following code emulates a fixed bug that
7983 occured when pushing elements (causing elements that just made their last
7984 pushing step to already (if possible) make their first falling step in the
7985 same game frame, which is bad); this code is also needed to use the famous
7986 "spring push bug" which is used in older levels and might be wanted to be
7987 used also in newer levels, but in this case the buggy pushing code is only
7988 affecting the "spring" element and no other elements */
7991 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
7993 if (game.engine_version < VERSION_IDENT(2,2,0,7))
7996 for (i = 0; i < MAX_PLAYERS; i++)
7998 struct PlayerInfo *player = &stored_player[i];
8003 if (player->active && player->is_pushing && player->is_moving &&
8005 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8006 Feld[x][y] == EL_SPRING))
8008 if (player->active && player->is_pushing && player->is_moving &&
8012 ContinueMoving(x, y);
8014 /* continue moving after pushing (this is actually a bug) */
8015 if (!IS_MOVING(x, y))
8024 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8026 Changed[x][y] = CE_BITMASK_DEFAULT;
8027 ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
8030 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8032 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8033 printf("GameActions(): This should never happen!\n");
8035 ChangePage[x][y] = -1;
8040 if (WasJustMoving[x][y] > 0)
8041 WasJustMoving[x][y]--;
8042 if (WasJustFalling[x][y] > 0)
8043 WasJustFalling[x][y]--;
8048 /* reset finished pushing action (not done in ContinueMoving() to allow
8049 continous pushing animation for elements with zero push delay) */
8050 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8052 ResetGfxAnimation(x, y);
8053 DrawLevelField(x, y);
8058 if (IS_BLOCKED(x, y))
8062 Blocked2Moving(x, y, &oldx, &oldy);
8063 if (!IS_MOVING(oldx, oldy))
8065 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8066 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8067 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8068 printf("GameActions(): This should never happen!\n");
8074 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8076 element = Feld[x][y];
8078 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8080 graphic = el2img(element);
8086 printf("::: %d,%d: %d [%d]\n", x, y, element, FrameCounter);
8088 element = graphic = 0;
8092 if (graphic_info[graphic].anim_global_sync)
8093 GfxFrame[x][y] = FrameCounter;
8095 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8096 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8097 ResetRandomAnimationValue(x, y);
8099 SetRandomAnimationValue(x, y);
8102 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8105 if (IS_INACTIVE(element))
8107 if (IS_ANIMATED(graphic))
8108 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8114 /* this may take place after moving, so 'element' may have changed */
8116 if (IS_CHANGING(x, y))
8118 if (IS_CHANGING(x, y) &&
8119 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8123 ChangeElement(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] :
8124 element_info[element].event_page_nr[CE_DELAY]);
8126 ChangeElement(x, y, element_info[element].event_page_nr[CE_DELAY]);
8129 element = Feld[x][y];
8130 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8134 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8139 element = Feld[x][y];
8140 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8142 if (element == EL_MOLE)
8143 printf("::: %d, %d, %d [%d]\n",
8144 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y],
8148 if (element == EL_YAMYAM)
8149 printf("::: %d, %d, %d\n",
8150 IS_ANIMATED(graphic), IS_MOVING(x, y), Stop[x][y]);
8154 if (IS_ANIMATED(graphic) &&
8158 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8161 if (element == EL_BUG)
8162 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8166 if (element == EL_MOLE)
8167 printf("::: %d, %d\n", graphic, GfxFrame[x][y]);
8171 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8172 EdelsteinFunkeln(x, y);
8174 else if ((element == EL_ACID ||
8175 element == EL_EXIT_OPEN ||
8176 element == EL_SP_EXIT_OPEN ||
8177 element == EL_SP_TERMINAL ||
8178 element == EL_SP_TERMINAL_ACTIVE ||
8179 element == EL_EXTRA_TIME ||
8180 element == EL_SHIELD_NORMAL ||
8181 element == EL_SHIELD_DEADLY) &&
8182 IS_ANIMATED(graphic))
8183 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8184 else if (IS_MOVING(x, y))
8185 ContinueMoving(x, y);
8186 else if (IS_ACTIVE_BOMB(element))
8187 CheckDynamite(x, y);
8189 else if (element == EL_EXPLOSION && !game.explosions_delayed)
8190 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8192 else if (element == EL_AMOEBA_GROWING)
8193 AmoebeWaechst(x, y);
8194 else if (element == EL_AMOEBA_SHRINKING)
8195 AmoebaDisappearing(x, y);
8197 #if !USE_NEW_AMOEBA_CODE
8198 else if (IS_AMOEBALIVE(element))
8199 AmoebeAbleger(x, y);
8202 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8204 else if (element == EL_EXIT_CLOSED)
8206 else if (element == EL_SP_EXIT_CLOSED)
8208 else if (element == EL_EXPANDABLE_WALL_GROWING)
8210 else if (element == EL_EXPANDABLE_WALL ||
8211 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8212 element == EL_EXPANDABLE_WALL_VERTICAL ||
8213 element == EL_EXPANDABLE_WALL_ANY)
8215 else if (element == EL_FLAMES)
8216 CheckForDragon(x, y);
8218 else if (IS_AUTO_CHANGING(element))
8219 ChangeElement(x, y);
8221 else if (element == EL_EXPLOSION)
8222 ; /* drawing of correct explosion animation is handled separately */
8223 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8224 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8227 /* this may take place after moving, so 'element' may have changed */
8228 if (IS_AUTO_CHANGING(Feld[x][y]))
8229 ChangeElement(x, y);
8232 if (IS_BELT_ACTIVE(element))
8233 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8235 if (game.magic_wall_active)
8237 int jx = local_player->jx, jy = local_player->jy;
8239 /* play the element sound at the position nearest to the player */
8240 if ((element == EL_MAGIC_WALL_FULL ||
8241 element == EL_MAGIC_WALL_ACTIVE ||
8242 element == EL_MAGIC_WALL_EMPTYING ||
8243 element == EL_BD_MAGIC_WALL_FULL ||
8244 element == EL_BD_MAGIC_WALL_ACTIVE ||
8245 element == EL_BD_MAGIC_WALL_EMPTYING) &&
8246 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
8254 #if USE_NEW_AMOEBA_CODE
8255 /* new experimental amoeba growth stuff */
8257 if (!(FrameCounter % 8))
8260 static unsigned long random = 1684108901;
8262 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
8265 x = (random >> 10) % lev_fieldx;
8266 y = (random >> 20) % lev_fieldy;
8268 x = RND(lev_fieldx);
8269 y = RND(lev_fieldy);
8271 element = Feld[x][y];
8273 /* !!! extend EL_SAND to anything diggable (but maybe not SP_BASE) !!! */
8274 if (!IS_PLAYER(x,y) &&
8275 (element == EL_EMPTY ||
8276 element == EL_SAND ||
8277 element == EL_QUICKSAND_EMPTY ||
8278 element == EL_ACID_SPLASH_LEFT ||
8279 element == EL_ACID_SPLASH_RIGHT))
8281 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8282 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8283 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8284 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8285 Feld[x][y] = EL_AMOEBA_DROP;
8288 random = random * 129 + 1;
8294 if (game.explosions_delayed)
8297 game.explosions_delayed = FALSE;
8299 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8301 element = Feld[x][y];
8303 if (ExplodeField[x][y])
8304 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
8305 else if (element == EL_EXPLOSION)
8306 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8308 ExplodeField[x][y] = EX_TYPE_NONE;
8311 game.explosions_delayed = TRUE;
8314 if (game.magic_wall_active)
8316 if (!(game.magic_wall_time_left % 4))
8318 int element = Feld[magic_wall_x][magic_wall_y];
8320 if (element == EL_BD_MAGIC_WALL_FULL ||
8321 element == EL_BD_MAGIC_WALL_ACTIVE ||
8322 element == EL_BD_MAGIC_WALL_EMPTYING)
8323 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
8325 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
8328 if (game.magic_wall_time_left > 0)
8330 game.magic_wall_time_left--;
8331 if (!game.magic_wall_time_left)
8333 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8335 element = Feld[x][y];
8337 if (element == EL_MAGIC_WALL_ACTIVE ||
8338 element == EL_MAGIC_WALL_FULL)
8340 Feld[x][y] = EL_MAGIC_WALL_DEAD;
8341 DrawLevelField(x, y);
8343 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
8344 element == EL_BD_MAGIC_WALL_FULL)
8346 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
8347 DrawLevelField(x, y);
8351 game.magic_wall_active = FALSE;
8356 if (game.light_time_left > 0)
8358 game.light_time_left--;
8360 if (game.light_time_left == 0)
8361 RedrawAllLightSwitchesAndInvisibleElements();
8364 if (game.timegate_time_left > 0)
8366 game.timegate_time_left--;
8368 if (game.timegate_time_left == 0)
8369 CloseAllOpenTimegates();
8372 for (i = 0; i < MAX_PLAYERS; i++)
8374 struct PlayerInfo *player = &stored_player[i];
8376 if (SHIELD_ON(player))
8378 if (player->shield_deadly_time_left)
8379 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
8380 else if (player->shield_normal_time_left)
8381 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
8385 if (TimeFrames >= FRAMES_PER_SECOND)
8390 if (!level.use_step_counter)
8394 for (i = 0; i < MAX_PLAYERS; i++)
8396 struct PlayerInfo *player = &stored_player[i];
8398 if (SHIELD_ON(player))
8400 player->shield_normal_time_left--;
8402 if (player->shield_deadly_time_left > 0)
8403 player->shield_deadly_time_left--;
8411 if (TimeLeft <= 10 && setup.time_limit)
8412 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
8414 DrawGameValue_Time(TimeLeft);
8416 if (!TimeLeft && setup.time_limit)
8417 for (i = 0; i < MAX_PLAYERS; i++)
8418 KillHero(&stored_player[i]);
8420 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
8421 DrawGameValue_Time(TimePlayed);
8424 if (tape.recording || tape.playing)
8425 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
8429 PlayAllPlayersSound();
8431 if (options.debug) /* calculate frames per second */
8433 static unsigned long fps_counter = 0;
8434 static int fps_frames = 0;
8435 unsigned long fps_delay_ms = Counter() - fps_counter;
8439 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
8441 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
8444 fps_counter = Counter();
8447 redraw_mask |= REDRAW_FPS;
8451 if (stored_player[0].jx != stored_player[0].last_jx ||
8452 stored_player[0].jy != stored_player[0].last_jy)
8453 printf("::: %d, %d, %d, %d, %d\n",
8454 stored_player[0].MovDir,
8455 stored_player[0].MovPos,
8456 stored_player[0].GfxPos,
8457 stored_player[0].Frame,
8458 stored_player[0].StepFrame);
8465 for (i = 0; i < MAX_PLAYERS; i++)
8468 MOVE_DELAY_NORMAL_SPEED / stored_player[i].move_delay_value;
8470 stored_player[i].Frame += move_frames;
8472 if (stored_player[i].MovPos != 0)
8473 stored_player[i].StepFrame += move_frames;
8475 if (stored_player[i].drop_delay > 0)
8476 stored_player[i].drop_delay--;
8481 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
8483 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
8485 local_player->show_envelope = 0;
8490 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
8492 int min_x = x, min_y = y, max_x = x, max_y = y;
8495 for (i = 0; i < MAX_PLAYERS; i++)
8497 int jx = stored_player[i].jx, jy = stored_player[i].jy;
8499 if (!stored_player[i].active || &stored_player[i] == player)
8502 min_x = MIN(min_x, jx);
8503 min_y = MIN(min_y, jy);
8504 max_x = MAX(max_x, jx);
8505 max_y = MAX(max_y, jy);
8508 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
8511 static boolean AllPlayersInVisibleScreen()
8515 for (i = 0; i < MAX_PLAYERS; i++)
8517 int jx = stored_player[i].jx, jy = stored_player[i].jy;
8519 if (!stored_player[i].active)
8522 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
8529 void ScrollLevel(int dx, int dy)
8531 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
8534 BlitBitmap(drawto_field, drawto_field,
8535 FX + TILEX * (dx == -1) - softscroll_offset,
8536 FY + TILEY * (dy == -1) - softscroll_offset,
8537 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
8538 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
8539 FX + TILEX * (dx == 1) - softscroll_offset,
8540 FY + TILEY * (dy == 1) - softscroll_offset);
8544 x = (dx == 1 ? BX1 : BX2);
8545 for (y = BY1; y <= BY2; y++)
8546 DrawScreenField(x, y);
8551 y = (dy == 1 ? BY1 : BY2);
8552 for (x = BX1; x <= BX2; x++)
8553 DrawScreenField(x, y);
8556 redraw_mask |= REDRAW_FIELD;
8559 static boolean canEnterSupaplexPort(int x, int y, int dx, int dy)
8561 int nextx = x + dx, nexty = y + dy;
8562 int element = Feld[x][y];
8565 element != EL_SP_PORT_LEFT &&
8566 element != EL_SP_GRAVITY_PORT_LEFT &&
8567 element != EL_SP_PORT_HORIZONTAL &&
8568 element != EL_SP_PORT_ANY) ||
8570 element != EL_SP_PORT_RIGHT &&
8571 element != EL_SP_GRAVITY_PORT_RIGHT &&
8572 element != EL_SP_PORT_HORIZONTAL &&
8573 element != EL_SP_PORT_ANY) ||
8575 element != EL_SP_PORT_UP &&
8576 element != EL_SP_GRAVITY_PORT_UP &&
8577 element != EL_SP_PORT_VERTICAL &&
8578 element != EL_SP_PORT_ANY) ||
8580 element != EL_SP_PORT_DOWN &&
8581 element != EL_SP_GRAVITY_PORT_DOWN &&
8582 element != EL_SP_PORT_VERTICAL &&
8583 element != EL_SP_PORT_ANY) ||
8584 !IN_LEV_FIELD(nextx, nexty) ||
8585 !IS_FREE(nextx, nexty))
8591 static void CheckGravityMovement(struct PlayerInfo *player)
8593 if (game.gravity && !player->programmed_action)
8596 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
8597 int move_dir_vertical = player->effective_action & MV_VERTICAL;
8599 int move_dir_horizontal = player->action & MV_HORIZONTAL;
8600 int move_dir_vertical = player->action & MV_VERTICAL;
8603 (player->last_move_dir & MV_HORIZONTAL ?
8604 (move_dir_vertical ? move_dir_vertical : move_dir_horizontal) :
8605 (move_dir_horizontal ? move_dir_horizontal : move_dir_vertical));
8606 int jx = player->jx, jy = player->jy;
8607 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
8608 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
8609 int new_jx = jx + dx, new_jy = jy + dy;
8611 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
8613 boolean player_is_snapping = player->action & JOY_BUTTON_1;
8616 boolean player_can_fall_down =
8617 (IN_LEV_FIELD(jx, jy + 1) &&
8618 (IS_FREE(jx, jy + 1) ||
8619 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)));
8621 boolean player_can_fall_down =
8622 (IN_LEV_FIELD(jx, jy + 1) &&
8623 (IS_FREE(jx, jy + 1)));
8625 boolean player_is_moving_to_valid_field =
8628 !player_is_snapping &&
8630 IN_LEV_FIELD(new_jx, new_jy) &&
8631 (Feld[new_jx][new_jy] == EL_SP_BASE ||
8632 Feld[new_jx][new_jy] == EL_SAND ||
8633 (IS_SP_PORT(Feld[new_jx][new_jy]) &&
8634 canEnterSupaplexPort(new_jx, new_jy, dx, dy))));
8635 /* !!! extend EL_SAND to anything diggable !!! */
8637 boolean player_is_standing_on_valid_field =
8638 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
8639 (IS_WALKABLE(Feld[jx][jy]) &&
8640 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
8643 printf("::: checking gravity NOW [%d, %d, %d] [%d] [%d / %d] ...\n",
8644 player_can_fall_down,
8645 player_is_standing_on_valid_field,
8646 player_is_moving_to_valid_field,
8647 (player_is_moving_to_valid_field ? Feld[new_jx][new_jy] : -1),
8648 player->effective_action,
8649 player->can_fall_into_acid);
8652 if (player_can_fall_down &&
8653 !player_is_standing_on_valid_field &&
8654 !player_is_moving_to_valid_field)
8657 printf("::: setting programmed_action to MV_DOWN [%d,%d - %d] ...\n",
8658 jx, jy, FrameCounter);
8661 player->programmed_action = MV_DOWN;
8666 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
8669 return CheckGravityMovement(player);
8672 if (game.gravity && !player->programmed_action)
8674 int jx = player->jx, jy = player->jy;
8675 boolean field_under_player_is_free =
8676 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
8677 boolean player_is_standing_on_valid_field =
8678 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
8679 (IS_WALKABLE(Feld[jx][jy]) &&
8680 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
8682 if (field_under_player_is_free && !player_is_standing_on_valid_field)
8683 player->programmed_action = MV_DOWN;
8689 -----------------------------------------------------------------------------
8690 dx, dy: direction (non-diagonal) to try to move the player to
8691 real_dx, real_dy: direction as read from input device (can be diagonal)
8694 boolean MovePlayerOneStep(struct PlayerInfo *player,
8695 int dx, int dy, int real_dx, int real_dy)
8698 static int trigger_sides[4][2] =
8700 /* enter side leave side */
8701 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
8702 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
8703 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
8704 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
8706 int move_direction = (dx == -1 ? MV_LEFT :
8707 dx == +1 ? MV_RIGHT :
8709 dy == +1 ? MV_DOWN : MV_NO_MOVING);
8710 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
8711 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
8713 int jx = player->jx, jy = player->jy;
8714 int new_jx = jx + dx, new_jy = jy + dy;
8718 if (!player->active || (!dx && !dy))
8719 return MF_NO_ACTION;
8721 player->MovDir = (dx < 0 ? MV_LEFT :
8724 dy > 0 ? MV_DOWN : MV_NO_MOVING);
8726 if (!IN_LEV_FIELD(new_jx, new_jy))
8727 return MF_NO_ACTION;
8729 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
8730 return MF_NO_ACTION;
8733 element = MovingOrBlocked2Element(new_jx, new_jy);
8735 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
8738 if (DONT_RUN_INTO(element))
8740 if (element == EL_ACID && dx == 0 && dy == 1)
8742 SplashAcid(new_jx, new_jy);
8743 Feld[jx][jy] = EL_PLAYER_1;
8744 InitMovingField(jx, jy, MV_DOWN);
8745 Store[jx][jy] = EL_ACID;
8746 ContinueMoving(jx, jy);
8750 TestIfHeroRunsIntoBadThing(jx, jy, player->MovDir);
8755 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
8756 if (can_move != MF_MOVING)
8759 /* check if DigField() has caused relocation of the player */
8760 if (player->jx != jx || player->jy != jy)
8761 return MF_NO_ACTION;
8763 StorePlayer[jx][jy] = 0;
8764 player->last_jx = jx;
8765 player->last_jy = jy;
8766 player->jx = new_jx;
8767 player->jy = new_jy;
8768 StorePlayer[new_jx][new_jy] = player->element_nr;
8771 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
8773 player->step_counter++;
8776 player->drop_delay = 0;
8779 PlayerVisit[jx][jy] = FrameCounter;
8781 ScrollPlayer(player, SCROLL_INIT);
8784 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
8786 CheckTriggeredElementChangeSide(jx, jy, Feld[jx][jy], CE_OTHER_GETS_LEFT,
8788 CheckElementChangeSide(jx, jy, Feld[jx][jy], CE_LEFT_BY_PLAYER,leave_side);
8791 if (IS_CUSTOM_ELEMENT(Feld[new_jx][new_jy]))
8793 CheckTriggeredElementChangeSide(new_jx, new_jy, Feld[new_jx][new_jy],
8794 CE_OTHER_GETS_ENTERED, enter_side);
8795 CheckElementChangeSide(new_jx, new_jy, Feld[new_jx][new_jy],
8796 CE_ENTERED_BY_PLAYER, enter_side);
8803 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
8805 int jx = player->jx, jy = player->jy;
8806 int old_jx = jx, old_jy = jy;
8807 int moved = MF_NO_ACTION;
8810 if (!player->active)
8815 if (player->MovPos == 0)
8817 player->is_moving = FALSE;
8818 player->is_digging = FALSE;
8819 player->is_collecting = FALSE;
8820 player->is_snapping = FALSE;
8821 player->is_pushing = FALSE;
8827 if (!player->active || (!dx && !dy))
8832 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
8838 if (!FrameReached(&player->move_delay, player->move_delay_value))
8841 if (!FrameReached(&player->move_delay, player->move_delay_value) &&
8842 !(tape.playing && tape.file_version < FILE_VERSION_2_0))
8848 /* remove the last programmed player action */
8849 player->programmed_action = 0;
8853 /* should only happen if pre-1.2 tape recordings are played */
8854 /* this is only for backward compatibility */
8856 int original_move_delay_value = player->move_delay_value;
8859 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
8863 /* scroll remaining steps with finest movement resolution */
8864 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
8866 while (player->MovPos)
8868 ScrollPlayer(player, SCROLL_GO_ON);
8869 ScrollScreen(NULL, SCROLL_GO_ON);
8875 player->move_delay_value = original_move_delay_value;
8878 if (player->last_move_dir & MV_HORIZONTAL)
8880 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
8881 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
8885 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
8886 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
8892 if (moved & MF_MOVING && !ScreenMovPos &&
8893 (player == local_player || !options.network))
8895 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
8896 int offset = (setup.scroll_delay ? 3 : 0);
8898 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
8900 /* actual player has left the screen -- scroll in that direction */
8901 if (jx != old_jx) /* player has moved horizontally */
8902 scroll_x += (jx - old_jx);
8903 else /* player has moved vertically */
8904 scroll_y += (jy - old_jy);
8908 if (jx != old_jx) /* player has moved horizontally */
8910 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
8911 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
8912 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
8914 /* don't scroll over playfield boundaries */
8915 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
8916 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
8918 /* don't scroll more than one field at a time */
8919 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
8921 /* don't scroll against the player's moving direction */
8922 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
8923 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
8924 scroll_x = old_scroll_x;
8926 else /* player has moved vertically */
8928 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
8929 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
8930 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
8932 /* don't scroll over playfield boundaries */
8933 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
8934 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
8936 /* don't scroll more than one field at a time */
8937 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
8939 /* don't scroll against the player's moving direction */
8940 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
8941 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
8942 scroll_y = old_scroll_y;
8946 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
8948 if (!options.network && !AllPlayersInVisibleScreen())
8950 scroll_x = old_scroll_x;
8951 scroll_y = old_scroll_y;
8955 ScrollScreen(player, SCROLL_INIT);
8956 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
8963 InitPlayerGfxAnimation(player, ACTION_DEFAULT);
8965 if (!(moved & MF_MOVING) && !player->is_pushing)
8970 player->StepFrame = 0;
8972 if (moved & MF_MOVING)
8974 if (old_jx != jx && old_jy == jy)
8975 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
8976 else if (old_jx == jx && old_jy != jy)
8977 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
8979 DrawLevelField(jx, jy); /* for "crumbled sand" */
8981 player->last_move_dir = player->MovDir;
8982 player->is_moving = TRUE;
8984 player->is_snapping = FALSE;
8988 player->is_switching = FALSE;
8991 player->is_dropping = FALSE;
8995 /* !!! ENABLE THIS FOR OLD VERSIONS !!! */
8997 static int trigger_sides[4][2] =
8999 /* enter side leave side */
9000 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9001 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9002 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9003 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9005 int move_direction = player->MovDir;
9006 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9007 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9010 CheckTriggeredElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy],
9012 player->index_bit, leave_side);
9014 if (IS_CUSTOM_ELEMENT(Feld[old_jx][old_jy]))
9015 CheckElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy],
9017 player->index_bit, leave_side);
9019 CheckTriggeredElementChangePlayer(jx, jy, Feld[jx][jy],
9020 CE_OTHER_GETS_ENTERED,
9021 player->index_bit, enter_side);
9023 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9024 CheckElementChangePlayer(jx, jy, Feld[jx][jy], CE_ENTERED_BY_PLAYER,
9025 player->index_bit, enter_side);
9035 CheckGravityMovementWhenNotMoving(player);
9038 player->last_move_dir = MV_NO_MOVING;
9040 player->is_moving = FALSE;
9043 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9045 TestIfHeroTouchesBadThing(jx, jy);
9046 TestIfPlayerTouchesCustomElement(jx, jy);
9049 if (!player->active)
9055 void ScrollPlayer(struct PlayerInfo *player, int mode)
9057 int jx = player->jx, jy = player->jy;
9058 int last_jx = player->last_jx, last_jy = player->last_jy;
9059 int move_stepsize = TILEX / player->move_delay_value;
9061 if (!player->active || !player->MovPos)
9064 if (mode == SCROLL_INIT)
9066 player->actual_frame_counter = FrameCounter;
9067 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9069 if (Feld[last_jx][last_jy] == EL_EMPTY)
9070 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9078 else if (!FrameReached(&player->actual_frame_counter, 1))
9081 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9082 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9084 if (!player->block_last_field &&
9085 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
9086 Feld[last_jx][last_jy] = EL_EMPTY;
9088 /* before DrawPlayer() to draw correct player graphic for this case */
9089 if (player->MovPos == 0)
9090 CheckGravityMovement(player);
9093 DrawPlayer(player); /* needed here only to cleanup last field */
9096 if (player->MovPos == 0) /* player reached destination field */
9099 if (player->move_delay_reset_counter > 0)
9101 player->move_delay_reset_counter--;
9103 if (player->move_delay_reset_counter == 0)
9105 /* continue with normal speed after quickly moving through gate */
9106 HALVE_PLAYER_SPEED(player);
9108 /* be able to make the next move without delay */
9109 player->move_delay = 0;
9113 if (IS_PASSABLE(Feld[last_jx][last_jy]))
9115 /* continue with normal speed after quickly moving through gate */
9116 HALVE_PLAYER_SPEED(player);
9118 /* be able to make the next move without delay */
9119 player->move_delay = 0;
9123 if (player->block_last_field &&
9124 Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
9125 Feld[last_jx][last_jy] = EL_EMPTY;
9127 player->last_jx = jx;
9128 player->last_jy = jy;
9130 if (Feld[jx][jy] == EL_EXIT_OPEN ||
9131 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
9132 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
9134 DrawPlayer(player); /* needed here only to cleanup last field */
9137 if (local_player->friends_still_needed == 0 ||
9138 IS_SP_ELEMENT(Feld[jx][jy]))
9139 player->LevelSolved = player->GameOver = TRUE;
9143 /* !!! ENABLE THIS FOR NEW VERSIONS !!! */
9144 /* this breaks one level: "machine", level 000 */
9146 static int trigger_sides[4][2] =
9148 /* enter side leave side */
9149 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* moving left */
9150 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* moving right */
9151 { CH_SIDE_BOTTOM, CH_SIDE_TOP }, /* moving up */
9152 { CH_SIDE_TOP, CH_SIDE_BOTTOM } /* moving down */
9154 int move_direction = player->MovDir;
9155 int enter_side = trigger_sides[MV_DIR_BIT(move_direction)][0];
9156 int leave_side = trigger_sides[MV_DIR_BIT(move_direction)][1];
9157 int old_jx = last_jx;
9158 int old_jy = last_jy;
9161 CheckTriggeredElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy],
9163 player->index_bit, leave_side);
9165 if (IS_CUSTOM_ELEMENT(Feld[old_jx][old_jy]))
9166 CheckElementChangePlayer(old_jx, old_jy, Feld[old_jx][old_jy],
9168 player->index_bit, leave_side);
9170 CheckTriggeredElementChangePlayer(jx, jy, Feld[jx][jy],
9171 CE_OTHER_GETS_ENTERED,
9172 player->index_bit, enter_side);
9174 if (IS_CUSTOM_ELEMENT(Feld[jx][jy]))
9175 CheckElementChangePlayer(jx, jy, Feld[jx][jy], CE_ENTERED_BY_PLAYER,
9176 player->index_bit, enter_side);
9182 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9184 TestIfHeroTouchesBadThing(jx, jy);
9185 TestIfPlayerTouchesCustomElement(jx, jy);
9187 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
9190 if (!player->active)
9194 if (level.use_step_counter)
9200 for (i = 0; i < MAX_PLAYERS; i++)
9202 struct PlayerInfo *player = &stored_player[i];
9204 if (SHIELD_ON(player))
9206 player->shield_normal_time_left--;
9208 if (player->shield_deadly_time_left > 0)
9209 player->shield_deadly_time_left--;
9217 if (TimeLeft <= 10 && setup.time_limit)
9218 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9220 DrawGameValue_Time(TimeLeft);
9222 if (!TimeLeft && setup.time_limit)
9223 for (i = 0; i < MAX_PLAYERS; i++)
9224 KillHero(&stored_player[i]);
9226 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9227 DrawGameValue_Time(TimePlayed);
9230 if (tape.single_step && tape.recording && !tape.pausing &&
9231 !player->programmed_action)
9232 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9236 void ScrollScreen(struct PlayerInfo *player, int mode)
9238 static unsigned long screen_frame_counter = 0;
9240 if (mode == SCROLL_INIT)
9242 /* set scrolling step size according to actual player's moving speed */
9243 ScrollStepSize = TILEX / player->move_delay_value;
9245 screen_frame_counter = FrameCounter;
9246 ScreenMovDir = player->MovDir;
9247 ScreenMovPos = player->MovPos;
9248 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9251 else if (!FrameReached(&screen_frame_counter, 1))
9256 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
9257 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9258 redraw_mask |= REDRAW_FIELD;
9261 ScreenMovDir = MV_NO_MOVING;
9264 void TestIfPlayerTouchesCustomElement(int x, int y)
9266 static int xy[4][2] =
9273 static int trigger_sides[4][2] =
9275 /* center side border side */
9276 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9277 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9278 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9279 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9281 static int touch_dir[4] =
9288 int center_element = Feld[x][y]; /* should always be non-moving! */
9291 for (i = 0; i < NUM_DIRECTIONS; i++)
9293 int xx = x + xy[i][0];
9294 int yy = y + xy[i][1];
9295 int center_side = trigger_sides[i][0];
9296 int border_side = trigger_sides[i][1];
9299 if (!IN_LEV_FIELD(xx, yy))
9302 if (IS_PLAYER(x, y))
9304 struct PlayerInfo *player = PLAYERINFO(x, y);
9306 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9307 border_element = Feld[xx][yy]; /* may be moving! */
9308 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9309 border_element = Feld[xx][yy];
9310 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9311 border_element = MovingOrBlocked2Element(xx, yy);
9313 continue; /* center and border element do not touch */
9315 CheckTriggeredElementChangePlayer(xx, yy, border_element,
9316 CE_OTHER_GETS_TOUCHED,
9317 player->index_bit, border_side);
9318 CheckElementChangePlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
9319 player->index_bit, border_side);
9321 else if (IS_PLAYER(xx, yy))
9323 struct PlayerInfo *player = PLAYERINFO(xx, yy);
9325 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9327 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9328 continue; /* center and border element do not touch */
9331 CheckTriggeredElementChangePlayer(x, y, center_element,
9332 CE_OTHER_GETS_TOUCHED,
9333 player->index_bit, center_side);
9334 CheckElementChangePlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
9335 player->index_bit, center_side);
9342 void TestIfElementTouchesCustomElement(int x, int y)
9344 static int xy[4][2] =
9351 static int trigger_sides[4][2] =
9353 /* center side border side */
9354 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9355 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9356 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9357 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9359 static int touch_dir[4] =
9366 boolean change_center_element = FALSE;
9367 int center_element_change_page = 0;
9368 int center_element = Feld[x][y]; /* should always be non-moving! */
9369 int border_trigger_element;
9372 for (i = 0; i < NUM_DIRECTIONS; i++)
9374 int xx = x + xy[i][0];
9375 int yy = y + xy[i][1];
9376 int center_side = trigger_sides[i][0];
9377 int border_side = trigger_sides[i][1];
9380 if (!IN_LEV_FIELD(xx, yy))
9383 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9384 border_element = Feld[xx][yy]; /* may be moving! */
9385 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9386 border_element = Feld[xx][yy];
9387 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9388 border_element = MovingOrBlocked2Element(xx, yy);
9390 continue; /* center and border element do not touch */
9392 /* check for change of center element (but change it only once) */
9393 if (IS_CUSTOM_ELEMENT(center_element) &&
9394 HAS_ANY_CHANGE_EVENT(center_element, CE_OTHER_IS_TOUCHING) &&
9395 !change_center_element)
9397 for (j = 0; j < element_info[center_element].num_change_pages; j++)
9399 struct ElementChangeInfo *change =
9400 &element_info[center_element].change_page[j];
9402 if (change->can_change &&
9403 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
9404 change->trigger_side & border_side &&
9406 IS_EQUAL_OR_IN_GROUP(border_element, change->trigger_element)
9408 change->trigger_element == border_element
9412 change_center_element = TRUE;
9413 center_element_change_page = j;
9414 border_trigger_element = border_element;
9421 /* check for change of border element */
9422 if (IS_CUSTOM_ELEMENT(border_element) &&
9423 HAS_ANY_CHANGE_EVENT(border_element, CE_OTHER_IS_TOUCHING))
9425 for (j = 0; j < element_info[border_element].num_change_pages; j++)
9427 struct ElementChangeInfo *change =
9428 &element_info[border_element].change_page[j];
9430 if (change->can_change &&
9431 change->events & CH_EVENT_BIT(CE_OTHER_IS_TOUCHING) &&
9432 change->trigger_side & center_side &&
9434 IS_EQUAL_OR_IN_GROUP(center_element, change->trigger_element)
9436 change->trigger_element == center_element
9441 printf("::: border_element %d, %d\n", x, y);
9444 CheckElementChangePage(xx, yy, border_element, center_element,
9445 CE_OTHER_IS_TOUCHING, j);
9452 if (change_center_element)
9455 printf("::: center_element %d, %d\n", x, y);
9458 CheckElementChangePage(x, y, center_element, border_trigger_element,
9459 CE_OTHER_IS_TOUCHING, center_element_change_page);
9463 void TestIfElementHitsCustomElement(int x, int y, int direction)
9465 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9466 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9467 int hitx = x + dx, hity = y + dy;
9468 int hitting_element = Feld[x][y];
9469 int touched_element;
9471 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
9472 !IS_FREE(hitx, hity) &&
9473 (!IS_MOVING(hitx, hity) ||
9474 MovDir[hitx][hity] != direction ||
9475 ABS(MovPos[hitx][hity]) <= TILEY / 2));
9478 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9482 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
9486 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9487 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9489 CheckElementChangeSide(x, y, hitting_element, touched_element,
9490 CE_HITTING_SOMETHING, direction);
9492 if (IN_LEV_FIELD(hitx, hity))
9494 int opposite_direction = MV_DIR_OPPOSITE(direction);
9495 int hitting_side = direction;
9496 int touched_side = opposite_direction;
9498 int touched_element = MovingOrBlocked2Element(hitx, hity);
9501 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9502 MovDir[hitx][hity] != direction ||
9503 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9512 CheckElementChangeSide(hitx, hity, touched_element, hitting_element,
9513 CE_HIT_BY_SOMETHING, opposite_direction);
9515 if (IS_CUSTOM_ELEMENT(hitting_element) &&
9516 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_HITTING))
9518 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
9520 struct ElementChangeInfo *change =
9521 &element_info[hitting_element].change_page[i];
9523 if (change->can_change &&
9524 change->events & CH_EVENT_BIT(CE_OTHER_IS_HITTING) &&
9525 change->trigger_side & touched_side &&
9528 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
9530 change->trigger_element == touched_element
9534 CheckElementChangePage(x, y, hitting_element, touched_element,
9535 CE_OTHER_IS_HITTING, i);
9541 if (IS_CUSTOM_ELEMENT(touched_element) &&
9542 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_HIT))
9544 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
9546 struct ElementChangeInfo *change =
9547 &element_info[touched_element].change_page[i];
9549 if (change->can_change &&
9550 change->events & CH_EVENT_BIT(CE_OTHER_GETS_HIT) &&
9551 change->trigger_side & hitting_side &&
9553 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
9555 change->trigger_element == hitting_element
9559 CheckElementChangePage(hitx, hity, touched_element,
9560 hitting_element, CE_OTHER_GETS_HIT, i);
9570 void TestIfElementSmashesCustomElement(int x, int y, int direction)
9572 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9573 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9574 int hitx = x + dx, hity = y + dy;
9575 int hitting_element = Feld[x][y];
9576 int touched_element;
9578 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
9579 !IS_FREE(hitx, hity) &&
9580 (!IS_MOVING(hitx, hity) ||
9581 MovDir[hitx][hity] != direction ||
9582 ABS(MovPos[hitx][hity]) <= TILEY / 2));
9585 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9589 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
9593 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9594 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9596 CheckElementChangeSide(x, y, hitting_element, touched_element,
9597 EP_CAN_SMASH_EVERYTHING, direction);
9599 if (IN_LEV_FIELD(hitx, hity))
9601 int opposite_direction = MV_DIR_OPPOSITE(direction);
9602 int hitting_side = direction;
9603 int touched_side = opposite_direction;
9605 int touched_element = MovingOrBlocked2Element(hitx, hity);
9608 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9609 MovDir[hitx][hity] != direction ||
9610 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9619 CheckElementChangeSide(hitx, hity, touched_element, hitting_element,
9620 CE_SMASHED_BY_SOMETHING, opposite_direction);
9622 if (IS_CUSTOM_ELEMENT(hitting_element) &&
9623 HAS_ANY_CHANGE_EVENT(hitting_element, CE_OTHER_IS_SMASHING))
9625 for (i = 0; i < element_info[hitting_element].num_change_pages; i++)
9627 struct ElementChangeInfo *change =
9628 &element_info[hitting_element].change_page[i];
9630 if (change->can_change &&
9631 change->events & CH_EVENT_BIT(CE_OTHER_IS_SMASHING) &&
9632 change->trigger_side & touched_side &&
9635 IS_EQUAL_OR_IN_GROUP(touched_element, change->trigger_element)
9637 change->trigger_element == touched_element
9641 CheckElementChangePage(x, y, hitting_element, touched_element,
9642 CE_OTHER_IS_SMASHING, i);
9648 if (IS_CUSTOM_ELEMENT(touched_element) &&
9649 HAS_ANY_CHANGE_EVENT(touched_element, CE_OTHER_GETS_SMASHED))
9651 for (i = 0; i < element_info[touched_element].num_change_pages; i++)
9653 struct ElementChangeInfo *change =
9654 &element_info[touched_element].change_page[i];
9656 if (change->can_change &&
9657 change->events & CH_EVENT_BIT(CE_OTHER_GETS_SMASHED) &&
9658 change->trigger_side & hitting_side &&
9660 IS_EQUAL_OR_IN_GROUP(hitting_element, change->trigger_element)
9662 change->trigger_element == hitting_element
9666 CheckElementChangePage(hitx, hity, touched_element,
9667 hitting_element, CE_OTHER_GETS_SMASHED, i);
9677 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
9679 int i, kill_x = -1, kill_y = -1;
9680 static int test_xy[4][2] =
9687 static int test_dir[4] =
9695 for (i = 0; i < NUM_DIRECTIONS; i++)
9697 int test_x, test_y, test_move_dir, test_element;
9699 test_x = good_x + test_xy[i][0];
9700 test_y = good_y + test_xy[i][1];
9701 if (!IN_LEV_FIELD(test_x, test_y))
9705 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
9708 test_element = Feld[test_x][test_y];
9710 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
9713 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
9714 2nd case: DONT_TOUCH style bad thing does not move away from good thing
9716 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
9717 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
9725 if (kill_x != -1 || kill_y != -1)
9727 if (IS_PLAYER(good_x, good_y))
9729 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
9731 if (player->shield_deadly_time_left > 0)
9732 Bang(kill_x, kill_y);
9733 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
9737 Bang(good_x, good_y);
9741 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
9743 int i, kill_x = -1, kill_y = -1;
9744 int bad_element = Feld[bad_x][bad_y];
9745 static int test_xy[4][2] =
9752 static int touch_dir[4] =
9759 static int test_dir[4] =
9767 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
9770 for (i = 0; i < NUM_DIRECTIONS; i++)
9772 int test_x, test_y, test_move_dir, test_element;
9774 test_x = bad_x + test_xy[i][0];
9775 test_y = bad_y + test_xy[i][1];
9776 if (!IN_LEV_FIELD(test_x, test_y))
9780 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NO_MOVING);
9782 test_element = Feld[test_x][test_y];
9784 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
9785 2nd case: DONT_TOUCH style bad thing does not move away from good thing
9787 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
9788 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
9790 /* good thing is player or penguin that does not move away */
9791 if (IS_PLAYER(test_x, test_y))
9793 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
9795 if (bad_element == EL_ROBOT && player->is_moving)
9796 continue; /* robot does not kill player if he is moving */
9798 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9800 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9801 continue; /* center and border element do not touch */
9808 else if (test_element == EL_PENGUIN)
9817 if (kill_x != -1 || kill_y != -1)
9819 if (IS_PLAYER(kill_x, kill_y))
9821 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
9823 if (player->shield_deadly_time_left > 0)
9825 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
9829 Bang(kill_x, kill_y);
9833 void TestIfHeroTouchesBadThing(int x, int y)
9835 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
9838 void TestIfHeroRunsIntoBadThing(int x, int y, int move_dir)
9840 TestIfGoodThingHitsBadThing(x, y, move_dir);
9843 void TestIfBadThingTouchesHero(int x, int y)
9845 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
9848 void TestIfBadThingRunsIntoHero(int x, int y, int move_dir)
9850 TestIfBadThingHitsGoodThing(x, y, move_dir);
9853 void TestIfFriendTouchesBadThing(int x, int y)
9855 TestIfGoodThingHitsBadThing(x, y, MV_NO_MOVING);
9858 void TestIfBadThingTouchesFriend(int x, int y)
9860 TestIfBadThingHitsGoodThing(x, y, MV_NO_MOVING);
9863 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
9865 int i, kill_x = bad_x, kill_y = bad_y;
9866 static int xy[4][2] =
9874 for (i = 0; i < NUM_DIRECTIONS; i++)
9878 x = bad_x + xy[i][0];
9879 y = bad_y + xy[i][1];
9880 if (!IN_LEV_FIELD(x, y))
9883 element = Feld[x][y];
9884 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
9885 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
9893 if (kill_x != bad_x || kill_y != bad_y)
9897 void KillHero(struct PlayerInfo *player)
9899 int jx = player->jx, jy = player->jy;
9901 if (!player->active)
9904 /* remove accessible field at the player's position */
9905 Feld[jx][jy] = EL_EMPTY;
9907 /* deactivate shield (else Bang()/Explode() would not work right) */
9908 player->shield_normal_time_left = 0;
9909 player->shield_deadly_time_left = 0;
9915 static void KillHeroUnlessEnemyProtected(int x, int y)
9917 if (!PLAYER_ENEMY_PROTECTED(x, y))
9918 KillHero(PLAYERINFO(x, y));
9921 static void KillHeroUnlessExplosionProtected(int x, int y)
9923 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
9924 KillHero(PLAYERINFO(x, y));
9927 void BuryHero(struct PlayerInfo *player)
9929 int jx = player->jx, jy = player->jy;
9931 if (!player->active)
9935 PlayLevelSoundElementAction(jx, jy, player->element_nr, ACTION_DYING);
9937 PlayLevelSound(jx, jy, SND_CLASS_PLAYER_DYING);
9939 PlayLevelSound(jx, jy, SND_GAME_LOSING);
9941 player->GameOver = TRUE;
9945 void RemoveHero(struct PlayerInfo *player)
9947 int jx = player->jx, jy = player->jy;
9948 int i, found = FALSE;
9950 player->present = FALSE;
9951 player->active = FALSE;
9953 if (!ExplodeField[jx][jy])
9954 StorePlayer[jx][jy] = 0;
9956 for (i = 0; i < MAX_PLAYERS; i++)
9957 if (stored_player[i].active)
9961 AllPlayersGone = TRUE;
9968 =============================================================================
9969 checkDiagonalPushing()
9970 -----------------------------------------------------------------------------
9971 check if diagonal input device direction results in pushing of object
9972 (by checking if the alternative direction is walkable, diggable, ...)
9973 =============================================================================
9976 static boolean checkDiagonalPushing(struct PlayerInfo *player,
9977 int x, int y, int real_dx, int real_dy)
9979 int jx, jy, dx, dy, xx, yy;
9981 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
9984 /* diagonal direction: check alternative direction */
9989 xx = jx + (dx == 0 ? real_dx : 0);
9990 yy = jy + (dy == 0 ? real_dy : 0);
9992 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
9996 =============================================================================
9998 -----------------------------------------------------------------------------
9999 x, y: field next to player (non-diagonal) to try to dig to
10000 real_dx, real_dy: direction as read from input device (can be diagonal)
10001 =============================================================================
10004 int DigField(struct PlayerInfo *player,
10005 int oldx, int oldy, int x, int y,
10006 int real_dx, int real_dy, int mode)
10008 static int trigger_sides[4] =
10010 CH_SIDE_RIGHT, /* moving left */
10011 CH_SIDE_LEFT, /* moving right */
10012 CH_SIDE_BOTTOM, /* moving up */
10013 CH_SIDE_TOP, /* moving down */
10016 boolean use_spring_bug = (game.engine_version < VERSION_IDENT(2,2,0,0));
10018 int jx = oldx, jy = oldy;
10019 int dx = x - jx, dy = y - jy;
10020 int nextx = x + dx, nexty = y + dy;
10021 int move_direction = (dx == -1 ? MV_LEFT :
10022 dx == +1 ? MV_RIGHT :
10024 dy == +1 ? MV_DOWN : MV_NO_MOVING);
10025 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
10026 int dig_side = trigger_sides[MV_DIR_BIT(move_direction)];
10027 int old_element = Feld[jx][jy];
10030 if (player->MovPos == 0)
10032 player->is_digging = FALSE;
10033 player->is_collecting = FALSE;
10036 if (player->MovPos == 0) /* last pushing move finished */
10037 player->is_pushing = FALSE;
10039 if (mode == DF_NO_PUSH) /* player just stopped pushing */
10041 player->is_switching = FALSE;
10042 player->push_delay = 0;
10044 return MF_NO_ACTION;
10047 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10048 return MF_NO_ACTION;
10053 if (IS_TUBE(Feld[jx][jy]) || IS_TUBE(Back[jx][jy]))
10055 if (IS_TUBE(Feld[jx][jy]) ||
10056 (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0)))
10060 int tube_element = (IS_TUBE(Feld[jx][jy]) ? Feld[jx][jy] : Back[jx][jy]);
10061 int tube_leave_directions[][2] =
10063 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
10064 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
10065 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
10066 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
10067 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
10068 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
10069 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
10070 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
10071 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
10072 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
10073 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
10074 { -1, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN }
10077 while (tube_leave_directions[i][0] != tube_element)
10080 if (tube_leave_directions[i][0] == -1) /* should not happen */
10084 if (!(tube_leave_directions[i][1] & move_direction))
10085 return MF_NO_ACTION; /* tube has no opening in this direction */
10090 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
10091 old_element = Back[jx][jy];
10095 if (IS_WALKABLE(old_element) &&
10096 !(element_info[old_element].access_direction & move_direction))
10097 return MF_NO_ACTION; /* field has no opening in this direction */
10099 element = Feld[x][y];
10101 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
10102 game.engine_version >= VERSION_IDENT(2,2,0,0))
10103 return MF_NO_ACTION;
10107 case EL_SP_PORT_LEFT:
10108 case EL_SP_PORT_RIGHT:
10109 case EL_SP_PORT_UP:
10110 case EL_SP_PORT_DOWN:
10111 case EL_SP_PORT_HORIZONTAL:
10112 case EL_SP_PORT_VERTICAL:
10113 case EL_SP_PORT_ANY:
10114 case EL_SP_GRAVITY_PORT_LEFT:
10115 case EL_SP_GRAVITY_PORT_RIGHT:
10116 case EL_SP_GRAVITY_PORT_UP:
10117 case EL_SP_GRAVITY_PORT_DOWN:
10119 if (!canEnterSupaplexPort(x, y, dx, dy))
10120 return MF_NO_ACTION;
10123 element != EL_SP_PORT_LEFT &&
10124 element != EL_SP_GRAVITY_PORT_LEFT &&
10125 element != EL_SP_PORT_HORIZONTAL &&
10126 element != EL_SP_PORT_ANY) ||
10128 element != EL_SP_PORT_RIGHT &&
10129 element != EL_SP_GRAVITY_PORT_RIGHT &&
10130 element != EL_SP_PORT_HORIZONTAL &&
10131 element != EL_SP_PORT_ANY) ||
10133 element != EL_SP_PORT_UP &&
10134 element != EL_SP_GRAVITY_PORT_UP &&
10135 element != EL_SP_PORT_VERTICAL &&
10136 element != EL_SP_PORT_ANY) ||
10138 element != EL_SP_PORT_DOWN &&
10139 element != EL_SP_GRAVITY_PORT_DOWN &&
10140 element != EL_SP_PORT_VERTICAL &&
10141 element != EL_SP_PORT_ANY) ||
10142 !IN_LEV_FIELD(nextx, nexty) ||
10143 !IS_FREE(nextx, nexty))
10144 return MF_NO_ACTION;
10147 if (element == EL_SP_GRAVITY_PORT_LEFT ||
10148 element == EL_SP_GRAVITY_PORT_RIGHT ||
10149 element == EL_SP_GRAVITY_PORT_UP ||
10150 element == EL_SP_GRAVITY_PORT_DOWN)
10151 game.gravity = !game.gravity;
10153 /* automatically move to the next field with double speed */
10154 player->programmed_action = move_direction;
10156 if (player->move_delay_reset_counter == 0)
10158 player->move_delay_reset_counter = 2; /* two double speed steps */
10160 DOUBLE_PLAYER_SPEED(player);
10163 player->move_delay_reset_counter = 2;
10165 DOUBLE_PLAYER_SPEED(player);
10169 printf("::: passing port %d,%d [%d]\n", x, y, FrameCounter);
10172 PlayLevelSound(x, y, SND_CLASS_SP_PORT_PASSING);
10177 case EL_TUBE_VERTICAL:
10178 case EL_TUBE_HORIZONTAL:
10179 case EL_TUBE_VERTICAL_LEFT:
10180 case EL_TUBE_VERTICAL_RIGHT:
10181 case EL_TUBE_HORIZONTAL_UP:
10182 case EL_TUBE_HORIZONTAL_DOWN:
10183 case EL_TUBE_LEFT_UP:
10184 case EL_TUBE_LEFT_DOWN:
10185 case EL_TUBE_RIGHT_UP:
10186 case EL_TUBE_RIGHT_DOWN:
10189 int tube_enter_directions[][2] =
10191 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
10192 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
10193 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
10194 { EL_TUBE_VERTICAL_LEFT, MV_RIGHT | MV_UP | MV_DOWN },
10195 { EL_TUBE_VERTICAL_RIGHT, MV_LEFT | MV_UP | MV_DOWN },
10196 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_DOWN },
10197 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_UP },
10198 { EL_TUBE_LEFT_UP, MV_RIGHT | MV_DOWN },
10199 { EL_TUBE_LEFT_DOWN, MV_RIGHT | MV_UP },
10200 { EL_TUBE_RIGHT_UP, MV_LEFT | MV_DOWN },
10201 { EL_TUBE_RIGHT_DOWN, MV_LEFT | MV_UP },
10202 { -1, MV_NO_MOVING }
10205 while (tube_enter_directions[i][0] != element)
10208 if (tube_enter_directions[i][0] == -1) /* should not happen */
10212 if (!(tube_enter_directions[i][1] & move_direction))
10213 return MF_NO_ACTION; /* tube has no opening in this direction */
10215 PlayLevelSound(x, y, SND_CLASS_TUBE_WALKING);
10222 if (IS_WALKABLE(element))
10224 int sound_action = ACTION_WALKING;
10226 if (!(element_info[element].access_direction & opposite_direction))
10227 return MF_NO_ACTION; /* field not accessible from this direction */
10229 if (element >= EL_GATE_1 && element <= EL_GATE_4)
10231 if (!player->key[element - EL_GATE_1])
10232 return MF_NO_ACTION;
10234 else if (element >= EL_GATE_1_GRAY && element <= EL_GATE_4_GRAY)
10236 if (!player->key[element - EL_GATE_1_GRAY])
10237 return MF_NO_ACTION;
10239 else if (element == EL_EXIT_OPEN ||
10240 element == EL_SP_EXIT_OPEN ||
10241 element == EL_SP_EXIT_OPENING)
10243 sound_action = ACTION_PASSING; /* player is passing exit */
10245 else if (element == EL_EMPTY)
10247 sound_action = ACTION_MOVING; /* nothing to walk on */
10250 /* play sound from background or player, whatever is available */
10251 if (element_info[element].sound[sound_action] != SND_UNDEFINED)
10252 PlayLevelSoundElementAction(x, y, element, sound_action);
10254 PlayLevelSoundElementAction(x, y, player->element_nr, sound_action);
10258 else if (IS_PASSABLE(element))
10260 if (!IN_LEV_FIELD(nextx, nexty) || !IS_FREE(nextx, nexty))
10261 return MF_NO_ACTION;
10263 if (IS_CUSTOM_ELEMENT(element) &&
10264 !(element_info[element].access_direction & opposite_direction))
10265 return MF_NO_ACTION; /* field not accessible from this direction */
10268 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
10269 return MF_NO_ACTION;
10272 if (element >= EL_EM_GATE_1 && element <= EL_EM_GATE_4)
10274 if (!player->key[element - EL_EM_GATE_1])
10275 return MF_NO_ACTION;
10277 else if (element >= EL_EM_GATE_1_GRAY && element <= EL_EM_GATE_4_GRAY)
10279 if (!player->key[element - EL_EM_GATE_1_GRAY])
10280 return MF_NO_ACTION;
10283 /* automatically move to the next field with double speed */
10284 player->programmed_action = move_direction;
10286 if (player->move_delay_reset_counter == 0)
10288 player->move_delay_reset_counter = 2; /* two double speed steps */
10290 DOUBLE_PLAYER_SPEED(player);
10293 player->move_delay_reset_counter = 2;
10295 DOUBLE_PLAYER_SPEED(player);
10298 PlayLevelSoundAction(x, y, ACTION_PASSING);
10302 else if (IS_DIGGABLE(element))
10306 if (mode != DF_SNAP)
10309 GfxElement[x][y] = GFX_ELEMENT(element);
10312 (GFX_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
10314 player->is_digging = TRUE;
10317 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
10319 CheckTriggeredElementChangePlayer(x, y, element, CE_OTHER_GETS_DIGGED,
10320 player->index_bit, dig_side);
10323 if (mode == DF_SNAP)
10324 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10329 else if (IS_COLLECTIBLE(element))
10333 if (mode != DF_SNAP)
10335 GfxElement[x][y] = element;
10336 player->is_collecting = TRUE;
10339 if (element == EL_SPEED_PILL)
10340 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
10341 else if (element == EL_EXTRA_TIME && level.time > 0)
10344 DrawGameValue_Time(TimeLeft);
10346 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
10348 player->shield_normal_time_left += 10;
10349 if (element == EL_SHIELD_DEADLY)
10350 player->shield_deadly_time_left += 10;
10352 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
10354 if (player->inventory_size < MAX_INVENTORY_SIZE)
10355 player->inventory_element[player->inventory_size++] = element;
10357 DrawGameValue_Dynamite(local_player->inventory_size);
10359 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
10361 player->dynabomb_count++;
10362 player->dynabombs_left++;
10364 else if (element == EL_DYNABOMB_INCREASE_SIZE)
10366 player->dynabomb_size++;
10368 else if (element == EL_DYNABOMB_INCREASE_POWER)
10370 player->dynabomb_xl = TRUE;
10372 else if ((element >= EL_KEY_1 && element <= EL_KEY_4) ||
10373 (element >= EL_EM_KEY_1 && element <= EL_EM_KEY_4))
10375 int key_nr = (element >= EL_KEY_1 && element <= EL_KEY_4 ?
10376 element - EL_KEY_1 : element - EL_EM_KEY_1);
10378 player->key[key_nr] = TRUE;
10380 DrawGameValue_Keys(player);
10382 redraw_mask |= REDRAW_DOOR_1;
10384 else if (IS_ENVELOPE(element))
10387 player->show_envelope = element;
10389 ShowEnvelope(element - EL_ENVELOPE_1);
10392 else if (IS_DROPPABLE(element)) /* can be collected and dropped */
10396 if (element_info[element].collect_count == 0)
10397 player->inventory_infinite_element = element;
10399 for (i = 0; i < element_info[element].collect_count; i++)
10400 if (player->inventory_size < MAX_INVENTORY_SIZE)
10401 player->inventory_element[player->inventory_size++] = element;
10403 DrawGameValue_Dynamite(local_player->inventory_size);
10405 else if (element_info[element].collect_count > 0)
10407 local_player->gems_still_needed -=
10408 element_info[element].collect_count;
10409 if (local_player->gems_still_needed < 0)
10410 local_player->gems_still_needed = 0;
10412 DrawGameValue_Emeralds(local_player->gems_still_needed);
10415 RaiseScoreElement(element);
10416 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
10418 CheckTriggeredElementChangePlayer(x, y, element,
10419 CE_OTHER_GETS_COLLECTED,
10420 player->index_bit, dig_side);
10423 if (mode == DF_SNAP)
10424 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10429 else if (IS_PUSHABLE(element))
10431 if (mode == DF_SNAP && element != EL_BD_ROCK)
10432 return MF_NO_ACTION;
10434 if (CAN_FALL(element) && dy)
10435 return MF_NO_ACTION;
10437 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
10438 !(element == EL_SPRING && level.use_spring_bug))
10439 return MF_NO_ACTION;
10442 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
10443 ((move_direction & MV_VERTICAL &&
10444 ((element_info[element].move_pattern & MV_LEFT &&
10445 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
10446 (element_info[element].move_pattern & MV_RIGHT &&
10447 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
10448 (move_direction & MV_HORIZONTAL &&
10449 ((element_info[element].move_pattern & MV_UP &&
10450 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
10451 (element_info[element].move_pattern & MV_DOWN &&
10452 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
10453 return MF_NO_ACTION;
10457 /* do not push elements already moving away faster than player */
10458 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
10459 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
10460 return MF_NO_ACTION;
10462 if (element == EL_SPRING && MovDir[x][y] != MV_NO_MOVING)
10463 return MF_NO_ACTION;
10467 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10469 if (player->push_delay_value == -1)
10470 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10472 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
10474 if (!player->is_pushing)
10475 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10479 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
10480 (game.engine_version < VERSION_IDENT(3,0,7,1) ||
10481 !player_is_pushing))
10482 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10485 if (!player->is_pushing &&
10486 game.engine_version >= VERSION_IDENT(2,2,0,7))
10487 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10491 printf("::: push delay: %ld [%d, %d] [%d]\n",
10492 player->push_delay_value, FrameCounter, game.engine_version,
10493 player->is_pushing);
10496 player->is_pushing = TRUE;
10498 if (!(IN_LEV_FIELD(nextx, nexty) &&
10499 (IS_FREE(nextx, nexty) ||
10500 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
10501 IS_SB_ELEMENT(element)))))
10502 return MF_NO_ACTION;
10504 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
10505 return MF_NO_ACTION;
10507 if (player->push_delay == 0) /* new pushing; restart delay */
10508 player->push_delay = FrameCounter;
10510 if (!FrameReached(&player->push_delay, player->push_delay_value) &&
10511 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
10512 element != EL_SPRING && element != EL_BALLOON)
10514 /* make sure that there is no move delay before next try to push */
10515 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10516 player->move_delay = INITIAL_MOVE_DELAY_OFF;
10518 return MF_NO_ACTION;
10522 printf("::: NOW PUSHING... [%d]\n", FrameCounter);
10525 if (IS_SB_ELEMENT(element))
10527 if (element == EL_SOKOBAN_FIELD_FULL)
10529 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
10530 local_player->sokobanfields_still_needed++;
10533 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
10535 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
10536 local_player->sokobanfields_still_needed--;
10539 Feld[x][y] = EL_SOKOBAN_OBJECT;
10541 if (Back[x][y] == Back[nextx][nexty])
10542 PlayLevelSoundAction(x, y, ACTION_PUSHING);
10543 else if (Back[x][y] != 0)
10544 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
10547 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
10550 if (local_player->sokobanfields_still_needed == 0 &&
10551 game.emulation == EMU_SOKOBAN)
10553 player->LevelSolved = player->GameOver = TRUE;
10554 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
10558 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
10560 InitMovingField(x, y, move_direction);
10561 GfxAction[x][y] = ACTION_PUSHING;
10563 if (mode == DF_SNAP)
10564 ContinueMoving(x, y);
10566 MovPos[x][y] = (dx != 0 ? dx : dy);
10568 Pushed[x][y] = TRUE;
10569 Pushed[nextx][nexty] = TRUE;
10571 if (game.engine_version < VERSION_IDENT(2,2,0,7))
10572 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10574 player->push_delay_value = -1; /* get new value later */
10576 CheckTriggeredElementChangePlayer(x, y, element, CE_OTHER_GETS_PUSHED,
10577 player->index_bit, dig_side);
10578 CheckElementChangePlayer(x, y, element, CE_PUSHED_BY_PLAYER,
10579 player->index_bit, dig_side);
10583 else if (IS_SWITCHABLE(element))
10585 if (PLAYER_SWITCHING(player, x, y))
10588 player->is_switching = TRUE;
10589 player->switch_x = x;
10590 player->switch_y = y;
10592 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
10594 if (element == EL_ROBOT_WHEEL)
10596 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
10600 DrawLevelField(x, y);
10602 else if (element == EL_SP_TERMINAL)
10606 for (yy = 0; yy < lev_fieldy; yy++) for (xx=0; xx < lev_fieldx; xx++)
10608 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
10610 else if (Feld[xx][yy] == EL_SP_TERMINAL)
10611 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
10614 else if (IS_BELT_SWITCH(element))
10616 ToggleBeltSwitch(x, y);
10618 else if (element == EL_SWITCHGATE_SWITCH_UP ||
10619 element == EL_SWITCHGATE_SWITCH_DOWN)
10621 ToggleSwitchgateSwitch(x, y);
10623 else if (element == EL_LIGHT_SWITCH ||
10624 element == EL_LIGHT_SWITCH_ACTIVE)
10626 ToggleLightSwitch(x, y);
10629 PlayLevelSound(x, y, element == EL_LIGHT_SWITCH ?
10630 SND_LIGHT_SWITCH_ACTIVATING :
10631 SND_LIGHT_SWITCH_DEACTIVATING);
10634 else if (element == EL_TIMEGATE_SWITCH)
10636 ActivateTimegateSwitch(x, y);
10638 else if (element == EL_BALLOON_SWITCH_LEFT ||
10639 element == EL_BALLOON_SWITCH_RIGHT ||
10640 element == EL_BALLOON_SWITCH_UP ||
10641 element == EL_BALLOON_SWITCH_DOWN ||
10642 element == EL_BALLOON_SWITCH_ANY)
10644 if (element == EL_BALLOON_SWITCH_ANY)
10645 game.balloon_dir = move_direction;
10647 game.balloon_dir = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
10648 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
10649 element == EL_BALLOON_SWITCH_UP ? MV_UP :
10650 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
10653 else if (element == EL_LAMP)
10655 Feld[x][y] = EL_LAMP_ACTIVE;
10656 local_player->lights_still_needed--;
10658 DrawLevelField(x, y);
10660 else if (element == EL_TIME_ORB_FULL)
10662 Feld[x][y] = EL_TIME_ORB_EMPTY;
10664 DrawGameValue_Time(TimeLeft);
10666 DrawLevelField(x, y);
10669 PlaySoundStereo(SND_TIME_ORB_FULL_COLLECTING, SOUND_MIDDLE);
10677 if (!PLAYER_SWITCHING(player, x, y))
10679 player->is_switching = TRUE;
10680 player->switch_x = x;
10681 player->switch_y = y;
10683 CheckTriggeredElementChangePlayer(x, y, element,
10684 CE_OTHER_IS_SWITCHING,
10685 player->index_bit, dig_side);
10686 CheckElementChangePlayer(x, y, element, CE_SWITCHED,
10687 player->index_bit, dig_side);
10690 CheckTriggeredElementChangePlayer(x, y, element, CE_OTHER_GETS_PRESSED,
10691 player->index_bit, dig_side);
10692 CheckElementChangePlayer(x, y, element, CE_PRESSED_BY_PLAYER,
10693 player->index_bit, dig_side);
10696 return MF_NO_ACTION;
10699 player->push_delay = 0;
10701 if (Feld[x][y] != element) /* really digged/collected something */
10702 player->is_collecting = !player->is_digging;
10707 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
10709 int jx = player->jx, jy = player->jy;
10710 int x = jx + dx, y = jy + dy;
10711 int snap_direction = (dx == -1 ? MV_LEFT :
10712 dx == +1 ? MV_RIGHT :
10714 dy == +1 ? MV_DOWN : MV_NO_MOVING);
10717 if (player->MovPos)
10720 if (player->MovPos && game.engine_version >= VERSION_IDENT(2,2,0,0))
10724 if (!player->active || !IN_LEV_FIELD(x, y))
10732 if (player->MovPos == 0)
10733 player->is_pushing = FALSE;
10735 player->is_snapping = FALSE;
10737 if (player->MovPos == 0)
10739 player->is_moving = FALSE;
10740 player->is_digging = FALSE;
10741 player->is_collecting = FALSE;
10747 if (player->is_snapping)
10750 player->MovDir = snap_direction;
10753 if (player->MovPos == 0)
10756 player->is_moving = FALSE;
10757 player->is_digging = FALSE;
10758 player->is_collecting = FALSE;
10761 player->is_dropping = FALSE;
10763 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
10766 player->is_snapping = TRUE;
10769 if (player->MovPos == 0)
10772 player->is_moving = FALSE;
10773 player->is_digging = FALSE;
10774 player->is_collecting = FALSE;
10777 DrawLevelField(x, y);
10783 boolean DropElement(struct PlayerInfo *player)
10785 static int trigger_sides[4] =
10787 CH_SIDE_LEFT, /* dropping left */
10788 CH_SIDE_RIGHT, /* dropping right */
10789 CH_SIDE_TOP, /* dropping up */
10790 CH_SIDE_BOTTOM, /* dropping down */
10792 int jx = player->jx, jy = player->jy;
10793 int drop_direction = player->MovDir;
10794 int drop_side = trigger_sides[MV_DIR_BIT(drop_direction)];
10795 int old_element = Feld[jx][jy];
10796 int drop_element = (player->inventory_size > 0 ?
10797 player->inventory_element[player->inventory_size - 1] :
10798 player->inventory_infinite_element != EL_UNDEFINED ?
10799 player->inventory_infinite_element :
10800 player->dynabombs_left > 0 ?
10801 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
10803 int new_element = drop_element; /* default: element does not change */
10805 /* check if player is active, not moving and ready to drop */
10806 if (!player->active || player->MovPos || player->drop_delay > 0)
10809 /* check if player has anything that can be dropped */
10811 if (new_element == EL_UNDEFINED)
10814 if (player->inventory_size == 0 &&
10815 player->inventory_infinite_element == EL_UNDEFINED &&
10816 player->dynabombs_left == 0)
10820 /* check if anything can be dropped at the current position */
10821 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
10824 /* collected custom elements can only be dropped on empty fields */
10826 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
10829 if (player->inventory_size > 0 &&
10830 IS_CUSTOM_ELEMENT(player->inventory_element[player->inventory_size - 1])
10831 && old_element != EL_EMPTY)
10835 if (old_element != EL_EMPTY)
10836 Back[jx][jy] = old_element; /* store old element on this field */
10838 ResetGfxAnimation(jx, jy);
10839 ResetRandomAnimationValue(jx, jy);
10841 if (player->inventory_size > 0 ||
10842 player->inventory_infinite_element != EL_UNDEFINED)
10844 if (player->inventory_size > 0)
10846 player->inventory_size--;
10849 new_element = player->inventory_element[player->inventory_size];
10852 DrawGameValue_Dynamite(local_player->inventory_size);
10854 if (new_element == EL_DYNAMITE)
10855 new_element = EL_DYNAMITE_ACTIVE;
10856 else if (new_element == EL_SP_DISK_RED)
10857 new_element = EL_SP_DISK_RED_ACTIVE;
10860 Feld[jx][jy] = new_element;
10862 if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy)))
10863 DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0);
10865 PlayLevelSoundAction(jx, jy, ACTION_DROPPING);
10868 /* needed if previous element just changed to "empty" in the last frame */
10869 Changed[jx][jy] = 0; /* allow another change */
10872 CheckTriggeredElementChangePlayer(jx, jy, new_element,
10873 CE_OTHER_GETS_DROPPED,
10874 player->index_bit, drop_side);
10875 CheckElementChangePlayer(jx, jy, new_element, CE_DROPPED_BY_PLAYER,
10876 player->index_bit, drop_side);
10878 TestIfElementTouchesCustomElement(jx, jy);
10880 else /* player is dropping a dyna bomb */
10882 player->dynabombs_left--;
10885 new_element = EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr;
10888 Feld[jx][jy] = new_element;
10890 if (IN_SCR_FIELD(SCREENX(jx), SCREENY(jy)))
10891 DrawGraphicThruMask(SCREENX(jx), SCREENY(jy), el2img(Feld[jx][jy]), 0);
10893 PlayLevelSoundAction(jx, jy, ACTION_DROPPING);
10900 if (Feld[jx][jy] == new_element) /* uninitialized unless CE change */
10903 InitField_WithBug1(jx, jy, FALSE);
10905 InitField(jx, jy, FALSE);
10906 if (CAN_MOVE(Feld[jx][jy]))
10907 InitMovDir(jx, jy);
10911 new_element = Feld[jx][jy]; /* element might have changed */
10913 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
10914 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
10917 int move_stepsize = element_info[new_element].move_stepsize;
10919 int direction, dx, dy, nextx, nexty;
10921 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
10922 MovDir[jx][jy] = player->MovDir;
10924 direction = MovDir[jx][jy];
10925 dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
10926 dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
10930 if (IN_LEV_FIELD(nextx, nexty) && IS_FREE(nextx, nexty))
10933 WasJustMoving[jx][jy] = 3;
10935 InitMovingField(jx, jy, direction);
10936 ContinueMoving(jx, jy);
10941 Changed[jx][jy] = 0; /* allow another change */
10944 TestIfElementHitsCustomElement(jx, jy, direction);
10946 CheckElementChangeSide(jx, jy, new_element, touched_element,
10947 CE_HITTING_SOMETHING, direction);
10952 player->drop_delay = 2 * TILEX / move_stepsize + 1;
10957 player->drop_delay = 8 + 8 + 8;
10961 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
10966 player->is_dropping = TRUE;
10972 /* ------------------------------------------------------------------------- */
10973 /* game sound playing functions */
10974 /* ------------------------------------------------------------------------- */
10976 static int *loop_sound_frame = NULL;
10977 static int *loop_sound_volume = NULL;
10979 void InitPlayLevelSound()
10981 int num_sounds = getSoundListSize();
10983 checked_free(loop_sound_frame);
10984 checked_free(loop_sound_volume);
10986 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
10987 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
10990 static void PlayLevelSound(int x, int y, int nr)
10992 int sx = SCREENX(x), sy = SCREENY(y);
10993 int volume, stereo_position;
10994 int max_distance = 8;
10995 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
10997 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
10998 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
11001 if (!IN_LEV_FIELD(x, y) ||
11002 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
11003 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
11006 volume = SOUND_MAX_VOLUME;
11008 if (!IN_SCR_FIELD(sx, sy))
11010 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
11011 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
11013 volume -= volume * (dx > dy ? dx : dy) / max_distance;
11016 stereo_position = (SOUND_MAX_LEFT +
11017 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
11018 (SCR_FIELDX + 2 * max_distance));
11020 if (IS_LOOP_SOUND(nr))
11022 /* This assures that quieter loop sounds do not overwrite louder ones,
11023 while restarting sound volume comparison with each new game frame. */
11025 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
11028 loop_sound_volume[nr] = volume;
11029 loop_sound_frame[nr] = FrameCounter;
11032 PlaySoundExt(nr, volume, stereo_position, type);
11035 static void PlayLevelSoundNearest(int x, int y, int sound_action)
11037 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
11038 x > LEVELX(BX2) ? LEVELX(BX2) : x,
11039 y < LEVELY(BY1) ? LEVELY(BY1) :
11040 y > LEVELY(BY2) ? LEVELY(BY2) : y,
11044 static void PlayLevelSoundAction(int x, int y, int action)
11046 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
11049 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
11051 int sound_effect = element_info[element].sound[action];
11053 if (sound_effect != SND_UNDEFINED)
11054 PlayLevelSound(x, y, sound_effect);
11057 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
11060 int sound_effect = element_info[element].sound[action];
11062 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11063 PlayLevelSound(x, y, sound_effect);
11066 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
11068 int sound_effect = element_info[Feld[x][y]].sound[action];
11070 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11071 PlayLevelSound(x, y, sound_effect);
11074 static void StopLevelSoundActionIfLoop(int x, int y, int action)
11076 int sound_effect = element_info[Feld[x][y]].sound[action];
11078 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11079 StopSound(sound_effect);
11082 static void PlayLevelMusic()
11084 if (levelset.music[level_nr] != MUS_UNDEFINED)
11085 PlayMusic(levelset.music[level_nr]); /* from config file */
11087 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
11090 void RaiseScore(int value)
11092 local_player->score += value;
11094 DrawGameValue_Score(local_player->score);
11097 void RaiseScoreElement(int element)
11102 case EL_BD_DIAMOND:
11103 case EL_EMERALD_YELLOW:
11104 case EL_EMERALD_RED:
11105 case EL_EMERALD_PURPLE:
11106 case EL_SP_INFOTRON:
11107 RaiseScore(level.score[SC_EMERALD]);
11110 RaiseScore(level.score[SC_DIAMOND]);
11113 RaiseScore(level.score[SC_CRYSTAL]);
11116 RaiseScore(level.score[SC_PEARL]);
11119 case EL_BD_BUTTERFLY:
11120 case EL_SP_ELECTRON:
11121 RaiseScore(level.score[SC_BUG]);
11124 case EL_BD_FIREFLY:
11125 case EL_SP_SNIKSNAK:
11126 RaiseScore(level.score[SC_SPACESHIP]);
11129 case EL_DARK_YAMYAM:
11130 RaiseScore(level.score[SC_YAMYAM]);
11133 RaiseScore(level.score[SC_ROBOT]);
11136 RaiseScore(level.score[SC_PACMAN]);
11139 RaiseScore(level.score[SC_NUT]);
11142 case EL_SP_DISK_RED:
11143 case EL_DYNABOMB_INCREASE_NUMBER:
11144 case EL_DYNABOMB_INCREASE_SIZE:
11145 case EL_DYNABOMB_INCREASE_POWER:
11146 RaiseScore(level.score[SC_DYNAMITE]);
11148 case EL_SHIELD_NORMAL:
11149 case EL_SHIELD_DEADLY:
11150 RaiseScore(level.score[SC_SHIELD]);
11152 case EL_EXTRA_TIME:
11153 RaiseScore(level.score[SC_TIME_BONUS]);
11159 RaiseScore(level.score[SC_KEY]);
11162 RaiseScore(element_info[element].collect_score);
11167 void RequestQuitGame(boolean ask_if_really_quit)
11169 if (AllPlayersGone ||
11170 !ask_if_really_quit ||
11171 level_editor_test_game ||
11172 Request("Do you really want to quit the game ?",
11173 REQ_ASK | REQ_STAY_CLOSED))
11175 #if defined(PLATFORM_UNIX)
11176 if (options.network)
11177 SendToServer_StopPlaying();
11181 game_status = GAME_MODE_MAIN;
11189 if (tape.playing && tape.deactivate_display)
11190 TapeDeactivateDisplayOff(TRUE);
11193 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
11196 if (tape.playing && tape.deactivate_display)
11197 TapeDeactivateDisplayOn();
11204 /* ---------- new game button stuff ---------------------------------------- */
11206 /* graphic position values for game buttons */
11207 #define GAME_BUTTON_XSIZE 30
11208 #define GAME_BUTTON_YSIZE 30
11209 #define GAME_BUTTON_XPOS 5
11210 #define GAME_BUTTON_YPOS 215
11211 #define SOUND_BUTTON_XPOS 5
11212 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
11214 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11215 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11216 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11217 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11218 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11219 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11226 } gamebutton_info[NUM_GAME_BUTTONS] =
11229 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
11234 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
11235 GAME_CTRL_ID_PAUSE,
11239 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
11244 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
11245 SOUND_CTRL_ID_MUSIC,
11246 "background music on/off"
11249 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
11250 SOUND_CTRL_ID_LOOPS,
11251 "sound loops on/off"
11254 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
11255 SOUND_CTRL_ID_SIMPLE,
11256 "normal sounds on/off"
11260 void CreateGameButtons()
11264 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11266 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
11267 struct GadgetInfo *gi;
11270 unsigned long event_mask;
11271 int gd_xoffset, gd_yoffset;
11272 int gd_x1, gd_x2, gd_y1, gd_y2;
11275 gd_xoffset = gamebutton_info[i].x;
11276 gd_yoffset = gamebutton_info[i].y;
11277 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
11278 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
11280 if (id == GAME_CTRL_ID_STOP ||
11281 id == GAME_CTRL_ID_PAUSE ||
11282 id == GAME_CTRL_ID_PLAY)
11284 button_type = GD_TYPE_NORMAL_BUTTON;
11286 event_mask = GD_EVENT_RELEASED;
11287 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11288 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11292 button_type = GD_TYPE_CHECK_BUTTON;
11294 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
11295 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
11296 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
11297 event_mask = GD_EVENT_PRESSED;
11298 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
11299 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11302 gi = CreateGadget(GDI_CUSTOM_ID, id,
11303 GDI_INFO_TEXT, gamebutton_info[i].infotext,
11304 GDI_X, DX + gd_xoffset,
11305 GDI_Y, DY + gd_yoffset,
11306 GDI_WIDTH, GAME_BUTTON_XSIZE,
11307 GDI_HEIGHT, GAME_BUTTON_YSIZE,
11308 GDI_TYPE, button_type,
11309 GDI_STATE, GD_BUTTON_UNPRESSED,
11310 GDI_CHECKED, checked,
11311 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
11312 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
11313 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
11314 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
11315 GDI_EVENT_MASK, event_mask,
11316 GDI_CALLBACK_ACTION, HandleGameButtons,
11320 Error(ERR_EXIT, "cannot create gadget");
11322 game_gadget[id] = gi;
11326 void FreeGameButtons()
11330 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11331 FreeGadget(game_gadget[i]);
11334 static void MapGameButtons()
11338 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11339 MapGadget(game_gadget[i]);
11342 void UnmapGameButtons()
11346 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11347 UnmapGadget(game_gadget[i]);
11350 static void HandleGameButtons(struct GadgetInfo *gi)
11352 int id = gi->custom_id;
11354 if (game_status != GAME_MODE_PLAYING)
11359 case GAME_CTRL_ID_STOP:
11360 RequestQuitGame(TRUE);
11363 case GAME_CTRL_ID_PAUSE:
11364 if (options.network)
11366 #if defined(PLATFORM_UNIX)
11368 SendToServer_ContinuePlaying();
11370 SendToServer_PausePlaying();
11374 TapeTogglePause(TAPE_TOGGLE_MANUAL);
11377 case GAME_CTRL_ID_PLAY:
11380 #if defined(PLATFORM_UNIX)
11381 if (options.network)
11382 SendToServer_ContinuePlaying();
11386 tape.pausing = FALSE;
11387 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
11392 case SOUND_CTRL_ID_MUSIC:
11393 if (setup.sound_music)
11395 setup.sound_music = FALSE;
11398 else if (audio.music_available)
11400 setup.sound = setup.sound_music = TRUE;
11402 SetAudioMode(setup.sound);
11408 case SOUND_CTRL_ID_LOOPS:
11409 if (setup.sound_loops)
11410 setup.sound_loops = FALSE;
11411 else if (audio.loops_available)
11413 setup.sound = setup.sound_loops = TRUE;
11414 SetAudioMode(setup.sound);
11418 case SOUND_CTRL_ID_SIMPLE:
11419 if (setup.sound_simple)
11420 setup.sound_simple = FALSE;
11421 else if (audio.sound_available)
11423 setup.sound = setup.sound_simple = TRUE;
11424 SetAudioMode(setup.sound);