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 /* EXPERIMENTAL STUFF */
25 #define USE_NEW_AMOEBA_CODE FALSE
27 /* EXPERIMENTAL STUFF */
28 #define USE_NEW_STUFF ( 1)
30 #define USE_NEW_SP_SLIPPERY (USE_NEW_STUFF * 1)
31 #define USE_NEW_CUSTOM_VALUE (USE_NEW_STUFF * 1)
32 #define USE_NEW_PLAYER_ANIM (USE_NEW_STUFF * 1)
33 #define USE_NEW_ALL_SLIPPERY (USE_NEW_STUFF * 1)
34 #define USE_NEW_PLAYER_SPEED (USE_NEW_STUFF * 1)
35 #define USE_NEW_DELAYED_ACTION (USE_NEW_STUFF * 1)
36 #define USE_NEW_SNAP_DELAY (USE_NEW_STUFF * 1)
37 #define USE_ONLY_ONE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
38 #define USE_ONE_MORE_CHANGE_PER_FRAME (USE_NEW_STUFF * 1)
39 #define USE_QUICKSAND_IMPACT_BUGFIX (USE_NEW_STUFF * 0)
40 #define USE_FIXED_DONT_RUN_INTO (USE_NEW_STUFF * 1)
47 /* for MovePlayer() */
48 #define MF_NO_ACTION 0
52 /* for ScrollPlayer() */
54 #define SCROLL_GO_ON 1
56 /* for Bang()/Explode() */
57 #define EX_PHASE_START 0
58 #define EX_TYPE_NONE 0
59 #define EX_TYPE_NORMAL (1 << 0)
60 #define EX_TYPE_CENTER (1 << 1)
61 #define EX_TYPE_BORDER (1 << 2)
62 #define EX_TYPE_CROSS (1 << 3)
63 #define EX_TYPE_DYNA (1 << 4)
64 #define EX_TYPE_SINGLE_TILE (EX_TYPE_CENTER | EX_TYPE_BORDER)
66 /* special positions in the game control window (relative to control window) */
69 #define XX_EMERALDS 29
70 #define YY_EMERALDS 54
71 #define XX_DYNAMITE 29
72 #define YY_DYNAMITE 89
81 /* special positions in the game control window (relative to main window) */
82 #define DX_LEVEL (DX + XX_LEVEL)
83 #define DY_LEVEL (DY + YY_LEVEL)
84 #define DX_EMERALDS (DX + XX_EMERALDS)
85 #define DY_EMERALDS (DY + YY_EMERALDS)
86 #define DX_DYNAMITE (DX + XX_DYNAMITE)
87 #define DY_DYNAMITE (DY + YY_DYNAMITE)
88 #define DX_KEYS (DX + XX_KEYS)
89 #define DY_KEYS (DY + YY_KEYS)
90 #define DX_SCORE (DX + XX_SCORE)
91 #define DY_SCORE (DY + YY_SCORE)
92 #define DX_TIME1 (DX + XX_TIME1)
93 #define DX_TIME2 (DX + XX_TIME2)
94 #define DY_TIME (DY + YY_TIME)
96 /* values for initial player move delay (initial delay counter value) */
97 #define INITIAL_MOVE_DELAY_OFF -1
98 #define INITIAL_MOVE_DELAY_ON 0
100 /* values for player movement speed (which is in fact a delay value) */
101 #define MOVE_DELAY_MIN_SPEED 32
102 #define MOVE_DELAY_NORMAL_SPEED 8
103 #define MOVE_DELAY_HIGH_SPEED 4
104 #define MOVE_DELAY_MAX_SPEED 1
107 #define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
108 #define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
110 #define DOUBLE_MOVE_DELAY(x) (x = (x < MOVE_DELAY_MIN_SPEED ? x * 2 : x))
111 #define HALVE_MOVE_DELAY(x) (x = (x > MOVE_DELAY_MAX_SPEED ? x / 2 : x))
113 #define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
114 #define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
116 /* values for other actions */
117 #define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
118 #define MOVE_STEPSIZE_MIN (1)
119 #define MOVE_STEPSIZE_MAX (TILEX)
121 #define GET_DX_FROM_DIR(d) ((d) == MV_LEFT ? -1 : (d) == MV_RIGHT ? 1 : 0)
122 #define GET_DY_FROM_DIR(d) ((d) == MV_UP ? -1 : (d) == MV_DOWN ? 1 : 0)
124 #define INIT_GFX_RANDOM() (SimpleRND(1000000))
126 #define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
127 RND(element_info[e].push_delay_random))
128 #define GET_NEW_DROP_DELAY(e) ( (element_info[e].drop_delay_fixed) + \
129 RND(element_info[e].drop_delay_random))
130 #define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
131 RND(element_info[e].move_delay_random))
132 #define GET_MAX_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
133 (element_info[e].move_delay_random))
134 #define GET_NEW_CUSTOM_VALUE(e) ( (element_info[e].ce_value_fixed_initial) +\
135 RND(element_info[e].ce_value_random_initial))
136 #define GET_CHANGE_DELAY(c) ( ((c)->delay_fixed * (c)->delay_frames) + \
137 RND((c)->delay_random * (c)->delay_frames))
138 #define GET_CE_DELAY_VALUE(c) ( ((c)->delay_fixed) + \
139 RND((c)->delay_random))
141 #define GET_TARGET_ELEMENT(e, ch) \
142 ((e) == EL_TRIGGER_ELEMENT ? (ch)->actual_trigger_element : \
143 (e) == EL_TRIGGER_PLAYER ? (ch)->actual_trigger_player : (e))
145 #define CAN_GROW_INTO(e) \
146 ((e) == EL_SAND || (IS_DIGGABLE(e) && level.grow_into_diggable))
148 #define ELEMENT_CAN_ENTER_FIELD_BASE_X(x, y, condition) \
149 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
152 #define ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, condition) \
153 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
154 (CAN_MOVE_INTO_ACID(e) && \
155 Feld[x][y] == EL_ACID) || \
158 #define ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, condition) \
159 (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
160 (CAN_MOVE_INTO_ACID(e) && \
161 Feld[x][y] == EL_ACID) || \
164 #define ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, condition) \
165 (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
167 (CAN_MOVE_INTO_ACID(e) && \
168 Feld[x][y] == EL_ACID) || \
169 (DONT_COLLIDE_WITH(e) && \
171 !PLAYER_ENEMY_PROTECTED(x, y))))
173 #define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
174 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, 0)
176 #define SATELLITE_CAN_ENTER_FIELD(x, y) \
177 ELEMENT_CAN_ENTER_FIELD_BASE_2(EL_SATELLITE, x, y, 0)
179 #define ENEMY_CAN_ENTER_FIELD(e, x, y) \
180 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
182 #define YAMYAM_CAN_ENTER_FIELD(e, x, y) \
183 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, Feld[x][y] == EL_DIAMOND)
185 #define DARK_YAMYAM_CAN_ENTER_FIELD(e, x, y) \
186 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x,y, IS_FOOD_DARK_YAMYAM(Feld[x][y]))
188 #define PACMAN_CAN_ENTER_FIELD(e, x, y) \
189 ELEMENT_CAN_ENTER_FIELD_BASE_3(e, x, y, IS_AMOEBOID(Feld[x][y]))
191 #define PIG_CAN_ENTER_FIELD(e, x, y) \
192 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, IS_FOOD_PIG(Feld[x][y]))
194 #define PENGUIN_CAN_ENTER_FIELD(e, x, y) \
195 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (Feld[x][y] == EL_EXIT_OPEN ||\
196 IS_FOOD_PENGUIN(Feld[x][y])))
197 #define DRAGON_CAN_ENTER_FIELD(e, x, y) \
198 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
200 #define MOLE_CAN_ENTER_FIELD(e, x, y, condition) \
201 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, (condition))
203 #define SPRING_CAN_ENTER_FIELD(e, x, y) \
204 ELEMENT_CAN_ENTER_FIELD_BASE_2(e, x, y, 0)
206 #define SPRING_CAN_BUMP_FROM_FIELD(x, y) \
207 (IN_LEV_FIELD(x, y) && (Feld[x][y] == EL_EMC_SPRING_BUMPER || \
208 Feld[x][y] == EL_EMC_SPRING_BUMPER_ACTIVE))
210 #define GROUP_NR(e) ((e) - EL_GROUP_START)
211 #define MOVE_ENTER_EL(e) (element_info[e].move_enter_element)
212 #define IS_IN_GROUP(e, nr) (element_info[e].in_group[nr] == TRUE)
213 #define IS_IN_GROUP_EL(e, ge) (IS_IN_GROUP(e, (ge) - EL_GROUP_START))
215 #define IS_EQUAL_OR_IN_GROUP(e, ge) \
216 (IS_GROUP_ELEMENT(ge) ? IS_IN_GROUP(e, GROUP_NR(ge)) : (e) == (ge))
218 #define CE_ENTER_FIELD_COND(e, x, y) \
219 (!IS_PLAYER(x, y) && \
220 IS_EQUAL_OR_IN_GROUP(Feld[x][y], MOVE_ENTER_EL(e)))
222 #define CUSTOM_ELEMENT_CAN_ENTER_FIELD(e, x, y) \
223 ELEMENT_CAN_ENTER_FIELD_BASE_4(e, x, y, CE_ENTER_FIELD_COND(e, x, y))
225 #define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
226 #define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
228 #define ACCESS_FROM(e, d) (element_info[e].access_direction &(d))
229 #define IS_WALKABLE_FROM(e, d) (IS_WALKABLE(e) && ACCESS_FROM(e, d))
230 #define IS_PASSABLE_FROM(e, d) (IS_PASSABLE(e) && ACCESS_FROM(e, d))
231 #define IS_ACCESSIBLE_FROM(e, d) (IS_ACCESSIBLE(e) && ACCESS_FROM(e, d))
233 /* game button identifiers */
234 #define GAME_CTRL_ID_STOP 0
235 #define GAME_CTRL_ID_PAUSE 1
236 #define GAME_CTRL_ID_PLAY 2
237 #define SOUND_CTRL_ID_MUSIC 3
238 #define SOUND_CTRL_ID_LOOPS 4
239 #define SOUND_CTRL_ID_SIMPLE 5
241 #define NUM_GAME_BUTTONS 6
244 /* forward declaration for internal use */
246 static void CreateField(int, int, int);
248 static void SetPlayerWaiting(struct PlayerInfo *, boolean);
249 static void AdvanceFrameAndPlayerCounters(int);
251 static boolean MovePlayerOneStep(struct PlayerInfo *, int, int, int, int);
252 static boolean MovePlayer(struct PlayerInfo *, int, int);
253 static void ScrollPlayer(struct PlayerInfo *, int);
254 static void ScrollScreen(struct PlayerInfo *, int);
256 int DigField(struct PlayerInfo *, int, int, int, int, int, int, int);
258 static void InitBeltMovement(void);
259 static void CloseAllOpenTimegates(void);
260 static void CheckGravityMovement(struct PlayerInfo *);
261 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *);
262 static void KillPlayerUnlessEnemyProtected(int, int);
263 static void KillPlayerUnlessExplosionProtected(int, int);
265 static void TestIfPlayerTouchesCustomElement(int, int);
266 static void TestIfElementTouchesCustomElement(int, int);
267 static void TestIfElementHitsCustomElement(int, int, int);
269 static void TestIfElementSmashesCustomElement(int, int, int);
272 static void HandleElementChange(int, int, int);
274 static boolean CheckTriggeredElementChangeExt(int, int, int, int, int,int,int);
275 #define CheckTriggeredElementChange(x, y, e, ev) \
276 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY,CH_SIDE_ANY, -1)
277 #define CheckTriggeredElementChangeByPlayer(x, y, e, ev, p, s) \
278 CheckTriggeredElementChangeExt(x, y, e, ev, p, s, -1)
279 #define CheckTriggeredElementChangeBySide(x, y, e, ev, s) \
280 CheckTriggeredElementChangeExt(x, y, e, ev, CH_PLAYER_ANY, s, -1)
281 #define CheckTriggeredElementChangeByPage(x, y, e, ev, p) \
282 CheckTriggeredElementChangeExt(x,y,e,ev, CH_PLAYER_ANY, CH_SIDE_ANY, p)
284 static boolean CheckElementChangeExt(int, int, int, int, int, int, int);
285 #define CheckElementChange(x, y, e, te, ev) \
286 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, CH_SIDE_ANY)
287 #define CheckElementChangeByPlayer(x, y, e, ev, p, s) \
288 CheckElementChangeExt(x, y, e, EL_EMPTY, ev, p, s)
289 #define CheckElementChangeBySide(x, y, e, te, ev, s) \
290 CheckElementChangeExt(x, y, e, te, ev, CH_PLAYER_ANY, s)
292 static void PlayLevelSound(int, int, int);
293 static void PlayLevelSoundNearest(int, int, int);
294 static void PlayLevelSoundAction(int, int, int);
295 static void PlayLevelSoundElementAction(int, int, int, int);
296 static void PlayLevelSoundElementActionIfLoop(int, int, int, int);
297 static void PlayLevelSoundActionIfLoop(int, int, int);
298 static void StopLevelSoundActionIfLoop(int, int, int);
299 static void PlayLevelMusic();
301 static void MapGameButtons();
302 static void HandleGameButtons(struct GadgetInfo *);
304 static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
307 /* ------------------------------------------------------------------------- */
308 /* definition of elements that automatically change to other elements after */
309 /* a specified time, eventually calling a function when changing */
310 /* ------------------------------------------------------------------------- */
312 /* forward declaration for changer functions */
313 static void InitBuggyBase(int, int);
314 static void WarnBuggyBase(int, int);
316 static void InitTrap(int, int);
317 static void ActivateTrap(int, int);
318 static void ChangeActiveTrap(int, int);
320 static void InitRobotWheel(int, int);
321 static void RunRobotWheel(int, int);
322 static void StopRobotWheel(int, int);
324 static void InitTimegateWheel(int, int);
325 static void RunTimegateWheel(int, int);
327 static void InitMagicBallDelay(int, int);
328 static void ActivateMagicBall(int, int);
330 struct ChangingElementInfo
335 void (*pre_change_function)(int x, int y);
336 void (*change_function)(int x, int y);
337 void (*post_change_function)(int x, int y);
340 static struct ChangingElementInfo change_delay_list[] =
391 EL_SWITCHGATE_OPENING,
399 EL_SWITCHGATE_CLOSING,
400 EL_SWITCHGATE_CLOSED,
432 EL_ACID_SPLASH_RIGHT,
441 EL_SP_BUGGY_BASE_ACTIVATING,
448 EL_SP_BUGGY_BASE_ACTIVATING,
449 EL_SP_BUGGY_BASE_ACTIVE,
456 EL_SP_BUGGY_BASE_ACTIVE,
480 EL_ROBOT_WHEEL_ACTIVE,
488 EL_TIMEGATE_SWITCH_ACTIVE,
496 EL_EMC_MAGIC_BALL_ACTIVE,
497 EL_EMC_MAGIC_BALL_ACTIVE,
504 EL_EMC_SPRING_BUMPER_ACTIVE,
505 EL_EMC_SPRING_BUMPER,
525 int push_delay_fixed, push_delay_random;
530 { EL_BALLOON, 0, 0 },
532 { EL_SOKOBAN_OBJECT, 2, 0 },
533 { EL_SOKOBAN_FIELD_FULL, 2, 0 },
534 { EL_SATELLITE, 2, 0 },
535 { EL_SP_DISK_YELLOW, 2, 0 },
537 { EL_UNDEFINED, 0, 0 },
545 move_stepsize_list[] =
547 { EL_AMOEBA_DROP, 2 },
548 { EL_AMOEBA_DROPPING, 2 },
549 { EL_QUICKSAND_FILLING, 1 },
550 { EL_QUICKSAND_EMPTYING, 1 },
551 { EL_MAGIC_WALL_FILLING, 2 },
552 { EL_BD_MAGIC_WALL_FILLING, 2 },
553 { EL_MAGIC_WALL_EMPTYING, 2 },
554 { EL_BD_MAGIC_WALL_EMPTYING, 2 },
564 collect_count_list[] =
567 { EL_BD_DIAMOND, 1 },
568 { EL_EMERALD_YELLOW, 1 },
569 { EL_EMERALD_RED, 1 },
570 { EL_EMERALD_PURPLE, 1 },
572 { EL_SP_INFOTRON, 1 },
584 access_direction_list[] =
586 { EL_TUBE_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
587 { EL_TUBE_VERTICAL, MV_UP | MV_DOWN },
588 { EL_TUBE_HORIZONTAL, MV_LEFT | MV_RIGHT },
589 { EL_TUBE_VERTICAL_LEFT, MV_LEFT | MV_UP | MV_DOWN },
590 { EL_TUBE_VERTICAL_RIGHT, MV_RIGHT | MV_UP | MV_DOWN },
591 { EL_TUBE_HORIZONTAL_UP, MV_LEFT | MV_RIGHT | MV_UP },
592 { EL_TUBE_HORIZONTAL_DOWN, MV_LEFT | MV_RIGHT | MV_DOWN },
593 { EL_TUBE_LEFT_UP, MV_LEFT | MV_UP },
594 { EL_TUBE_LEFT_DOWN, MV_LEFT | MV_DOWN },
595 { EL_TUBE_RIGHT_UP, MV_RIGHT | MV_UP },
596 { EL_TUBE_RIGHT_DOWN, MV_RIGHT | MV_DOWN },
598 { EL_SP_PORT_LEFT, MV_RIGHT },
599 { EL_SP_PORT_RIGHT, MV_LEFT },
600 { EL_SP_PORT_UP, MV_DOWN },
601 { EL_SP_PORT_DOWN, MV_UP },
602 { EL_SP_PORT_HORIZONTAL, MV_LEFT | MV_RIGHT },
603 { EL_SP_PORT_VERTICAL, MV_UP | MV_DOWN },
604 { EL_SP_PORT_ANY, MV_LEFT | MV_RIGHT | MV_UP | MV_DOWN },
605 { EL_SP_GRAVITY_PORT_LEFT, MV_RIGHT },
606 { EL_SP_GRAVITY_PORT_RIGHT, MV_LEFT },
607 { EL_SP_GRAVITY_PORT_UP, MV_DOWN },
608 { EL_SP_GRAVITY_PORT_DOWN, MV_UP },
609 { EL_SP_GRAVITY_ON_PORT_LEFT, MV_RIGHT },
610 { EL_SP_GRAVITY_ON_PORT_RIGHT, MV_LEFT },
611 { EL_SP_GRAVITY_ON_PORT_UP, MV_DOWN },
612 { EL_SP_GRAVITY_ON_PORT_DOWN, MV_UP },
613 { EL_SP_GRAVITY_OFF_PORT_LEFT, MV_RIGHT },
614 { EL_SP_GRAVITY_OFF_PORT_RIGHT, MV_LEFT },
615 { EL_SP_GRAVITY_OFF_PORT_UP, MV_DOWN },
616 { EL_SP_GRAVITY_OFF_PORT_DOWN, MV_UP },
618 { EL_UNDEFINED, MV_NONE }
621 static boolean trigger_events[MAX_NUM_ELEMENTS][NUM_CHANGE_EVENTS];
623 #define IS_AUTO_CHANGING(e) (element_info[e].has_change_event[CE_DELAY])
624 #define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
625 #define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
626 IS_JUST_CHANGING(x, y))
628 #define CE_PAGE(e, ce) (element_info[e].event_page[ce])
630 /* static variables for playfield scan mode (scanning forward or backward) */
631 static int playfield_scan_start_x = 0;
632 static int playfield_scan_start_y = 0;
633 static int playfield_scan_delta_x = 1;
634 static int playfield_scan_delta_y = 1;
636 #define SCAN_PLAYFIELD(x, y) for ((y) = playfield_scan_start_y; \
637 (y) >= 0 && (y) <= lev_fieldy - 1; \
638 (y) += playfield_scan_delta_y) \
639 for ((x) = playfield_scan_start_x; \
640 (x) >= 0 && (x) <= lev_fieldx - 1; \
641 (x) += playfield_scan_delta_x) \
643 static void InitPlayfieldScanModeVars()
645 if (game.use_reverse_scan_direction)
647 playfield_scan_start_x = lev_fieldx - 1;
648 playfield_scan_start_y = lev_fieldy - 1;
650 playfield_scan_delta_x = -1;
651 playfield_scan_delta_y = -1;
655 playfield_scan_start_x = 0;
656 playfield_scan_start_y = 0;
658 playfield_scan_delta_x = 1;
659 playfield_scan_delta_y = 1;
663 static void InitPlayfieldScanMode(int mode)
665 game.use_reverse_scan_direction =
666 (mode == CA_ARG_SCAN_MODE_REVERSE ? TRUE : FALSE);
668 InitPlayfieldScanModeVars();
671 static int get_move_delay_from_stepsize(int move_stepsize)
674 MIN(MAX(MOVE_STEPSIZE_MIN, move_stepsize), MOVE_STEPSIZE_MAX);
676 /* make sure that stepsize value is always a power of 2 */
677 move_stepsize = (1 << log_2(move_stepsize));
679 return TILEX / move_stepsize;
682 static void SetPlayerMoveSpeed(struct PlayerInfo *player, int move_stepsize,
685 int move_delay = get_move_delay_from_stepsize(move_stepsize);
686 boolean cannot_move = (move_stepsize == STEPSIZE_NOT_MOVING ? TRUE : FALSE);
688 /* do no immediately change move delay -- the player might just be moving */
689 player->move_delay_value_next = move_delay;
691 /* information if player can move must be set separately */
692 player->cannot_move = cannot_move;
696 player->move_delay = game.initial_move_delay;
697 player->move_delay_value = game.initial_move_delay_value;
699 player->move_delay_value_next = -1;
701 player->move_delay_reset_counter = 0;
705 void GetPlayerConfig()
707 if (!audio.sound_available)
708 setup.sound_simple = FALSE;
710 if (!audio.loops_available)
711 setup.sound_loops = FALSE;
713 if (!audio.music_available)
714 setup.sound_music = FALSE;
716 if (!video.fullscreen_available)
717 setup.fullscreen = FALSE;
719 setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
721 SetAudioMode(setup.sound);
725 static int getBeltNrFromBeltElement(int element)
727 return (element < EL_CONVEYOR_BELT_2_LEFT ? 0 :
728 element < EL_CONVEYOR_BELT_3_LEFT ? 1 :
729 element < EL_CONVEYOR_BELT_4_LEFT ? 2 : 3);
732 static int getBeltNrFromBeltActiveElement(int element)
734 return (element < EL_CONVEYOR_BELT_2_LEFT_ACTIVE ? 0 :
735 element < EL_CONVEYOR_BELT_3_LEFT_ACTIVE ? 1 :
736 element < EL_CONVEYOR_BELT_4_LEFT_ACTIVE ? 2 : 3);
739 static int getBeltNrFromBeltSwitchElement(int element)
741 return (element < EL_CONVEYOR_BELT_2_SWITCH_LEFT ? 0 :
742 element < EL_CONVEYOR_BELT_3_SWITCH_LEFT ? 1 :
743 element < EL_CONVEYOR_BELT_4_SWITCH_LEFT ? 2 : 3);
746 static int getBeltDirNrFromBeltSwitchElement(int element)
748 static int belt_base_element[4] =
750 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
751 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
752 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
753 EL_CONVEYOR_BELT_4_SWITCH_LEFT
756 int belt_nr = getBeltNrFromBeltSwitchElement(element);
757 int belt_dir_nr = element - belt_base_element[belt_nr];
759 return (belt_dir_nr % 3);
762 static int getBeltDirFromBeltSwitchElement(int element)
764 static int belt_move_dir[3] =
771 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(element);
773 return belt_move_dir[belt_dir_nr];
776 static void InitPlayerField(int x, int y, int element, boolean init_game)
778 if (element == EL_SP_MURPHY)
782 if (stored_player[0].present)
784 Feld[x][y] = EL_SP_MURPHY_CLONE;
790 stored_player[0].use_murphy = TRUE;
793 Feld[x][y] = EL_PLAYER_1;
799 struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_PLAYER_1];
800 int jx = player->jx, jy = player->jy;
802 player->present = TRUE;
804 player->block_last_field = (element == EL_SP_MURPHY ?
805 level.sp_block_last_field :
806 level.block_last_field);
808 /* ---------- initialize player's last field block delay --------------- */
810 /* always start with reliable default value (no adjustment needed) */
811 player->block_delay_adjustment = 0;
813 /* special case 1: in Supaplex, Murphy blocks last field one more frame */
814 if (player->block_last_field && element == EL_SP_MURPHY)
815 player->block_delay_adjustment = 1;
817 /* special case 2: in game engines before 3.1.1, blocking was different */
818 if (game.use_block_last_field_bug)
819 player->block_delay_adjustment = (player->block_last_field ? -1 : 1);
821 if (!options.network || player->connected)
823 player->active = TRUE;
825 /* remove potentially duplicate players */
826 if (StorePlayer[jx][jy] == Feld[x][y])
827 StorePlayer[jx][jy] = 0;
829 StorePlayer[x][y] = Feld[x][y];
833 printf("Player %d activated.\n", player->element_nr);
834 printf("[Local player is %d and currently %s.]\n",
835 local_player->element_nr,
836 local_player->active ? "active" : "not active");
840 Feld[x][y] = EL_EMPTY;
842 player->jx = player->last_jx = x;
843 player->jy = player->last_jy = y;
847 static void InitField(int x, int y, boolean init_game)
849 int element = Feld[x][y];
858 InitPlayerField(x, y, element, init_game);
861 case EL_SOKOBAN_FIELD_PLAYER:
862 element = Feld[x][y] = EL_PLAYER_1;
863 InitField(x, y, init_game);
865 element = Feld[x][y] = EL_SOKOBAN_FIELD_EMPTY;
866 InitField(x, y, init_game);
869 case EL_SOKOBAN_FIELD_EMPTY:
870 local_player->sokobanfields_still_needed++;
874 if (x < lev_fieldx-1 && Feld[x+1][y] == EL_ACID)
875 Feld[x][y] = EL_ACID_POOL_TOPLEFT;
876 else if (x > 0 && Feld[x-1][y] == EL_ACID)
877 Feld[x][y] = EL_ACID_POOL_TOPRIGHT;
878 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPLEFT)
879 Feld[x][y] = EL_ACID_POOL_BOTTOMLEFT;
880 else if (y > 0 && Feld[x][y-1] == EL_ACID)
881 Feld[x][y] = EL_ACID_POOL_BOTTOM;
882 else if (y > 0 && Feld[x][y-1] == EL_ACID_POOL_TOPRIGHT)
883 Feld[x][y] = EL_ACID_POOL_BOTTOMRIGHT;
891 case EL_SPACESHIP_RIGHT:
892 case EL_SPACESHIP_UP:
893 case EL_SPACESHIP_LEFT:
894 case EL_SPACESHIP_DOWN:
896 case EL_BD_BUTTERFLY_RIGHT:
897 case EL_BD_BUTTERFLY_UP:
898 case EL_BD_BUTTERFLY_LEFT:
899 case EL_BD_BUTTERFLY_DOWN:
900 case EL_BD_BUTTERFLY:
901 case EL_BD_FIREFLY_RIGHT:
902 case EL_BD_FIREFLY_UP:
903 case EL_BD_FIREFLY_LEFT:
904 case EL_BD_FIREFLY_DOWN:
906 case EL_PACMAN_RIGHT:
930 if (y == lev_fieldy - 1)
932 Feld[x][y] = EL_AMOEBA_GROWING;
933 Store[x][y] = EL_AMOEBA_WET;
937 case EL_DYNAMITE_ACTIVE:
938 case EL_SP_DISK_RED_ACTIVE:
939 case EL_DYNABOMB_PLAYER_1_ACTIVE:
940 case EL_DYNABOMB_PLAYER_2_ACTIVE:
941 case EL_DYNABOMB_PLAYER_3_ACTIVE:
942 case EL_DYNABOMB_PLAYER_4_ACTIVE:
947 local_player->lights_still_needed++;
951 local_player->friends_still_needed++;
956 GfxDir[x][y] = MovDir[x][y] = 1 << RND(4);
959 case EL_CONVEYOR_BELT_1_SWITCH_LEFT:
960 case EL_CONVEYOR_BELT_1_SWITCH_MIDDLE:
961 case EL_CONVEYOR_BELT_1_SWITCH_RIGHT:
962 case EL_CONVEYOR_BELT_2_SWITCH_LEFT:
963 case EL_CONVEYOR_BELT_2_SWITCH_MIDDLE:
964 case EL_CONVEYOR_BELT_2_SWITCH_RIGHT:
965 case EL_CONVEYOR_BELT_3_SWITCH_LEFT:
966 case EL_CONVEYOR_BELT_3_SWITCH_MIDDLE:
967 case EL_CONVEYOR_BELT_3_SWITCH_RIGHT:
968 case EL_CONVEYOR_BELT_4_SWITCH_LEFT:
969 case EL_CONVEYOR_BELT_4_SWITCH_MIDDLE:
970 case EL_CONVEYOR_BELT_4_SWITCH_RIGHT:
973 int belt_nr = getBeltNrFromBeltSwitchElement(Feld[x][y]);
974 int belt_dir = getBeltDirFromBeltSwitchElement(Feld[x][y]);
975 int belt_dir_nr = getBeltDirNrFromBeltSwitchElement(Feld[x][y]);
977 if (game.belt_dir_nr[belt_nr] == 3) /* initial value */
979 game.belt_dir[belt_nr] = belt_dir;
980 game.belt_dir_nr[belt_nr] = belt_dir_nr;
982 else /* more than one switch -- set it like the first switch */
984 Feld[x][y] = Feld[x][y] - belt_dir_nr + game.belt_dir_nr[belt_nr];
989 case EL_SWITCHGATE_SWITCH_DOWN: /* always start with same switch pos */
991 Feld[x][y] = EL_SWITCHGATE_SWITCH_UP;
994 case EL_LIGHT_SWITCH_ACTIVE:
996 game.light_time_left = level.time_light * FRAMES_PER_SECOND;
999 case EL_EMC_MAGIC_BALL:
1000 if (game.ball_state)
1001 Feld[x][y] = EL_EMC_MAGIC_BALL_ACTIVE;
1004 case EL_EMC_MAGIC_BALL_SWITCH:
1005 if (game.ball_state)
1006 Feld[x][y] = EL_EMC_MAGIC_BALL_SWITCH_ACTIVE;
1011 if (IS_CUSTOM_ELEMENT(element))
1013 if (CAN_MOVE(element))
1016 #if USE_NEW_CUSTOM_VALUE
1017 if (!element_info[element].use_last_ce_value || init_game)
1018 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
1022 if (IS_CUSTOM_ELEMENT(element) && CAN_MOVE(element))
1025 else if (IS_GROUP_ELEMENT(element))
1027 struct ElementGroupInfo *group = element_info[element].group;
1028 int last_anim_random_frame = gfx.anim_random_frame;
1031 if (group->choice_mode == ANIM_RANDOM)
1032 gfx.anim_random_frame = RND(group->num_elements_resolved);
1034 element_pos = getAnimationFrame(group->num_elements_resolved, 1,
1035 group->choice_mode, 0,
1038 if (group->choice_mode == ANIM_RANDOM)
1039 gfx.anim_random_frame = last_anim_random_frame;
1041 group->choice_pos++;
1043 Feld[x][y] = group->element_resolved[element_pos];
1045 InitField(x, y, init_game);
1052 CheckTriggeredElementChange(x, y, element, CE_CREATION_OF_X);
1057 #if USE_NEW_CUSTOM_VALUE
1060 CustomValue[x][y] = GET_NEW_CUSTOM_VALUE(Feld[x][y]);
1062 CustomValue[x][y] = element_info[Feld[x][y]].custom_value_initial;
1070 static inline void InitField_WithBug1(int x, int y, boolean init_game)
1072 InitField(x, y, init_game);
1074 /* not needed to call InitMovDir() -- already done by InitField()! */
1075 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1076 CAN_MOVE(Feld[x][y]))
1080 static inline void InitField_WithBug2(int x, int y, boolean init_game)
1082 int old_element = Feld[x][y];
1084 InitField(x, y, init_game);
1086 /* not needed to call InitMovDir() -- already done by InitField()! */
1087 if (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1088 CAN_MOVE(old_element) &&
1089 (old_element < EL_MOLE_LEFT || old_element > EL_MOLE_DOWN))
1092 /* this case is in fact a combination of not less than three bugs:
1093 first, it calls InitMovDir() for elements that can move, although this is
1094 already done by InitField(); then, it checks the element that was at this
1095 field _before_ the call to InitField() (which can change it); lastly, it
1096 was not called for "mole with direction" elements, which were treated as
1097 "cannot move" due to (fixed) wrong element initialization in "src/init.c"
1101 inline void DrawGameValue_Emeralds(int value)
1103 DrawText(DX_EMERALDS, DY_EMERALDS, int2str(value, 3), FONT_TEXT_2);
1106 inline void DrawGameValue_Dynamite(int value)
1108 DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(value, 3), FONT_TEXT_2);
1111 inline void DrawGameValue_Keys(int key[MAX_NUM_KEYS])
1115 /* currently only 4 of 8 possible keys are displayed */
1116 for (i = 0; i < STD_NUM_KEYS; i++)
1119 DrawMiniGraphicExt(drawto, DX_KEYS + i * MINI_TILEX, DY_KEYS,
1120 el2edimg(EL_KEY_1 + i));
1122 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
1123 DOOR_GFX_PAGEX5 + XX_KEYS + i * MINI_TILEX, YY_KEYS,
1124 MINI_TILEX, MINI_TILEY, DX_KEYS + i * MINI_TILEX, DY_KEYS);
1128 inline void DrawGameValue_Score(int value)
1130 DrawText(DX_SCORE, DY_SCORE, int2str(value, 5), FONT_TEXT_2);
1133 inline void DrawGameValue_Time(int value)
1136 DrawText(DX_TIME1, DY_TIME, int2str(value, 3), FONT_TEXT_2);
1138 DrawText(DX_TIME2, DY_TIME, int2str(value, 4), FONT_LEVEL_NUMBER);
1141 inline void DrawGameValue_Level(int value)
1144 DrawText(DX_LEVEL, DY_LEVEL, int2str(value, 2), FONT_TEXT_2);
1147 /* misuse area for displaying emeralds to draw bigger level number */
1148 DrawTextExt(drawto, DX_EMERALDS, DY_EMERALDS,
1149 int2str(value, 3), FONT_LEVEL_NUMBER, BLIT_OPAQUE);
1151 /* now copy it to the area for displaying level number */
1152 BlitBitmap(drawto, drawto,
1153 DX_EMERALDS, DY_EMERALDS + 1,
1154 getFontWidth(FONT_LEVEL_NUMBER) * 3,
1155 getFontHeight(FONT_LEVEL_NUMBER) - 1,
1156 DX_LEVEL - 1, DY_LEVEL + 1);
1158 /* restore the area for displaying emeralds */
1159 DrawGameValue_Emeralds(local_player->gems_still_needed);
1161 /* yes, this is all really ugly :-) */
1165 void DrawAllGameValues(int emeralds, int dynamite, int score, int time,
1168 int key[MAX_NUM_KEYS];
1171 for (i = 0; i < MAX_NUM_KEYS; i++)
1172 key[i] = key_bits & (1 << i);
1174 DrawGameValue_Level(level_nr);
1176 DrawGameValue_Emeralds(emeralds);
1177 DrawGameValue_Dynamite(dynamite);
1178 DrawGameValue_Score(score);
1179 DrawGameValue_Time(time);
1181 DrawGameValue_Keys(key);
1184 void DrawGameDoorValues()
1188 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
1190 DrawGameDoorValues_EM();
1195 DrawGameValue_Level(level_nr);
1197 DrawGameValue_Emeralds(local_player->gems_still_needed);
1198 DrawGameValue_Dynamite(local_player->inventory_size);
1199 DrawGameValue_Score(local_player->score);
1200 DrawGameValue_Time(TimeLeft);
1202 for (i = 0; i < MAX_PLAYERS; i++)
1203 DrawGameValue_Keys(stored_player[i].key);
1206 static void resolve_group_element(int group_element, int recursion_depth)
1208 static int group_nr;
1209 static struct ElementGroupInfo *group;
1210 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1213 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1215 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1216 group_element - EL_GROUP_START + 1);
1218 /* replace element which caused too deep recursion by question mark */
1219 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1224 if (recursion_depth == 0) /* initialization */
1226 group = element_info[group_element].group;
1227 group_nr = group_element - EL_GROUP_START;
1229 group->num_elements_resolved = 0;
1230 group->choice_pos = 0;
1233 for (i = 0; i < actual_group->num_elements; i++)
1235 int element = actual_group->element[i];
1237 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1240 if (IS_GROUP_ELEMENT(element))
1241 resolve_group_element(element, recursion_depth + 1);
1244 group->element_resolved[group->num_elements_resolved++] = element;
1245 element_info[element].in_group[group_nr] = TRUE;
1252 =============================================================================
1254 -----------------------------------------------------------------------------
1255 initialize game engine due to level / tape version number
1256 =============================================================================
1259 static void InitGameEngine()
1261 int i, j, k, l, x, y;
1263 /* set game engine from tape file when re-playing, else from level file */
1264 game.engine_version = (tape.playing ? tape.engine_version :
1265 level.game_version);
1267 /* ---------------------------------------------------------------------- */
1268 /* set flags for bugs and changes according to active game engine version */
1269 /* ---------------------------------------------------------------------- */
1272 Summary of bugfix/change:
1273 Fixed handling for custom elements that change when pushed by the player.
1275 Fixed/changed in version:
1279 Before 3.1.0, custom elements that "change when pushing" changed directly
1280 after the player started pushing them (until then handled in "DigField()").
1281 Since 3.1.0, these custom elements are not changed until the "pushing"
1282 move of the element is finished (now handled in "ContinueMoving()").
1284 Affected levels/tapes:
1285 The first condition is generally needed for all levels/tapes before version
1286 3.1.0, which might use the old behaviour before it was changed; known tapes
1287 that are affected are some tapes from the level set "Walpurgis Gardens" by
1289 The second condition is an exception from the above case and is needed for
1290 the special case of tapes recorded with game (not engine!) version 3.1.0 or
1291 above (including some development versions of 3.1.0), but before it was
1292 known that this change would break tapes like the above and was fixed in
1293 3.1.1, so that the changed behaviour was active although the engine version
1294 while recording maybe was before 3.1.0. There is at least one tape that is
1295 affected by this exception, which is the tape for the one-level set "Bug
1296 Machine" by Juergen Bonhagen.
1299 game.use_change_when_pushing_bug =
1300 (game.engine_version < VERSION_IDENT(3,1,0,0) &&
1302 tape.game_version >= VERSION_IDENT(3,1,0,0) &&
1303 tape.game_version < VERSION_IDENT(3,1,1,0)));
1306 Summary of bugfix/change:
1307 Fixed handling for blocking the field the player leaves when moving.
1309 Fixed/changed in version:
1313 Before 3.1.1, when "block last field when moving" was enabled, the field
1314 the player is leaving when moving was blocked for the time of the move,
1315 and was directly unblocked afterwards. This resulted in the last field
1316 being blocked for exactly one less than the number of frames of one player
1317 move. Additionally, even when blocking was disabled, the last field was
1318 blocked for exactly one frame.
1319 Since 3.1.1, due to changes in player movement handling, the last field
1320 is not blocked at all when blocking is disabled. When blocking is enabled,
1321 the last field is blocked for exactly the number of frames of one player
1322 move. Additionally, if the player is Murphy, the hero of Supaplex, the
1323 last field is blocked for exactly one more than the number of frames of
1326 Affected levels/tapes:
1327 (!!! yet to be determined -- probably many !!!)
1330 game.use_block_last_field_bug =
1331 (game.engine_version < VERSION_IDENT(3,1,1,0));
1334 Summary of bugfix/change:
1335 Changed behaviour of CE changes with multiple changes per single frame.
1337 Fixed/changed in version:
1341 Before 3.2.0-6, only one single CE change was allowed in each engine frame.
1342 This resulted in race conditions where CEs seem to behave strange in some
1343 situations (where triggered CE changes were just skipped because there was
1344 already a CE change on that tile in the playfield in that engine frame).
1345 Since 3.2.0-6, this was changed to allow up to MAX_NUM_CHANGES_PER_FRAME.
1346 (The number of changes per frame must be limited in any case, because else
1347 it is easily possible to define CE changes that would result in an infinite
1348 loop, causing the whole game to freeze. The MAX_NUM_CHANGES_PER_FRAME value
1349 should be set large enough so that it would only be reached in cases where
1350 the corresponding CE change conditions run into a loop. Therefore, it seems
1351 to be reasonable to set MAX_NUM_CHANGES_PER_FRAME to the same value as the
1352 maximal number of change pages for custom elements.)
1354 Affected levels/tapes:
1358 #if USE_ONLY_ONE_CHANGE_PER_FRAME
1359 game.max_num_changes_per_frame = 1;
1361 game.max_num_changes_per_frame =
1362 (game.engine_version < VERSION_IDENT(3,2,0,6) ? 1 : 32);
1365 /* ---------------------------------------------------------------------- */
1367 /* default scan direction: scan playfield from top/left to bottom/right */
1368 InitPlayfieldScanMode(CA_ARG_SCAN_MODE_NORMAL);
1370 /* dynamically adjust element properties according to game engine version */
1371 InitElementPropertiesEngine(game.engine_version);
1374 printf("level %d: level version == %06d\n", level_nr, level.game_version);
1375 printf(" tape version == %06d [%s] [file: %06d]\n",
1376 tape.engine_version, (tape.playing ? "PLAYING" : "RECORDING"),
1378 printf(" => game.engine_version == %06d\n", game.engine_version);
1381 /* ---------- recursively resolve group elements ------------------------- */
1383 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1384 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
1385 element_info[i].in_group[j] = FALSE;
1387 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
1388 resolve_group_element(EL_GROUP_START + i, 0);
1390 /* ---------- initialize player's initial move delay --------------------- */
1393 /* dynamically adjust player properties according to level information */
1394 game.initial_move_delay_value =
1395 get_move_delay_from_stepsize(level.initial_player_stepsize);
1397 /* dynamically adjust player properties according to level information */
1398 game.initial_move_delay_value =
1399 (level.double_speed ? MOVE_DELAY_HIGH_SPEED : MOVE_DELAY_NORMAL_SPEED);
1402 /* dynamically adjust player properties according to game engine version */
1403 game.initial_move_delay = (game.engine_version <= VERSION_IDENT(2,0,1,0) ?
1404 game.initial_move_delay_value : 0);
1406 /* ---------- initialize player's initial push delay --------------------- */
1408 /* dynamically adjust player properties according to game engine version */
1409 game.initial_push_delay_value =
1410 (game.engine_version < VERSION_IDENT(3,0,7,1) ? 5 : -1);
1412 /* ---------- initialize changing elements ------------------------------- */
1414 /* initialize changing elements information */
1415 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1417 struct ElementInfo *ei = &element_info[i];
1419 /* this pointer might have been changed in the level editor */
1420 ei->change = &ei->change_page[0];
1422 if (!IS_CUSTOM_ELEMENT(i))
1424 ei->change->target_element = EL_EMPTY_SPACE;
1425 ei->change->delay_fixed = 0;
1426 ei->change->delay_random = 0;
1427 ei->change->delay_frames = 1;
1430 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1432 ei->has_change_event[j] = FALSE;
1434 ei->event_page_nr[j] = 0;
1435 ei->event_page[j] = &ei->change_page[0];
1439 /* add changing elements from pre-defined list */
1440 for (i = 0; change_delay_list[i].element != EL_UNDEFINED; i++)
1442 struct ChangingElementInfo *ch_delay = &change_delay_list[i];
1443 struct ElementInfo *ei = &element_info[ch_delay->element];
1445 ei->change->target_element = ch_delay->target_element;
1446 ei->change->delay_fixed = ch_delay->change_delay;
1448 ei->change->pre_change_function = ch_delay->pre_change_function;
1449 ei->change->change_function = ch_delay->change_function;
1450 ei->change->post_change_function = ch_delay->post_change_function;
1452 ei->change->can_change = TRUE;
1453 ei->change->can_change_or_has_action = TRUE;
1455 ei->has_change_event[CE_DELAY] = TRUE;
1457 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE, TRUE);
1458 SET_PROPERTY(ch_delay->element, EP_CAN_CHANGE_OR_HAS_ACTION, TRUE);
1461 /* ---------- initialize internal run-time variables ------------- */
1463 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1465 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1467 for (j = 0; j < ei->num_change_pages; j++)
1469 ei->change_page[j].can_change_or_has_action =
1470 (ei->change_page[j].can_change |
1471 ei->change_page[j].has_action);
1475 /* add change events from custom element configuration */
1476 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1478 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1480 for (j = 0; j < ei->num_change_pages; j++)
1482 if (!ei->change_page[j].can_change_or_has_action)
1485 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1487 /* only add event page for the first page found with this event */
1488 if (ei->change_page[j].has_event[k] && !(ei->has_change_event[k]))
1490 ei->has_change_event[k] = TRUE;
1492 ei->event_page_nr[k] = j;
1493 ei->event_page[k] = &ei->change_page[j];
1499 /* ---------- initialize run-time trigger player and element ------------- */
1501 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
1503 struct ElementInfo *ei = &element_info[EL_CUSTOM_START + i];
1505 for (j = 0; j < ei->num_change_pages; j++)
1507 ei->change_page[j].actual_trigger_element = EL_EMPTY;
1508 ei->change_page[j].actual_trigger_player = EL_PLAYER_1;
1509 ei->change_page[j].actual_trigger_side = CH_SIDE_NONE;
1510 ei->change_page[j].actual_trigger_ce_value = 0;
1514 /* ---------- initialize trigger events ---------------------------------- */
1516 /* initialize trigger events information */
1517 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1518 for (j = 0; j < NUM_CHANGE_EVENTS; j++)
1519 trigger_events[i][j] = FALSE;
1521 /* add trigger events from element change event properties */
1522 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1524 struct ElementInfo *ei = &element_info[i];
1526 for (j = 0; j < ei->num_change_pages; j++)
1528 if (!ei->change_page[j].can_change_or_has_action)
1531 if (ei->change_page[j].has_event[CE_BY_OTHER_ACTION])
1533 int trigger_element = ei->change_page[j].trigger_element;
1535 for (k = 0; k < NUM_CHANGE_EVENTS; k++)
1537 if (ei->change_page[j].has_event[k])
1539 if (IS_GROUP_ELEMENT(trigger_element))
1541 struct ElementGroupInfo *group =
1542 element_info[trigger_element].group;
1544 for (l = 0; l < group->num_elements_resolved; l++)
1545 trigger_events[group->element_resolved[l]][k] = TRUE;
1548 trigger_events[trigger_element][k] = TRUE;
1555 /* ---------- initialize push delay -------------------------------------- */
1557 /* initialize push delay values to default */
1558 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1560 if (!IS_CUSTOM_ELEMENT(i))
1562 element_info[i].push_delay_fixed = game.default_push_delay_fixed;
1563 element_info[i].push_delay_random = game.default_push_delay_random;
1567 /* set push delay value for certain elements from pre-defined list */
1568 for (i = 0; push_delay_list[i].element != EL_UNDEFINED; i++)
1570 int e = push_delay_list[i].element;
1572 element_info[e].push_delay_fixed = push_delay_list[i].push_delay_fixed;
1573 element_info[e].push_delay_random = push_delay_list[i].push_delay_random;
1576 /* set push delay value for Supaplex elements for newer engine versions */
1577 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
1579 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1581 if (IS_SP_ELEMENT(i))
1583 /* set SP push delay to just enough to push under a falling zonk */
1584 int delay = (game.engine_version >= VERSION_IDENT(3,1,1,0) ? 8 : 6);
1586 element_info[i].push_delay_fixed = delay;
1587 element_info[i].push_delay_random = 0;
1592 /* ---------- initialize move stepsize ----------------------------------- */
1594 /* initialize move stepsize values to default */
1595 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1596 if (!IS_CUSTOM_ELEMENT(i))
1597 element_info[i].move_stepsize = MOVE_STEPSIZE_NORMAL;
1599 /* set move stepsize value for certain elements from pre-defined list */
1600 for (i = 0; move_stepsize_list[i].element != EL_UNDEFINED; i++)
1602 int e = move_stepsize_list[i].element;
1604 element_info[e].move_stepsize = move_stepsize_list[i].move_stepsize;
1607 /* ---------- initialize collect score ----------------------------------- */
1609 /* initialize collect score values for custom elements from initial value */
1610 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1611 if (IS_CUSTOM_ELEMENT(i))
1612 element_info[i].collect_score = element_info[i].collect_score_initial;
1614 /* ---------- initialize collect count ----------------------------------- */
1616 /* initialize collect count values for non-custom elements */
1617 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1618 if (!IS_CUSTOM_ELEMENT(i))
1619 element_info[i].collect_count_initial = 0;
1621 /* add collect count values for all elements from pre-defined list */
1622 for (i = 0; collect_count_list[i].element != EL_UNDEFINED; i++)
1623 element_info[collect_count_list[i].element].collect_count_initial =
1624 collect_count_list[i].count;
1626 /* ---------- initialize access direction -------------------------------- */
1628 /* initialize access direction values to default (access from every side) */
1629 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1630 if (!IS_CUSTOM_ELEMENT(i))
1631 element_info[i].access_direction = MV_ALL_DIRECTIONS;
1633 /* set access direction value for certain elements from pre-defined list */
1634 for (i = 0; access_direction_list[i].element != EL_UNDEFINED; i++)
1635 element_info[access_direction_list[i].element].access_direction =
1636 access_direction_list[i].direction;
1638 /* ---------- initialize explosion content ------------------------------- */
1639 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1641 if (IS_CUSTOM_ELEMENT(i))
1644 for (y = 0; y < 3; y++) for (x = 0; x < 3; x++)
1646 /* (content for EL_YAMYAM set at run-time with game.yamyam_content_nr) */
1648 element_info[i].content.e[x][y] =
1649 (i == EL_PLAYER_1 ? EL_EMERALD_YELLOW :
1650 i == EL_PLAYER_2 ? EL_EMERALD_RED :
1651 i == EL_PLAYER_3 ? EL_EMERALD :
1652 i == EL_PLAYER_4 ? EL_EMERALD_PURPLE :
1653 i == EL_MOLE ? EL_EMERALD_RED :
1654 i == EL_PENGUIN ? EL_EMERALD_PURPLE :
1655 i == EL_BUG ? (x == 1 && y == 1 ? EL_DIAMOND : EL_EMERALD) :
1656 i == EL_BD_BUTTERFLY ? EL_BD_DIAMOND :
1657 i == EL_SP_ELECTRON ? EL_SP_INFOTRON :
1658 i == EL_AMOEBA_TO_DIAMOND ? level.amoeba_content :
1659 i == EL_WALL_EMERALD ? EL_EMERALD :
1660 i == EL_WALL_DIAMOND ? EL_DIAMOND :
1661 i == EL_WALL_BD_DIAMOND ? EL_BD_DIAMOND :
1662 i == EL_WALL_EMERALD_YELLOW ? EL_EMERALD_YELLOW :
1663 i == EL_WALL_EMERALD_RED ? EL_EMERALD_RED :
1664 i == EL_WALL_EMERALD_PURPLE ? EL_EMERALD_PURPLE :
1665 i == EL_WALL_PEARL ? EL_PEARL :
1666 i == EL_WALL_CRYSTAL ? EL_CRYSTAL :
1672 int get_num_special_action(int element, int action_first, int action_last)
1674 int num_special_action = 0;
1677 for (i = action_first; i <= action_last; i++)
1679 boolean found = FALSE;
1681 for (j = 0; j < NUM_DIRECTIONS; j++)
1682 if (el_act_dir2img(element, i, j) !=
1683 el_act_dir2img(element, ACTION_DEFAULT, j))
1687 num_special_action++;
1692 return num_special_action;
1696 =============================================================================
1698 -----------------------------------------------------------------------------
1699 initialize and start new game
1700 =============================================================================
1705 boolean emulate_bd = TRUE; /* unless non-BOULDERDASH elements found */
1706 boolean emulate_sb = TRUE; /* unless non-SOKOBAN elements found */
1707 boolean emulate_sp = TRUE; /* unless non-SUPAPLEX elements found */
1712 /* don't play tapes over network */
1713 network_playing = (options.network && !tape.playing);
1715 for (i = 0; i < MAX_PLAYERS; i++)
1717 struct PlayerInfo *player = &stored_player[i];
1719 player->index_nr = i;
1720 player->index_bit = (1 << i);
1721 player->element_nr = EL_PLAYER_1 + i;
1723 player->present = FALSE;
1724 player->active = FALSE;
1727 player->effective_action = 0;
1728 player->programmed_action = 0;
1731 player->gems_still_needed = level.gems_needed;
1732 player->sokobanfields_still_needed = 0;
1733 player->lights_still_needed = 0;
1734 player->friends_still_needed = 0;
1736 for (j = 0; j < MAX_NUM_KEYS; j++)
1737 player->key[j] = FALSE;
1739 player->dynabomb_count = 0;
1740 player->dynabomb_size = 1;
1741 player->dynabombs_left = 0;
1742 player->dynabomb_xl = FALSE;
1744 player->MovDir = MV_NONE;
1747 player->GfxDir = MV_NONE;
1748 player->GfxAction = ACTION_DEFAULT;
1750 player->StepFrame = 0;
1752 player->use_murphy = FALSE;
1753 player->artwork_element =
1754 (level.use_artwork_element[i] ? level.artwork_element[i] :
1755 player->element_nr);
1757 player->block_last_field = FALSE; /* initialized in InitPlayerField() */
1758 player->block_delay_adjustment = 0; /* initialized in InitPlayerField() */
1760 player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
1762 player->actual_frame_counter = 0;
1764 player->step_counter = 0;
1766 player->last_move_dir = MV_NONE;
1768 player->is_waiting = FALSE;
1769 player->is_moving = FALSE;
1770 player->is_auto_moving = FALSE;
1771 player->is_digging = FALSE;
1772 player->is_snapping = FALSE;
1773 player->is_collecting = FALSE;
1774 player->is_pushing = FALSE;
1775 player->is_switching = FALSE;
1776 player->is_dropping = FALSE;
1778 player->is_bored = FALSE;
1779 player->is_sleeping = FALSE;
1781 player->frame_counter_bored = -1;
1782 player->frame_counter_sleeping = -1;
1784 player->anim_delay_counter = 0;
1785 player->post_delay_counter = 0;
1787 player->action_waiting = ACTION_DEFAULT;
1788 player->last_action_waiting = ACTION_DEFAULT;
1789 player->special_action_bored = ACTION_DEFAULT;
1790 player->special_action_sleeping = ACTION_DEFAULT;
1792 /* set number of special actions for bored and sleeping animation */
1793 player->num_special_action_bored =
1794 get_num_special_action(player->artwork_element,
1795 ACTION_BORING_1, ACTION_BORING_LAST);
1796 player->num_special_action_sleeping =
1797 get_num_special_action(player->artwork_element,
1798 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
1800 player->switch_x = -1;
1801 player->switch_y = -1;
1803 player->drop_x = -1;
1804 player->drop_y = -1;
1806 player->show_envelope = 0;
1809 SetPlayerMoveSpeed(player, level.initial_player_stepsize, TRUE);
1811 player->move_delay = game.initial_move_delay;
1812 player->move_delay_value = game.initial_move_delay_value;
1814 player->move_delay_value_next = -1;
1816 player->move_delay_reset_counter = 0;
1818 player->cannot_move = FALSE;
1821 player->push_delay = -1; /* initialized when pushing starts */
1822 player->push_delay_value = game.initial_push_delay_value;
1824 player->drop_delay = 0;
1826 player->last_jx = player->last_jy = 0;
1827 player->jx = player->jy = 0;
1829 player->shield_normal_time_left = 0;
1830 player->shield_deadly_time_left = 0;
1832 player->inventory_infinite_element = EL_UNDEFINED;
1833 player->inventory_size = 0;
1835 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
1836 SnapField(player, 0, 0);
1838 player->LevelSolved = FALSE;
1839 player->GameOver = FALSE;
1842 network_player_action_received = FALSE;
1844 #if defined(NETWORK_AVALIABLE)
1845 /* initial null action */
1846 if (network_playing)
1847 SendToServer_MovePlayer(MV_NONE);
1856 TimeLeft = level.time;
1859 ScreenMovDir = MV_NONE;
1863 ScrollStepSize = 0; /* will be correctly initialized by ScrollScreen() */
1865 AllPlayersGone = FALSE;
1867 game.yamyam_content_nr = 0;
1868 game.magic_wall_active = FALSE;
1869 game.magic_wall_time_left = 0;
1870 game.light_time_left = 0;
1871 game.timegate_time_left = 0;
1872 game.switchgate_pos = 0;
1873 game.wind_direction = level.wind_direction_initial;
1874 game.gravity = level.initial_gravity;
1875 game.explosions_delayed = TRUE;
1877 game.lenses_time_left = 0;
1878 game.magnify_time_left = 0;
1880 game.ball_state = level.ball_state_initial;
1881 game.ball_content_nr = 0;
1883 game.envelope_active = FALSE;
1885 for (i = 0; i < NUM_BELTS; i++)
1887 game.belt_dir[i] = MV_NONE;
1888 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
1891 for (i = 0; i < MAX_NUM_AMOEBA; i++)
1892 AmoebaCnt[i] = AmoebaCnt2[i] = 0;
1895 SCAN_PLAYFIELD(x, y)
1897 for (x = 0; x < lev_fieldx; x++) for (y = 0; y < lev_fieldy; y++)
1900 Feld[x][y] = level.field[x][y];
1901 MovPos[x][y] = MovDir[x][y] = MovDelay[x][y] = 0;
1902 ChangeDelay[x][y] = 0;
1903 ChangePage[x][y] = -1;
1904 #if USE_NEW_CUSTOM_VALUE
1905 CustomValue[x][y] = 0; /* initialized in InitField() */
1907 Store[x][y] = Store2[x][y] = StorePlayer[x][y] = Back[x][y] = 0;
1909 WasJustMoving[x][y] = 0;
1910 WasJustFalling[x][y] = 0;
1911 CheckCollision[x][y] = 0;
1913 Pushed[x][y] = FALSE;
1915 ChangeCount[x][y] = 0;
1916 ChangeEvent[x][y] = -1;
1918 ExplodePhase[x][y] = 0;
1919 ExplodeDelay[x][y] = 0;
1920 ExplodeField[x][y] = EX_TYPE_NONE;
1922 RunnerVisit[x][y] = 0;
1923 PlayerVisit[x][y] = 0;
1926 GfxRandom[x][y] = INIT_GFX_RANDOM();
1927 GfxElement[x][y] = EL_UNDEFINED;
1928 GfxAction[x][y] = ACTION_DEFAULT;
1929 GfxDir[x][y] = MV_NONE;
1933 SCAN_PLAYFIELD(x, y)
1935 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
1938 if (emulate_bd && !IS_BD_ELEMENT(Feld[x][y]))
1940 if (emulate_sb && !IS_SB_ELEMENT(Feld[x][y]))
1942 if (emulate_sp && !IS_SP_ELEMENT(Feld[x][y]))
1945 InitField(x, y, TRUE);
1950 game.emulation = (emulate_bd ? EMU_BOULDERDASH :
1951 emulate_sb ? EMU_SOKOBAN :
1952 emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
1954 #if USE_NEW_ALL_SLIPPERY
1955 /* initialize type of slippery elements */
1956 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1958 if (!IS_CUSTOM_ELEMENT(i))
1960 /* default: elements slip down either to the left or right randomly */
1961 element_info[i].slippery_type = SLIPPERY_ANY_RANDOM;
1963 /* SP style elements prefer to slip down on the left side */
1964 if (game.engine_version >= VERSION_IDENT(3,1,1,0) && IS_SP_ELEMENT(i))
1965 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
1967 /* BD style elements prefer to slip down on the left side */
1968 if (game.emulation == EMU_BOULDERDASH)
1969 element_info[i].slippery_type = SLIPPERY_ANY_LEFT_RIGHT;
1974 /* initialize explosion and ignition delay */
1975 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1977 if (!IS_CUSTOM_ELEMENT(i))
1980 int delay = (((IS_SP_ELEMENT(i) && i != EL_EMPTY_SPACE) &&
1981 game.engine_version >= VERSION_IDENT(3,1,0,0)) ||
1982 game.emulation == EMU_SUPAPLEX ? 3 : 2);
1983 int last_phase = (num_phase + 1) * delay;
1984 int half_phase = (num_phase / 2) * delay;
1986 element_info[i].explosion_delay = last_phase - 1;
1987 element_info[i].ignition_delay = half_phase;
1989 if (i == EL_BLACK_ORB)
1990 element_info[i].ignition_delay = 1;
1994 if (element_info[i].explosion_delay < 1) /* !!! check again !!! */
1995 element_info[i].explosion_delay = 1;
1997 if (element_info[i].ignition_delay < 1) /* !!! check again !!! */
1998 element_info[i].ignition_delay = 1;
2002 /* correct non-moving belts to start moving left */
2003 for (i = 0; i < NUM_BELTS; i++)
2004 if (game.belt_dir[i] == MV_NONE)
2005 game.belt_dir_nr[i] = 3; /* not moving, next moving left */
2007 /* check if any connected player was not found in playfield */
2008 for (i = 0; i < MAX_PLAYERS; i++)
2010 struct PlayerInfo *player = &stored_player[i];
2012 if (player->connected && !player->present)
2014 for (j = 0; j < MAX_PLAYERS; j++)
2016 struct PlayerInfo *some_player = &stored_player[j];
2017 int jx = some_player->jx, jy = some_player->jy;
2019 /* assign first free player found that is present in the playfield */
2020 if (some_player->present && !some_player->connected)
2022 player->present = TRUE;
2023 player->active = TRUE;
2025 some_player->present = FALSE;
2026 some_player->active = FALSE;
2029 player->element_nr = some_player->element_nr;
2032 player->artwork_element = some_player->artwork_element;
2034 player->block_last_field = some_player->block_last_field;
2035 player->block_delay_adjustment = some_player->block_delay_adjustment;
2037 StorePlayer[jx][jy] = player->element_nr;
2038 player->jx = player->last_jx = jx;
2039 player->jy = player->last_jy = jy;
2049 /* when playing a tape, eliminate all players which do not participate */
2051 for (i = 0; i < MAX_PLAYERS; i++)
2053 if (stored_player[i].active && !tape.player_participates[i])
2055 struct PlayerInfo *player = &stored_player[i];
2056 int jx = player->jx, jy = player->jy;
2058 player->active = FALSE;
2059 StorePlayer[jx][jy] = 0;
2060 Feld[jx][jy] = EL_EMPTY;
2064 else if (!options.network && !setup.team_mode) /* && !tape.playing */
2066 /* when in single player mode, eliminate all but the first active player */
2068 for (i = 0; i < MAX_PLAYERS; i++)
2070 if (stored_player[i].active)
2072 for (j = i + 1; j < MAX_PLAYERS; j++)
2074 if (stored_player[j].active)
2076 struct PlayerInfo *player = &stored_player[j];
2077 int jx = player->jx, jy = player->jy;
2079 player->active = FALSE;
2080 player->present = FALSE;
2082 StorePlayer[jx][jy] = 0;
2083 Feld[jx][jy] = EL_EMPTY;
2090 /* when recording the game, store which players take part in the game */
2093 for (i = 0; i < MAX_PLAYERS; i++)
2094 if (stored_player[i].active)
2095 tape.player_participates[i] = TRUE;
2100 for (i = 0; i < MAX_PLAYERS; i++)
2102 struct PlayerInfo *player = &stored_player[i];
2104 printf("Player %d: present == %d, connected == %d, active == %d.\n",
2109 if (local_player == player)
2110 printf("Player %d is local player.\n", i+1);
2114 if (BorderElement == EL_EMPTY)
2117 SBX_Right = lev_fieldx - SCR_FIELDX;
2119 SBY_Lower = lev_fieldy - SCR_FIELDY;
2124 SBX_Right = lev_fieldx - SCR_FIELDX + 1;
2126 SBY_Lower = lev_fieldy - SCR_FIELDY + 1;
2129 if (lev_fieldx + (SBX_Left == -1 ? 2 : 0) <= SCR_FIELDX)
2130 SBX_Left = SBX_Right = -1 * (SCR_FIELDX - lev_fieldx) / 2;
2132 if (lev_fieldy + (SBY_Upper == -1 ? 2 : 0) <= SCR_FIELDY)
2133 SBY_Upper = SBY_Lower = -1 * (SCR_FIELDY - lev_fieldy) / 2;
2135 /* if local player not found, look for custom element that might create
2136 the player (make some assumptions about the right custom element) */
2137 if (!local_player->present)
2139 int start_x = 0, start_y = 0;
2140 int found_rating = 0;
2141 int found_element = EL_UNDEFINED;
2142 int player_nr = local_player->index_nr;
2145 SCAN_PLAYFIELD(x, y)
2147 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
2150 int element = Feld[x][y];
2155 if (level.use_start_element[player_nr] &&
2156 level.start_element[player_nr] == element &&
2163 found_element = element;
2166 if (!IS_CUSTOM_ELEMENT(element))
2169 if (CAN_CHANGE(element))
2171 for (i = 0; i < element_info[element].num_change_pages; i++)
2173 /* check for player created from custom element as single target */
2174 content = element_info[element].change_page[i].target_element;
2175 is_player = ELEM_IS_PLAYER(content);
2177 if (is_player && (found_rating < 3 || element < found_element))
2183 found_element = element;
2188 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3; xx++)
2190 /* check for player created from custom element as explosion content */
2191 content = element_info[element].content.e[xx][yy];
2192 is_player = ELEM_IS_PLAYER(content);
2194 if (is_player && (found_rating < 2 || element < found_element))
2196 start_x = x + xx - 1;
2197 start_y = y + yy - 1;
2200 found_element = element;
2203 if (!CAN_CHANGE(element))
2206 for (i = 0; i < element_info[element].num_change_pages; i++)
2208 /* check for player created from custom element as extended target */
2210 element_info[element].change_page[i].target_content.e[xx][yy];
2212 is_player = ELEM_IS_PLAYER(content);
2214 if (is_player && (found_rating < 1 || element < found_element))
2216 start_x = x + xx - 1;
2217 start_y = y + yy - 1;
2220 found_element = element;
2226 scroll_x = (start_x < SBX_Left + MIDPOSX ? SBX_Left :
2227 start_x > SBX_Right + MIDPOSX ? SBX_Right :
2230 scroll_y = (start_y < SBY_Upper + MIDPOSY ? SBY_Upper :
2231 start_y > SBY_Lower + MIDPOSY ? SBY_Lower :
2236 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
2237 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
2238 local_player->jx - MIDPOSX);
2240 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
2241 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
2242 local_player->jy - MIDPOSY);
2245 if (!game.restart_level)
2246 CloseDoor(DOOR_CLOSE_1);
2248 /* !!! FIX THIS (START) !!! */
2249 if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
2251 InitGameEngine_EM();
2258 /* after drawing the level, correct some elements */
2259 if (game.timegate_time_left == 0)
2260 CloseAllOpenTimegates();
2262 if (setup.soft_scrolling)
2263 BlitBitmap(fieldbuffer, backbuffer, FX, FY, SXSIZE, SYSIZE, SX, SY);
2265 redraw_mask |= REDRAW_FROM_BACKBUFFER;
2268 /* !!! FIX THIS (END) !!! */
2270 if (!game.restart_level)
2272 /* copy default game door content to main double buffer */
2273 BlitBitmap(graphic_info[IMG_GLOBAL_DOOR].bitmap, drawto,
2274 DOOR_GFX_PAGEX5, DOOR_GFX_PAGEY1, DXSIZE, DYSIZE, DX, DY);
2277 DrawGameDoorValues();
2279 if (!game.restart_level)
2283 game_gadget[SOUND_CTRL_ID_MUSIC]->checked = setup.sound_music;
2284 game_gadget[SOUND_CTRL_ID_LOOPS]->checked = setup.sound_loops;
2285 game_gadget[SOUND_CTRL_ID_SIMPLE]->checked = setup.sound_simple;
2289 /* copy actual game door content to door double buffer for OpenDoor() */
2290 BlitBitmap(drawto, bitmap_db_door,
2291 DX, DY, DXSIZE, DYSIZE, DOOR_GFX_PAGEX1, DOOR_GFX_PAGEY1);
2293 OpenDoor(DOOR_OPEN_ALL);
2295 PlaySoundStereo(SND_GAME_STARTING, SOUND_MIDDLE);
2297 if (setup.sound_music)
2300 KeyboardAutoRepeatOffUnlessAutoplay();
2304 for (i = 0; i < MAX_PLAYERS; i++)
2305 printf("Player %d %sactive.\n",
2306 i + 1, (stored_player[i].active ? "" : "not "));
2310 game.restart_level = FALSE;
2313 void UpdateEngineValues(int actual_scroll_x, int actual_scroll_y)
2315 /* this is used for non-R'n'D game engines to update certain engine values */
2317 /* needed to determine if sounds are played within the visible screen area */
2318 scroll_x = actual_scroll_x;
2319 scroll_y = actual_scroll_y;
2322 void InitMovDir(int x, int y)
2324 int i, element = Feld[x][y];
2325 static int xy[4][2] =
2332 static int direction[3][4] =
2334 { MV_RIGHT, MV_UP, MV_LEFT, MV_DOWN },
2335 { MV_LEFT, MV_DOWN, MV_RIGHT, MV_UP },
2336 { MV_LEFT, MV_RIGHT, MV_UP, MV_DOWN }
2345 Feld[x][y] = EL_BUG;
2346 MovDir[x][y] = direction[0][element - EL_BUG_RIGHT];
2349 case EL_SPACESHIP_RIGHT:
2350 case EL_SPACESHIP_UP:
2351 case EL_SPACESHIP_LEFT:
2352 case EL_SPACESHIP_DOWN:
2353 Feld[x][y] = EL_SPACESHIP;
2354 MovDir[x][y] = direction[0][element - EL_SPACESHIP_RIGHT];
2357 case EL_BD_BUTTERFLY_RIGHT:
2358 case EL_BD_BUTTERFLY_UP:
2359 case EL_BD_BUTTERFLY_LEFT:
2360 case EL_BD_BUTTERFLY_DOWN:
2361 Feld[x][y] = EL_BD_BUTTERFLY;
2362 MovDir[x][y] = direction[0][element - EL_BD_BUTTERFLY_RIGHT];
2365 case EL_BD_FIREFLY_RIGHT:
2366 case EL_BD_FIREFLY_UP:
2367 case EL_BD_FIREFLY_LEFT:
2368 case EL_BD_FIREFLY_DOWN:
2369 Feld[x][y] = EL_BD_FIREFLY;
2370 MovDir[x][y] = direction[0][element - EL_BD_FIREFLY_RIGHT];
2373 case EL_PACMAN_RIGHT:
2375 case EL_PACMAN_LEFT:
2376 case EL_PACMAN_DOWN:
2377 Feld[x][y] = EL_PACMAN;
2378 MovDir[x][y] = direction[0][element - EL_PACMAN_RIGHT];
2381 case EL_SP_SNIKSNAK:
2382 MovDir[x][y] = MV_UP;
2385 case EL_SP_ELECTRON:
2386 MovDir[x][y] = MV_LEFT;
2393 Feld[x][y] = EL_MOLE;
2394 MovDir[x][y] = direction[2][element - EL_MOLE_LEFT];
2398 if (IS_CUSTOM_ELEMENT(element))
2400 struct ElementInfo *ei = &element_info[element];
2401 int move_direction_initial = ei->move_direction_initial;
2402 int move_pattern = ei->move_pattern;
2404 if (move_direction_initial == MV_START_PREVIOUS)
2406 if (MovDir[x][y] != MV_NONE)
2409 move_direction_initial = MV_START_AUTOMATIC;
2412 if (move_direction_initial == MV_START_RANDOM)
2413 MovDir[x][y] = 1 << RND(4);
2414 else if (move_direction_initial & MV_ANY_DIRECTION)
2415 MovDir[x][y] = move_direction_initial;
2416 else if (move_pattern == MV_ALL_DIRECTIONS ||
2417 move_pattern == MV_TURNING_LEFT ||
2418 move_pattern == MV_TURNING_RIGHT ||
2419 move_pattern == MV_TURNING_LEFT_RIGHT ||
2420 move_pattern == MV_TURNING_RIGHT_LEFT ||
2421 move_pattern == MV_TURNING_RANDOM)
2422 MovDir[x][y] = 1 << RND(4);
2423 else if (move_pattern == MV_HORIZONTAL)
2424 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
2425 else if (move_pattern == MV_VERTICAL)
2426 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
2427 else if (move_pattern & MV_ANY_DIRECTION)
2428 MovDir[x][y] = element_info[element].move_pattern;
2429 else if (move_pattern == MV_ALONG_LEFT_SIDE ||
2430 move_pattern == MV_ALONG_RIGHT_SIDE)
2432 /* use random direction as default start direction */
2433 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
2434 MovDir[x][y] = 1 << RND(4);
2436 for (i = 0; i < NUM_DIRECTIONS; i++)
2438 int x1 = x + xy[i][0];
2439 int y1 = y + xy[i][1];
2441 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2443 if (move_pattern == MV_ALONG_RIGHT_SIDE)
2444 MovDir[x][y] = direction[0][i];
2446 MovDir[x][y] = direction[1][i];
2455 MovDir[x][y] = 1 << RND(4);
2457 if (element != EL_BUG &&
2458 element != EL_SPACESHIP &&
2459 element != EL_BD_BUTTERFLY &&
2460 element != EL_BD_FIREFLY)
2463 for (i = 0; i < NUM_DIRECTIONS; i++)
2465 int x1 = x + xy[i][0];
2466 int y1 = y + xy[i][1];
2468 if (!IN_LEV_FIELD(x1, y1) || !IS_FREE(x1, y1))
2470 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
2472 MovDir[x][y] = direction[0][i];
2475 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY ||
2476 element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
2478 MovDir[x][y] = direction[1][i];
2487 GfxDir[x][y] = MovDir[x][y];
2490 void InitAmoebaNr(int x, int y)
2493 int group_nr = AmoebeNachbarNr(x, y);
2497 for (i = 1; i < MAX_NUM_AMOEBA; i++)
2499 if (AmoebaCnt[i] == 0)
2507 AmoebaNr[x][y] = group_nr;
2508 AmoebaCnt[group_nr]++;
2509 AmoebaCnt2[group_nr]++;
2515 boolean raise_level = FALSE;
2517 if (local_player->MovPos)
2520 if (tape.auto_play) /* tape might already be stopped here */
2521 tape.auto_play_level_solved = TRUE;
2523 local_player->LevelSolved = FALSE;
2525 PlaySoundStereo(SND_GAME_WINNING, SOUND_MIDDLE);
2529 if (!tape.playing && setup.sound_loops)
2530 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2531 SND_CTRL_PLAY_LOOP);
2533 while (TimeLeft > 0)
2535 if (!tape.playing && !setup.sound_loops)
2536 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2538 if (TimeLeft > 100 && TimeLeft % 10 == 0)
2541 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2546 RaiseScore(level.score[SC_TIME_BONUS]);
2549 DrawGameValue_Time(TimeLeft);
2557 if (!tape.playing && setup.sound_loops)
2558 StopSound(SND_GAME_LEVELTIME_BONUS);
2560 else if (level.time == 0) /* level without time limit */
2562 if (!tape.playing && setup.sound_loops)
2563 PlaySoundExt(SND_GAME_LEVELTIME_BONUS, SOUND_MAX_VOLUME, SOUND_MIDDLE,
2564 SND_CTRL_PLAY_LOOP);
2566 while (TimePlayed < 999)
2568 if (!tape.playing && !setup.sound_loops)
2569 PlaySoundStereo(SND_GAME_LEVELTIME_BONUS, SOUND_MIDDLE);
2571 if (TimePlayed < 900 && TimePlayed % 10 == 0)
2574 RaiseScore(level.score[SC_TIME_BONUS] * 10);
2579 RaiseScore(level.score[SC_TIME_BONUS]);
2582 DrawGameValue_Time(TimePlayed);
2590 if (!tape.playing && setup.sound_loops)
2591 StopSound(SND_GAME_LEVELTIME_BONUS);
2594 /* close exit door after last player */
2595 if (AllPlayersGone && ExitX >= 0 && ExitY >= 0 &&
2596 (Feld[ExitX][ExitY] == EL_EXIT_OPEN ||
2597 Feld[ExitX][ExitY] == EL_SP_EXIT_OPEN))
2599 int element = Feld[ExitX][ExitY];
2601 Feld[ExitX][ExitY] = (element == EL_EXIT_OPEN ? EL_EXIT_CLOSING :
2602 EL_SP_EXIT_CLOSING);
2604 PlayLevelSoundElementAction(ExitX, ExitY, element, ACTION_CLOSING);
2607 /* player disappears */
2608 if (ExitX >= 0 && ExitY >= 0)
2609 DrawLevelField(ExitX, ExitY);
2616 CloseDoor(DOOR_CLOSE_1);
2621 SaveTape(tape.level_nr); /* Ask to save tape */
2624 if (level_nr == leveldir_current->handicap_level)
2626 leveldir_current->handicap_level++;
2627 SaveLevelSetup_SeriesInfo();
2630 if (level_editor_test_game)
2631 local_player->score = -1; /* no highscore when playing from editor */
2632 else if (level_nr < leveldir_current->last_level)
2633 raise_level = TRUE; /* advance to next level */
2635 if ((hi_pos = NewHiScore()) >= 0)
2637 game_status = GAME_MODE_SCORES;
2638 DrawHallOfFame(hi_pos);
2647 game_status = GAME_MODE_MAIN;
2664 LoadScore(level_nr);
2666 if (strcmp(setup.player_name, EMPTY_PLAYER_NAME) == 0 ||
2667 local_player->score < highscore[MAX_SCORE_ENTRIES - 1].Score)
2670 for (k = 0; k < MAX_SCORE_ENTRIES; k++)
2672 if (local_player->score > highscore[k].Score)
2674 /* player has made it to the hall of fame */
2676 if (k < MAX_SCORE_ENTRIES - 1)
2678 int m = MAX_SCORE_ENTRIES - 1;
2681 for (l = k; l < MAX_SCORE_ENTRIES; l++)
2682 if (!strcmp(setup.player_name, highscore[l].Name))
2684 if (m == k) /* player's new highscore overwrites his old one */
2688 for (l = m; l > k; l--)
2690 strcpy(highscore[l].Name, highscore[l - 1].Name);
2691 highscore[l].Score = highscore[l - 1].Score;
2698 strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN);
2699 highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0';
2700 highscore[k].Score = local_player->score;
2706 else if (!strncmp(setup.player_name, highscore[k].Name,
2707 MAX_PLAYER_NAME_LEN))
2708 break; /* player already there with a higher score */
2714 SaveScore(level_nr);
2719 inline static int getElementMoveStepsize(int x, int y)
2721 int element = Feld[x][y];
2722 int direction = MovDir[x][y];
2723 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2724 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2725 int horiz_move = (dx != 0);
2726 int sign = (horiz_move ? dx : dy);
2727 int step = sign * element_info[element].move_stepsize;
2729 /* special values for move stepsize for spring and things on conveyor belt */
2733 if (element == EL_SPRING)
2734 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2735 else if (CAN_FALL(element) && !CAN_MOVE(element) &&
2736 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2737 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2739 if (CAN_FALL(element) &&
2740 y < lev_fieldy - 1 && IS_BELT_ACTIVE(Feld[x][y + 1]))
2741 step = sign * MOVE_STEPSIZE_NORMAL / 2;
2742 else if (element == EL_SPRING)
2743 step = sign * MOVE_STEPSIZE_NORMAL * 2;
2750 void InitPlayerGfxAnimation(struct PlayerInfo *player, int action, int dir)
2752 if (player->GfxAction != action || player->GfxDir != dir)
2755 printf("Player frame reset! (%d => %d, %d => %d)\n",
2756 player->GfxAction, action, player->GfxDir, dir);
2759 player->GfxAction = action;
2760 player->GfxDir = dir;
2762 player->StepFrame = 0;
2766 static void ResetRandomAnimationValue(int x, int y)
2768 GfxRandom[x][y] = INIT_GFX_RANDOM();
2771 static void ResetGfxAnimation(int x, int y)
2774 GfxAction[x][y] = ACTION_DEFAULT;
2775 GfxDir[x][y] = MovDir[x][y];
2778 void InitMovingField(int x, int y, int direction)
2780 int element = Feld[x][y];
2781 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2782 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2786 if (!WasJustMoving[x][y] || direction != MovDir[x][y])
2787 ResetGfxAnimation(x, y);
2789 MovDir[x][y] = direction;
2790 GfxDir[x][y] = direction;
2791 GfxAction[x][y] = (direction == MV_DOWN && CAN_FALL(element) ?
2792 ACTION_FALLING : ACTION_MOVING);
2794 /* this is needed for CEs with property "can move" / "not moving" */
2796 if (getElementMoveStepsize(x, y) != 0) /* moving or being moved */
2798 if (Feld[newx][newy] == EL_EMPTY)
2799 Feld[newx][newy] = EL_BLOCKED;
2801 MovDir[newx][newy] = MovDir[x][y];
2803 #if USE_NEW_CUSTOM_VALUE
2804 CustomValue[newx][newy] = CustomValue[x][y];
2807 GfxFrame[newx][newy] = GfxFrame[x][y];
2808 GfxRandom[newx][newy] = GfxRandom[x][y];
2809 GfxAction[newx][newy] = GfxAction[x][y];
2810 GfxDir[newx][newy] = GfxDir[x][y];
2814 void Moving2Blocked(int x, int y, int *goes_to_x, int *goes_to_y)
2816 int direction = MovDir[x][y];
2817 int newx = x + (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
2818 int newy = y + (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
2824 void Blocked2Moving(int x, int y, int *comes_from_x, int *comes_from_y)
2826 int oldx = x, oldy = y;
2827 int direction = MovDir[x][y];
2829 if (direction == MV_LEFT)
2831 else if (direction == MV_RIGHT)
2833 else if (direction == MV_UP)
2835 else if (direction == MV_DOWN)
2838 *comes_from_x = oldx;
2839 *comes_from_y = oldy;
2842 int MovingOrBlocked2Element(int x, int y)
2844 int element = Feld[x][y];
2846 if (element == EL_BLOCKED)
2850 Blocked2Moving(x, y, &oldx, &oldy);
2851 return Feld[oldx][oldy];
2857 static int MovingOrBlocked2ElementIfNotLeaving(int x, int y)
2859 /* like MovingOrBlocked2Element(), but if element is moving
2860 and (x,y) is the field the moving element is just leaving,
2861 return EL_BLOCKED instead of the element value */
2862 int element = Feld[x][y];
2864 if (IS_MOVING(x, y))
2866 if (element == EL_BLOCKED)
2870 Blocked2Moving(x, y, &oldx, &oldy);
2871 return Feld[oldx][oldy];
2880 static void RemoveField(int x, int y)
2882 Feld[x][y] = EL_EMPTY;
2888 #if USE_NEW_CUSTOM_VALUE
2889 CustomValue[x][y] = 0;
2893 ChangeDelay[x][y] = 0;
2894 ChangePage[x][y] = -1;
2895 Pushed[x][y] = FALSE;
2898 ExplodeField[x][y] = EX_TYPE_NONE;
2901 GfxElement[x][y] = EL_UNDEFINED;
2902 GfxAction[x][y] = ACTION_DEFAULT;
2903 GfxDir[x][y] = MV_NONE;
2906 void RemoveMovingField(int x, int y)
2908 int oldx = x, oldy = y, newx = x, newy = y;
2909 int element = Feld[x][y];
2910 int next_element = EL_UNDEFINED;
2912 if (element != EL_BLOCKED && !IS_MOVING(x, y))
2915 if (IS_MOVING(x, y))
2917 Moving2Blocked(x, y, &newx, &newy);
2919 if (Feld[newx][newy] != EL_BLOCKED)
2921 /* element is moving, but target field is not free (blocked), but
2922 already occupied by something different (example: acid pool);
2923 in this case, only remove the moving field, but not the target */
2925 RemoveField(oldx, oldy);
2927 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2929 DrawLevelField(oldx, oldy);
2934 else if (element == EL_BLOCKED)
2936 Blocked2Moving(x, y, &oldx, &oldy);
2937 if (!IS_MOVING(oldx, oldy))
2941 if (element == EL_BLOCKED &&
2942 (Feld[oldx][oldy] == EL_QUICKSAND_EMPTYING ||
2943 Feld[oldx][oldy] == EL_MAGIC_WALL_EMPTYING ||
2944 Feld[oldx][oldy] == EL_BD_MAGIC_WALL_EMPTYING ||
2945 Feld[oldx][oldy] == EL_AMOEBA_DROPPING))
2946 next_element = get_next_element(Feld[oldx][oldy]);
2948 RemoveField(oldx, oldy);
2949 RemoveField(newx, newy);
2951 Store[oldx][oldy] = Store2[oldx][oldy] = 0;
2953 if (next_element != EL_UNDEFINED)
2954 Feld[oldx][oldy] = next_element;
2956 DrawLevelField(oldx, oldy);
2957 DrawLevelField(newx, newy);
2960 void DrawDynamite(int x, int y)
2962 int sx = SCREENX(x), sy = SCREENY(y);
2963 int graphic = el2img(Feld[x][y]);
2966 if (!IN_SCR_FIELD(sx, sy) || IS_PLAYER(x, y))
2969 if (IS_WALKABLE_INSIDE(Back[x][y]))
2973 DrawGraphic(sx, sy, el2img(Back[x][y]), 0);
2974 else if (Store[x][y])
2975 DrawGraphic(sx, sy, el2img(Store[x][y]), 0);
2977 frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
2979 if (Back[x][y] || Store[x][y])
2980 DrawGraphicThruMask(sx, sy, graphic, frame);
2982 DrawGraphic(sx, sy, graphic, frame);
2985 void CheckDynamite(int x, int y)
2987 if (MovDelay[x][y] != 0) /* dynamite is still waiting to explode */
2991 if (MovDelay[x][y] != 0)
2994 PlayLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3000 StopLevelSoundActionIfLoop(x, y, ACTION_ACTIVE);
3005 void DrawRelocatePlayer(struct PlayerInfo *player)
3007 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3008 boolean no_delay = (tape.warp_forward);
3009 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3010 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3011 int jx = player->jx;
3012 int jy = player->jy;
3014 if (level.instant_relocation)
3016 int offset = (setup.scroll_delay ? 3 : 0);
3018 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
3020 scroll_x = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3021 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3022 local_player->jx - MIDPOSX);
3024 scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3025 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3026 local_player->jy - MIDPOSY);
3030 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
3031 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
3032 scroll_x = jx - MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
3034 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
3035 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
3036 scroll_y = jy - MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
3038 /* don't scroll over playfield boundaries */
3039 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
3040 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
3042 /* don't scroll over playfield boundaries */
3043 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
3044 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
3047 RedrawPlayfield(TRUE, 0,0,0,0);
3051 int scroll_xx = -999, scroll_yy = -999;
3053 ScrollScreen(NULL, SCROLL_GO_ON); /* scroll last frame to full tile */
3055 while (scroll_xx != scroll_x || scroll_yy != scroll_y)
3058 int fx = FX, fy = FY;
3060 scroll_xx = (local_player->jx < SBX_Left + MIDPOSX ? SBX_Left :
3061 local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
3062 local_player->jx - MIDPOSX);
3064 scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
3065 local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
3066 local_player->jy - MIDPOSY);
3068 dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
3069 dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
3071 if (dx == 0 && dy == 0) /* no scrolling needed at all */
3077 fx += dx * TILEX / 2;
3078 fy += dy * TILEY / 2;
3080 ScrollLevel(dx, dy);
3083 /* scroll in two steps of half tile size to make things smoother */
3084 BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
3086 Delay(wait_delay_value);
3088 /* scroll second step to align at full tile size */
3090 Delay(wait_delay_value);
3095 Delay(wait_delay_value);
3099 void RelocatePlayer(int jx, int jy, int el_player_raw)
3101 int el_player = GET_PLAYER_ELEMENT(el_player_raw);
3102 int player_nr = GET_PLAYER_NR(el_player);
3103 struct PlayerInfo *player = &stored_player[player_nr];
3104 boolean ffwd_delay = (tape.playing && tape.fast_forward);
3105 boolean no_delay = (tape.warp_forward);
3106 int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
3107 int wait_delay_value = (no_delay ? 0 : frame_delay_value);
3108 int old_jx = player->jx;
3109 int old_jy = player->jy;
3110 int old_element = Feld[old_jx][old_jy];
3111 int element = Feld[jx][jy];
3112 boolean player_relocated = (old_jx != jx || old_jy != jy);
3114 int move_dir_horiz = (jx < old_jx ? MV_LEFT : jx > old_jx ? MV_RIGHT : 0);
3115 int move_dir_vert = (jy < old_jy ? MV_UP : jy > old_jy ? MV_DOWN : 0);
3116 int enter_side_horiz = MV_DIR_OPPOSITE(move_dir_horiz);
3117 int enter_side_vert = MV_DIR_OPPOSITE(move_dir_vert);
3118 int leave_side_horiz = move_dir_horiz;
3119 int leave_side_vert = move_dir_vert;
3120 int enter_side = enter_side_horiz | enter_side_vert;
3121 int leave_side = leave_side_horiz | leave_side_vert;
3123 if (player->GameOver) /* do not reanimate dead player */
3126 if (!player_relocated) /* no need to relocate the player */
3129 if (IS_PLAYER(jx, jy)) /* player already placed at new position */
3131 RemoveField(jx, jy); /* temporarily remove newly placed player */
3132 DrawLevelField(jx, jy);
3135 if (player->present)
3137 while (player->MovPos)
3139 ScrollPlayer(player, SCROLL_GO_ON);
3140 ScrollScreen(NULL, SCROLL_GO_ON);
3142 AdvanceFrameAndPlayerCounters(player->index_nr);
3147 Delay(wait_delay_value);
3150 DrawPlayer(player); /* needed here only to cleanup last field */
3151 DrawLevelField(player->jx, player->jy); /* remove player graphic */
3153 player->is_moving = FALSE;
3156 if (IS_CUSTOM_ELEMENT(old_element))
3157 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
3159 player->index_bit, leave_side);
3161 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
3163 player->index_bit, leave_side);
3165 Feld[jx][jy] = el_player;
3166 InitPlayerField(jx, jy, el_player, TRUE);
3168 if (!ELEM_IS_PLAYER(element)) /* player may be set on walkable element */
3170 Feld[jx][jy] = element;
3171 InitField(jx, jy, FALSE);
3174 if (player == local_player) /* only visually relocate local player */
3175 DrawRelocatePlayer(player);
3177 TestIfPlayerTouchesBadThing(jx, jy);
3178 TestIfPlayerTouchesCustomElement(jx, jy);
3180 if (IS_CUSTOM_ELEMENT(element))
3181 CheckElementChangeByPlayer(jx, jy, element, CE_ENTERED_BY_PLAYER,
3182 player->index_bit, enter_side);
3184 CheckTriggeredElementChangeByPlayer(jx, jy, element, CE_PLAYER_ENTERS_X,
3185 player->index_bit, enter_side);
3188 void Explode(int ex, int ey, int phase, int mode)
3194 /* !!! eliminate this variable !!! */
3195 int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
3197 if (game.explosions_delayed)
3199 ExplodeField[ex][ey] = mode;
3203 if (phase == EX_PHASE_START) /* initialize 'Store[][]' field */
3205 int center_element = Feld[ex][ey];
3206 int artwork_element, explosion_element; /* set these values later */
3209 /* --- This is only really needed (and now handled) in "Impact()". --- */
3210 /* do not explode moving elements that left the explode field in time */
3211 if (game.engine_version >= VERSION_IDENT(2,2,0,7) &&
3212 center_element == EL_EMPTY &&
3213 (mode == EX_TYPE_NORMAL || mode == EX_TYPE_CENTER))
3218 /* !!! at this place, the center element may be EL_BLOCKED !!! */
3219 if (mode == EX_TYPE_NORMAL ||
3220 mode == EX_TYPE_CENTER ||
3221 mode == EX_TYPE_CROSS)
3222 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3225 /* remove things displayed in background while burning dynamite */
3226 if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
3229 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
3231 /* put moving element to center field (and let it explode there) */
3232 center_element = MovingOrBlocked2Element(ex, ey);
3233 RemoveMovingField(ex, ey);
3234 Feld[ex][ey] = center_element;
3237 /* now "center_element" is finally determined -- set related values now */
3238 artwork_element = center_element; /* for custom player artwork */
3239 explosion_element = center_element; /* for custom player artwork */
3241 if (IS_PLAYER(ex, ey))
3243 int player_nr = GET_PLAYER_NR(StorePlayer[ex][ey]);
3245 artwork_element = stored_player[player_nr].artwork_element;
3247 if (level.use_explosion_element[player_nr])
3249 explosion_element = level.explosion_element[player_nr];
3250 artwork_element = explosion_element;
3255 if (mode == EX_TYPE_NORMAL ||
3256 mode == EX_TYPE_CENTER ||
3257 mode == EX_TYPE_CROSS)
3258 PlayLevelSoundElementAction(ex, ey, artwork_element, ACTION_EXPLODING);
3262 last_phase = element_info[explosion_element].explosion_delay + 1;
3264 last_phase = element_info[center_element].explosion_delay + 1;
3267 for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
3269 int xx = x - ex + 1;
3270 int yy = y - ey + 1;
3273 if (!IN_LEV_FIELD(x, y) ||
3274 (mode & EX_TYPE_SINGLE_TILE && (x != ex || y != ey)) ||
3275 (mode == EX_TYPE_CROSS && (x != ex && y != ey)))
3278 element = Feld[x][y];
3280 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
3282 element = MovingOrBlocked2Element(x, y);
3284 if (!IS_EXPLOSION_PROOF(element))
3285 RemoveMovingField(x, y);
3288 /* indestructible elements can only explode in center (but not flames) */
3289 if ((IS_EXPLOSION_PROOF(element) && (x != ex || y != ey ||
3290 mode == EX_TYPE_BORDER)) ||
3291 element == EL_FLAMES)
3294 /* no idea why this was changed from 3.0.8 to 3.1.0 -- this causes buggy
3295 behaviour, for example when touching a yamyam that explodes to rocks
3296 with active deadly shield, a rock is created under the player !!! */
3297 /* (case 1 (surely buggy): >= 3.1.0, case 2 (maybe buggy): <= 3.0.8) */
3299 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)) &&
3300 (game.engine_version < VERSION_IDENT(3,1,0,0) ||
3301 (x == ex && y == ey && mode != EX_TYPE_BORDER)))
3303 if (IS_PLAYER(x, y) && SHIELD_ON(PLAYERINFO(x, y)))
3306 if (IS_ACTIVE_BOMB(element))
3308 /* re-activate things under the bomb like gate or penguin */
3309 Feld[x][y] = (Back[x][y] ? Back[x][y] : EL_EMPTY);
3316 /* save walkable background elements while explosion on same tile */
3317 if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element) &&
3318 (x != ex || y != ey || mode == EX_TYPE_BORDER))
3319 Back[x][y] = element;
3321 /* ignite explodable elements reached by other explosion */
3322 if (element == EL_EXPLOSION)
3323 element = Store2[x][y];
3325 if (AmoebaNr[x][y] &&
3326 (element == EL_AMOEBA_FULL ||
3327 element == EL_BD_AMOEBA ||
3328 element == EL_AMOEBA_GROWING))
3330 AmoebaCnt[AmoebaNr[x][y]]--;
3331 AmoebaCnt2[AmoebaNr[x][y]]--;
3336 if (IS_PLAYER(ex, ey) && !PLAYER_EXPLOSION_PROTECTED(ex, ey))
3339 int player_nr = StorePlayer[ex][ey] - EL_PLAYER_1;
3341 Store[x][y] = EL_PLAYER_IS_EXPLODING_1 + player_nr;
3343 switch(StorePlayer[ex][ey])
3346 Store[x][y] = EL_PLAYER_IS_EXPLODING_2;
3349 Store[x][y] = EL_PLAYER_IS_EXPLODING_3;
3352 Store[x][y] = EL_PLAYER_IS_EXPLODING_4;
3356 Store[x][y] = EL_PLAYER_IS_EXPLODING_1;
3361 if (PLAYERINFO(ex, ey)->use_murphy)
3362 Store[x][y] = EL_EMPTY;
3365 /* !!! check this case -- currently needed for rnd_rado_negundo_v,
3366 !!! levels 015 018 019 020 021 022 023 026 027 028 !!! */
3367 else if (ELEM_IS_PLAYER(center_element))
3368 Store[x][y] = EL_EMPTY;
3369 else if (center_element == EL_YAMYAM)
3370 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3371 else if (element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3372 Store[x][y] = element_info[center_element].content.e[xx][yy];
3374 /* needed because EL_BD_BUTTERFLY is not defined as "CAN_EXPLODE"
3375 (killing EL_BD_BUTTERFLY with dynamite would result in BD diamond
3376 otherwise) -- FIX THIS !!! */
3377 else if (!CAN_EXPLODE(element) && element != EL_BD_BUTTERFLY)
3378 Store[x][y] = element_info[element].content.e[1][1];
3380 else if (!CAN_EXPLODE(element))
3381 Store[x][y] = element_info[element].content.e[1][1];
3384 Store[x][y] = EL_EMPTY;
3386 else if (center_element == EL_MOLE)
3387 Store[x][y] = EL_EMERALD_RED;
3388 else if (center_element == EL_PENGUIN)
3389 Store[x][y] = EL_EMERALD_PURPLE;
3390 else if (center_element == EL_BUG)
3391 Store[x][y] = ((x == ex && y == ey) ? EL_DIAMOND : EL_EMERALD);
3392 else if (center_element == EL_BD_BUTTERFLY)
3393 Store[x][y] = EL_BD_DIAMOND;
3394 else if (center_element == EL_SP_ELECTRON)
3395 Store[x][y] = EL_SP_INFOTRON;
3396 else if (center_element == EL_AMOEBA_TO_DIAMOND)
3397 Store[x][y] = level.amoeba_content;
3398 else if (center_element == EL_YAMYAM)
3399 Store[x][y] = level.yamyam_content[game.yamyam_content_nr].e[xx][yy];
3400 else if (IS_CUSTOM_ELEMENT(center_element) &&
3401 element_info[center_element].content.e[xx][yy] != EL_EMPTY)
3402 Store[x][y] = element_info[center_element].content.e[xx][yy];
3403 else if (element == EL_WALL_EMERALD)
3404 Store[x][y] = EL_EMERALD;
3405 else if (element == EL_WALL_DIAMOND)
3406 Store[x][y] = EL_DIAMOND;
3407 else if (element == EL_WALL_BD_DIAMOND)
3408 Store[x][y] = EL_BD_DIAMOND;
3409 else if (element == EL_WALL_EMERALD_YELLOW)
3410 Store[x][y] = EL_EMERALD_YELLOW;
3411 else if (element == EL_WALL_EMERALD_RED)
3412 Store[x][y] = EL_EMERALD_RED;
3413 else if (element == EL_WALL_EMERALD_PURPLE)
3414 Store[x][y] = EL_EMERALD_PURPLE;
3415 else if (element == EL_WALL_PEARL)
3416 Store[x][y] = EL_PEARL;
3417 else if (element == EL_WALL_CRYSTAL)
3418 Store[x][y] = EL_CRYSTAL;
3419 else if (IS_CUSTOM_ELEMENT(element) && !CAN_EXPLODE(element))
3420 Store[x][y] = element_info[element].content.e[1][1];
3422 Store[x][y] = EL_EMPTY;
3425 if (x != ex || y != ey || mode == EX_TYPE_BORDER ||
3426 center_element == EL_AMOEBA_TO_DIAMOND)
3427 Store2[x][y] = element;
3429 Feld[x][y] = EL_EXPLOSION;
3430 GfxElement[x][y] = artwork_element;
3432 ExplodePhase[x][y] = 1;
3433 ExplodeDelay[x][y] = last_phase;
3438 if (center_element == EL_YAMYAM)
3439 game.yamyam_content_nr =
3440 (game.yamyam_content_nr + 1) % level.num_yamyam_contents;
3452 GfxFrame[x][y] = 0; /* restart explosion animation */
3454 last_phase = ExplodeDelay[x][y];
3456 ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
3460 /* activate this even in non-DEBUG version until cause for crash in
3461 getGraphicAnimationFrame() (see below) is found and eliminated */
3466 if (GfxElement[x][y] == EL_UNDEFINED)
3469 printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
3470 printf("Explode(): This should never happen!\n");
3473 GfxElement[x][y] = EL_EMPTY;
3477 border_element = Store2[x][y];
3478 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3479 border_element = StorePlayer[x][y];
3481 if (phase == element_info[border_element].ignition_delay ||
3482 phase == last_phase)
3484 boolean border_explosion = FALSE;
3486 if (IS_PLAYER(x, y) && PLAYERINFO(x, y)->present &&
3487 !PLAYER_EXPLOSION_PROTECTED(x, y))
3489 KillPlayerUnlessExplosionProtected(x, y);
3490 border_explosion = TRUE;
3492 else if (CAN_EXPLODE_BY_EXPLOSION(border_element))
3494 Feld[x][y] = Store2[x][y];
3497 border_explosion = TRUE;
3499 else if (border_element == EL_AMOEBA_TO_DIAMOND)
3501 AmoebeUmwandeln(x, y);
3503 border_explosion = TRUE;
3506 /* if an element just explodes due to another explosion (chain-reaction),
3507 do not immediately end the new explosion when it was the last frame of
3508 the explosion (as it would be done in the following "if"-statement!) */
3509 if (border_explosion && phase == last_phase)
3513 if (phase == last_phase)
3517 element = Feld[x][y] = Store[x][y];
3518 Store[x][y] = Store2[x][y] = 0;
3519 GfxElement[x][y] = EL_UNDEFINED;
3521 /* player can escape from explosions and might therefore be still alive */
3522 if (element >= EL_PLAYER_IS_EXPLODING_1 &&
3523 element <= EL_PLAYER_IS_EXPLODING_4)
3525 int player_nr = element - EL_PLAYER_IS_EXPLODING_1;
3526 int explosion_element = EL_PLAYER_1 + player_nr;
3527 int xx = MIN(MAX(0, x - stored_player[player_nr].jx + 1), 2);
3528 int yy = MIN(MAX(0, y - stored_player[player_nr].jy + 1), 2);
3530 if (level.use_explosion_element[player_nr])
3531 explosion_element = level.explosion_element[player_nr];
3533 Feld[x][y] = (stored_player[player_nr].active ? EL_EMPTY :
3534 element_info[explosion_element].content.e[xx][yy]);
3537 /* restore probably existing indestructible background element */
3538 if (Back[x][y] && IS_INDESTRUCTIBLE(Back[x][y]))
3539 element = Feld[x][y] = Back[x][y];
3542 MovDir[x][y] = MovPos[x][y] = MovDelay[x][y] = 0;
3543 GfxDir[x][y] = MV_NONE;
3544 ChangeDelay[x][y] = 0;
3545 ChangePage[x][y] = -1;
3547 #if USE_NEW_CUSTOM_VALUE
3548 CustomValue[x][y] = 0;
3551 InitField_WithBug2(x, y, FALSE);
3553 DrawLevelField(x, y);
3555 TestIfElementTouchesCustomElement(x, y);
3557 if (GFX_CRUMBLED(element))
3558 DrawLevelFieldCrumbledSandNeighbours(x, y);
3560 if (IS_PLAYER(x, y) && !PLAYERINFO(x, y)->present)
3561 StorePlayer[x][y] = 0;
3563 if (ELEM_IS_PLAYER(element))
3564 RelocatePlayer(x, y, element);
3566 else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
3568 int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);
3569 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
3572 DrawLevelFieldCrumbledSand(x, y);
3574 if (IS_WALKABLE_OVER(Back[x][y]) && Back[x][y] != EL_EMPTY)
3576 DrawLevelElement(x, y, Back[x][y]);
3577 DrawGraphicThruMask(SCREENX(x), SCREENY(y), graphic, frame);
3579 else if (IS_WALKABLE_UNDER(Back[x][y]))
3581 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3582 DrawLevelElementThruMask(x, y, Back[x][y]);
3584 else if (!IS_WALKABLE_INSIDE(Back[x][y]))
3585 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
3589 void DynaExplode(int ex, int ey)
3592 int dynabomb_element = Feld[ex][ey];
3593 int dynabomb_size = 1;
3594 boolean dynabomb_xl = FALSE;
3595 struct PlayerInfo *player;
3596 static int xy[4][2] =
3604 if (IS_ACTIVE_BOMB(dynabomb_element))
3606 player = &stored_player[dynabomb_element - EL_DYNABOMB_PLAYER_1_ACTIVE];
3607 dynabomb_size = player->dynabomb_size;
3608 dynabomb_xl = player->dynabomb_xl;
3609 player->dynabombs_left++;
3612 Explode(ex, ey, EX_PHASE_START, EX_TYPE_CENTER);
3614 for (i = 0; i < NUM_DIRECTIONS; i++)
3616 for (j = 1; j <= dynabomb_size; j++)
3618 int x = ex + j * xy[i][0];
3619 int y = ey + j * xy[i][1];
3622 if (!IN_LEV_FIELD(x, y) || IS_INDESTRUCTIBLE(Feld[x][y]))
3625 element = Feld[x][y];
3627 /* do not restart explosions of fields with active bombs */
3628 if (element == EL_EXPLOSION && IS_ACTIVE_BOMB(Store2[x][y]))
3631 Explode(x, y, EX_PHASE_START, EX_TYPE_BORDER);
3633 if (element != EL_EMPTY && element != EL_EXPLOSION &&
3634 !IS_DIGGABLE(element) && !dynabomb_xl)
3640 void Bang(int x, int y)
3642 int element = MovingOrBlocked2Element(x, y);
3643 int explosion_type = EX_TYPE_NORMAL;
3645 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y))
3647 struct PlayerInfo *player = PLAYERINFO(x, y);
3649 element = Feld[x][y] = (player->use_murphy ? EL_SP_MURPHY :
3650 player->element_nr);
3652 if (level.use_explosion_element[player->index_nr])
3654 int explosion_element = level.explosion_element[player->index_nr];
3656 if (element_info[explosion_element].explosion_type == EXPLODES_CROSS)
3657 explosion_type = EX_TYPE_CROSS;
3658 else if (element_info[explosion_element].explosion_type == EXPLODES_1X1)
3659 explosion_type = EX_TYPE_CENTER;
3667 case EL_BD_BUTTERFLY:
3670 case EL_DARK_YAMYAM:
3674 RaiseScoreElement(element);
3677 case EL_DYNABOMB_PLAYER_1_ACTIVE:
3678 case EL_DYNABOMB_PLAYER_2_ACTIVE:
3679 case EL_DYNABOMB_PLAYER_3_ACTIVE:
3680 case EL_DYNABOMB_PLAYER_4_ACTIVE:
3681 case EL_DYNABOMB_INCREASE_NUMBER:
3682 case EL_DYNABOMB_INCREASE_SIZE:
3683 case EL_DYNABOMB_INCREASE_POWER:
3684 explosion_type = EX_TYPE_DYNA;
3689 case EL_LAMP_ACTIVE:
3690 case EL_AMOEBA_TO_DIAMOND:
3691 if (!IS_PLAYER(x, y)) /* penguin and player may be at same field */
3692 explosion_type = EX_TYPE_CENTER;
3696 if (element_info[element].explosion_type == EXPLODES_CROSS)
3697 explosion_type = EX_TYPE_CROSS;
3698 else if (element_info[element].explosion_type == EXPLODES_1X1)
3699 explosion_type = EX_TYPE_CENTER;
3703 if (explosion_type == EX_TYPE_DYNA)
3706 Explode(x, y, EX_PHASE_START, explosion_type);
3708 CheckTriggeredElementChange(x, y, element, CE_EXPLOSION_OF_X);
3711 void SplashAcid(int x, int y)
3713 if (IN_LEV_FIELD(x - 1, y - 1) && IS_FREE(x - 1, y - 1) &&
3714 (!IN_LEV_FIELD(x - 1, y - 2) ||
3715 !CAN_FALL(MovingOrBlocked2Element(x - 1, y - 2))))
3716 Feld[x - 1][y - 1] = EL_ACID_SPLASH_LEFT;
3718 if (IN_LEV_FIELD(x + 1, y - 1) && IS_FREE(x + 1, y - 1) &&
3719 (!IN_LEV_FIELD(x + 1, y - 2) ||
3720 !CAN_FALL(MovingOrBlocked2Element(x + 1, y - 2))))
3721 Feld[x + 1][y - 1] = EL_ACID_SPLASH_RIGHT;
3723 PlayLevelSound(x, y, SND_ACID_SPLASHING);
3726 static void InitBeltMovement()
3728 static int belt_base_element[4] =
3730 EL_CONVEYOR_BELT_1_LEFT,
3731 EL_CONVEYOR_BELT_2_LEFT,
3732 EL_CONVEYOR_BELT_3_LEFT,
3733 EL_CONVEYOR_BELT_4_LEFT
3735 static int belt_base_active_element[4] =
3737 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3738 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3739 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3740 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3745 /* set frame order for belt animation graphic according to belt direction */
3746 for (i = 0; i < NUM_BELTS; i++)
3750 for (j = 0; j < NUM_BELT_PARTS; j++)
3752 int element = belt_base_active_element[belt_nr] + j;
3753 int graphic = el2img(element);
3755 if (game.belt_dir[i] == MV_LEFT)
3756 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3758 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3763 SCAN_PLAYFIELD(x, y)
3765 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3768 int element = Feld[x][y];
3770 for (i = 0; i < NUM_BELTS; i++)
3772 if (IS_BELT(element) && game.belt_dir[i] != MV_NONE)
3774 int e_belt_nr = getBeltNrFromBeltElement(element);
3777 if (e_belt_nr == belt_nr)
3779 int belt_part = Feld[x][y] - belt_base_element[belt_nr];
3781 Feld[x][y] = belt_base_active_element[belt_nr] + belt_part;
3788 static void ToggleBeltSwitch(int x, int y)
3790 static int belt_base_element[4] =
3792 EL_CONVEYOR_BELT_1_LEFT,
3793 EL_CONVEYOR_BELT_2_LEFT,
3794 EL_CONVEYOR_BELT_3_LEFT,
3795 EL_CONVEYOR_BELT_4_LEFT
3797 static int belt_base_active_element[4] =
3799 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3800 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3801 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3802 EL_CONVEYOR_BELT_4_LEFT_ACTIVE
3804 static int belt_base_switch_element[4] =
3806 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3807 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3808 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3809 EL_CONVEYOR_BELT_4_SWITCH_LEFT
3811 static int belt_move_dir[4] =
3819 int element = Feld[x][y];
3820 int belt_nr = getBeltNrFromBeltSwitchElement(element);
3821 int belt_dir_nr = (game.belt_dir_nr[belt_nr] + 1) % 4;
3822 int belt_dir = belt_move_dir[belt_dir_nr];
3825 if (!IS_BELT_SWITCH(element))
3828 game.belt_dir_nr[belt_nr] = belt_dir_nr;
3829 game.belt_dir[belt_nr] = belt_dir;
3831 if (belt_dir_nr == 3)
3834 /* set frame order for belt animation graphic according to belt direction */
3835 for (i = 0; i < NUM_BELT_PARTS; i++)
3837 int element = belt_base_active_element[belt_nr] + i;
3838 int graphic = el2img(element);
3840 if (belt_dir == MV_LEFT)
3841 graphic_info[graphic].anim_mode &= ~ANIM_REVERSE;
3843 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
3847 SCAN_PLAYFIELD(xx, yy)
3849 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
3852 int element = Feld[xx][yy];
3854 if (IS_BELT_SWITCH(element))
3856 int e_belt_nr = getBeltNrFromBeltSwitchElement(element);
3858 if (e_belt_nr == belt_nr)
3860 Feld[xx][yy] = belt_base_switch_element[belt_nr] + belt_dir_nr;
3861 DrawLevelField(xx, yy);
3864 else if (IS_BELT(element) && belt_dir != MV_NONE)
3866 int e_belt_nr = getBeltNrFromBeltElement(element);
3868 if (e_belt_nr == belt_nr)
3870 int belt_part = Feld[xx][yy] - belt_base_element[belt_nr];
3872 Feld[xx][yy] = belt_base_active_element[belt_nr] + belt_part;
3873 DrawLevelField(xx, yy);
3876 else if (IS_BELT_ACTIVE(element) && belt_dir == MV_NONE)
3878 int e_belt_nr = getBeltNrFromBeltActiveElement(element);
3880 if (e_belt_nr == belt_nr)
3882 int belt_part = Feld[xx][yy] - belt_base_active_element[belt_nr];
3884 Feld[xx][yy] = belt_base_element[belt_nr] + belt_part;
3885 DrawLevelField(xx, yy);
3891 static void ToggleSwitchgateSwitch(int x, int y)
3895 game.switchgate_pos = !game.switchgate_pos;
3898 SCAN_PLAYFIELD(xx, yy)
3900 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
3903 int element = Feld[xx][yy];
3905 if (element == EL_SWITCHGATE_SWITCH_UP ||
3906 element == EL_SWITCHGATE_SWITCH_DOWN)
3908 Feld[xx][yy] = EL_SWITCHGATE_SWITCH_UP + game.switchgate_pos;
3909 DrawLevelField(xx, yy);
3911 else if (element == EL_SWITCHGATE_OPEN ||
3912 element == EL_SWITCHGATE_OPENING)
3914 Feld[xx][yy] = EL_SWITCHGATE_CLOSING;
3916 PlayLevelSoundAction(xx, yy, ACTION_CLOSING);
3918 else if (element == EL_SWITCHGATE_CLOSED ||
3919 element == EL_SWITCHGATE_CLOSING)
3921 Feld[xx][yy] = EL_SWITCHGATE_OPENING;
3923 PlayLevelSoundAction(xx, yy, ACTION_OPENING);
3928 static int getInvisibleActiveFromInvisibleElement(int element)
3930 return (element == EL_INVISIBLE_STEELWALL ? EL_INVISIBLE_STEELWALL_ACTIVE :
3931 element == EL_INVISIBLE_WALL ? EL_INVISIBLE_WALL_ACTIVE :
3932 element == EL_INVISIBLE_SAND ? EL_INVISIBLE_SAND_ACTIVE :
3936 static int getInvisibleFromInvisibleActiveElement(int element)
3938 return (element == EL_INVISIBLE_STEELWALL_ACTIVE ? EL_INVISIBLE_STEELWALL :
3939 element == EL_INVISIBLE_WALL_ACTIVE ? EL_INVISIBLE_WALL :
3940 element == EL_INVISIBLE_SAND_ACTIVE ? EL_INVISIBLE_SAND :
3944 static void RedrawAllLightSwitchesAndInvisibleElements()
3949 SCAN_PLAYFIELD(x, y)
3951 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
3954 int element = Feld[x][y];
3956 if (element == EL_LIGHT_SWITCH &&
3957 game.light_time_left > 0)
3959 Feld[x][y] = EL_LIGHT_SWITCH_ACTIVE;
3960 DrawLevelField(x, y);
3962 else if (element == EL_LIGHT_SWITCH_ACTIVE &&
3963 game.light_time_left == 0)
3965 Feld[x][y] = EL_LIGHT_SWITCH;
3966 DrawLevelField(x, y);
3968 else if (element == EL_EMC_DRIPPER &&
3969 game.light_time_left > 0)
3971 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
3972 DrawLevelField(x, y);
3974 else if (element == EL_EMC_DRIPPER_ACTIVE &&
3975 game.light_time_left == 0)
3977 Feld[x][y] = EL_EMC_DRIPPER;
3978 DrawLevelField(x, y);
3980 else if (element == EL_INVISIBLE_STEELWALL ||
3981 element == EL_INVISIBLE_WALL ||
3982 element == EL_INVISIBLE_SAND)
3984 if (game.light_time_left > 0)
3985 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
3987 DrawLevelField(x, y);
3989 /* uncrumble neighbour fields, if needed */
3990 if (element == EL_INVISIBLE_SAND)
3991 DrawLevelFieldCrumbledSandNeighbours(x, y);
3993 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
3994 element == EL_INVISIBLE_WALL_ACTIVE ||
3995 element == EL_INVISIBLE_SAND_ACTIVE)
3997 if (game.light_time_left == 0)
3998 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4000 DrawLevelField(x, y);
4002 /* re-crumble neighbour fields, if needed */
4003 if (element == EL_INVISIBLE_SAND)
4004 DrawLevelFieldCrumbledSandNeighbours(x, y);
4009 static void RedrawAllInvisibleElementsForLenses()
4014 SCAN_PLAYFIELD(x, y)
4016 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4019 int element = Feld[x][y];
4021 if (element == EL_EMC_DRIPPER &&
4022 game.lenses_time_left > 0)
4024 Feld[x][y] = EL_EMC_DRIPPER_ACTIVE;
4025 DrawLevelField(x, y);
4027 else if (element == EL_EMC_DRIPPER_ACTIVE &&
4028 game.lenses_time_left == 0)
4030 Feld[x][y] = EL_EMC_DRIPPER;
4031 DrawLevelField(x, y);
4033 else if (element == EL_INVISIBLE_STEELWALL ||
4034 element == EL_INVISIBLE_WALL ||
4035 element == EL_INVISIBLE_SAND)
4037 if (game.lenses_time_left > 0)
4038 Feld[x][y] = getInvisibleActiveFromInvisibleElement(element);
4040 DrawLevelField(x, y);
4042 /* uncrumble neighbour fields, if needed */
4043 if (element == EL_INVISIBLE_SAND)
4044 DrawLevelFieldCrumbledSandNeighbours(x, y);
4046 else if (element == EL_INVISIBLE_STEELWALL_ACTIVE ||
4047 element == EL_INVISIBLE_WALL_ACTIVE ||
4048 element == EL_INVISIBLE_SAND_ACTIVE)
4050 if (game.lenses_time_left == 0)
4051 Feld[x][y] = getInvisibleFromInvisibleActiveElement(element);
4053 DrawLevelField(x, y);
4055 /* re-crumble neighbour fields, if needed */
4056 if (element == EL_INVISIBLE_SAND)
4057 DrawLevelFieldCrumbledSandNeighbours(x, y);
4062 static void RedrawAllInvisibleElementsForMagnifier()
4067 SCAN_PLAYFIELD(x, y)
4069 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
4072 int element = Feld[x][y];
4074 if (element == EL_EMC_FAKE_GRASS &&
4075 game.magnify_time_left > 0)
4077 Feld[x][y] = EL_EMC_FAKE_GRASS_ACTIVE;
4078 DrawLevelField(x, y);
4080 else if (element == EL_EMC_FAKE_GRASS_ACTIVE &&
4081 game.magnify_time_left == 0)
4083 Feld[x][y] = EL_EMC_FAKE_GRASS;
4084 DrawLevelField(x, y);
4086 else if (IS_GATE_GRAY(element) &&
4087 game.magnify_time_left > 0)
4089 Feld[x][y] = (IS_RND_GATE_GRAY(element) ?
4090 element - EL_GATE_1_GRAY + EL_GATE_1_GRAY_ACTIVE :
4091 IS_EM_GATE_GRAY(element) ?
4092 element - EL_EM_GATE_1_GRAY + EL_EM_GATE_1_GRAY_ACTIVE :
4093 IS_EMC_GATE_GRAY(element) ?
4094 element - EL_EMC_GATE_5_GRAY + EL_EMC_GATE_5_GRAY_ACTIVE :
4096 DrawLevelField(x, y);
4098 else if (IS_GATE_GRAY_ACTIVE(element) &&
4099 game.magnify_time_left == 0)
4101 Feld[x][y] = (IS_RND_GATE_GRAY_ACTIVE(element) ?
4102 element - EL_GATE_1_GRAY_ACTIVE + EL_GATE_1_GRAY :
4103 IS_EM_GATE_GRAY_ACTIVE(element) ?
4104 element - EL_EM_GATE_1_GRAY_ACTIVE + EL_EM_GATE_1_GRAY :
4105 IS_EMC_GATE_GRAY_ACTIVE(element) ?
4106 element - EL_EMC_GATE_5_GRAY_ACTIVE + EL_EMC_GATE_5_GRAY :
4108 DrawLevelField(x, y);
4113 static void ToggleLightSwitch(int x, int y)
4115 int element = Feld[x][y];
4117 game.light_time_left =
4118 (element == EL_LIGHT_SWITCH ?
4119 level.time_light * FRAMES_PER_SECOND : 0);
4121 RedrawAllLightSwitchesAndInvisibleElements();
4124 static void ActivateTimegateSwitch(int x, int y)
4128 game.timegate_time_left = level.time_timegate * FRAMES_PER_SECOND;
4131 SCAN_PLAYFIELD(xx, yy)
4133 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4136 int element = Feld[xx][yy];
4138 if (element == EL_TIMEGATE_CLOSED ||
4139 element == EL_TIMEGATE_CLOSING)
4141 Feld[xx][yy] = EL_TIMEGATE_OPENING;
4142 PlayLevelSound(xx, yy, SND_TIMEGATE_OPENING);
4146 else if (element == EL_TIMEGATE_SWITCH_ACTIVE)
4148 Feld[xx][yy] = EL_TIMEGATE_SWITCH;
4149 DrawLevelField(xx, yy);
4155 Feld[x][y] = EL_TIMEGATE_SWITCH_ACTIVE;
4158 void Impact(int x, int y)
4160 boolean last_line = (y == lev_fieldy - 1);
4161 boolean object_hit = FALSE;
4162 boolean impact = (last_line || object_hit);
4163 int element = Feld[x][y];
4164 int smashed = EL_STEELWALL;
4166 if (!last_line) /* check if element below was hit */
4168 if (Feld[x][y + 1] == EL_PLAYER_IS_LEAVING)
4171 object_hit = (!IS_FREE(x, y + 1) && (!IS_MOVING(x, y + 1) ||
4172 MovDir[x][y + 1] != MV_DOWN ||
4173 MovPos[x][y + 1] <= TILEY / 2));
4175 /* do not smash moving elements that left the smashed field in time */
4176 if (game.engine_version >= VERSION_IDENT(2,2,0,7) && IS_MOVING(x, y + 1) &&
4177 ABS(MovPos[x][y + 1] + getElementMoveStepsize(x, y + 1)) >= TILEX)
4180 #if USE_QUICKSAND_IMPACT_BUGFIX
4181 if (Feld[x][y + 1] == EL_QUICKSAND_EMPTYING && object_hit == FALSE)
4183 RemoveMovingField(x, y + 1);
4184 Feld[x][y + 1] = EL_QUICKSAND_EMPTY;
4185 Feld[x][y + 2] = EL_ROCK;
4186 DrawLevelField(x, y + 2);
4193 smashed = MovingOrBlocked2Element(x, y + 1);
4195 impact = (last_line || object_hit);
4198 if (!last_line && smashed == EL_ACID) /* element falls into acid */
4200 SplashAcid(x, y + 1);
4204 /* !!! not sufficient for all cases -- see EL_PEARL below !!! */
4205 /* only reset graphic animation if graphic really changes after impact */
4207 el_act_dir2img(element, GfxAction[x][y], MV_DOWN) != el2img(element))
4209 ResetGfxAnimation(x, y);
4210 DrawLevelField(x, y);
4213 if (impact && CAN_EXPLODE_IMPACT(element))
4218 else if (impact && element == EL_PEARL)
4220 ResetGfxAnimation(x, y);
4222 Feld[x][y] = EL_PEARL_BREAKING;
4223 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4226 else if (impact && CheckElementChange(x, y, element, smashed, CE_IMPACT))
4228 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4233 if (impact && element == EL_AMOEBA_DROP)
4235 if (object_hit && IS_PLAYER(x, y + 1))
4236 KillPlayerUnlessEnemyProtected(x, y + 1);
4237 else if (object_hit && smashed == EL_PENGUIN)
4241 Feld[x][y] = EL_AMOEBA_GROWING;
4242 Store[x][y] = EL_AMOEBA_WET;
4244 ResetRandomAnimationValue(x, y);
4249 if (object_hit) /* check which object was hit */
4251 if (CAN_PASS_MAGIC_WALL(element) &&
4252 (smashed == EL_MAGIC_WALL ||
4253 smashed == EL_BD_MAGIC_WALL))
4256 int activated_magic_wall =
4257 (smashed == EL_MAGIC_WALL ? EL_MAGIC_WALL_ACTIVE :
4258 EL_BD_MAGIC_WALL_ACTIVE);
4260 /* activate magic wall / mill */
4262 SCAN_PLAYFIELD(xx, yy)
4264 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
4266 if (Feld[xx][yy] == smashed)
4267 Feld[xx][yy] = activated_magic_wall;
4269 game.magic_wall_time_left = level.time_magic_wall * FRAMES_PER_SECOND;
4270 game.magic_wall_active = TRUE;
4272 PlayLevelSound(x, y, (smashed == EL_MAGIC_WALL ?
4273 SND_MAGIC_WALL_ACTIVATING :
4274 SND_BD_MAGIC_WALL_ACTIVATING));
4277 if (IS_PLAYER(x, y + 1))
4279 if (CAN_SMASH_PLAYER(element))
4281 KillPlayerUnlessEnemyProtected(x, y + 1);
4285 else if (smashed == EL_PENGUIN)
4287 if (CAN_SMASH_PLAYER(element))
4293 else if (element == EL_BD_DIAMOND)
4295 if (IS_CLASSIC_ENEMY(smashed) && IS_BD_ELEMENT(smashed))
4301 else if (((element == EL_SP_INFOTRON ||
4302 element == EL_SP_ZONK) &&
4303 (smashed == EL_SP_SNIKSNAK ||
4304 smashed == EL_SP_ELECTRON ||
4305 smashed == EL_SP_DISK_ORANGE)) ||
4306 (element == EL_SP_INFOTRON &&
4307 smashed == EL_SP_DISK_YELLOW))
4312 else if (CAN_SMASH_EVERYTHING(element))
4314 if (IS_CLASSIC_ENEMY(smashed) ||
4315 CAN_EXPLODE_SMASHED(smashed))
4320 else if (!IS_MOVING(x, y + 1) && !IS_BLOCKED(x, y + 1))
4322 if (smashed == EL_LAMP ||
4323 smashed == EL_LAMP_ACTIVE)
4328 else if (smashed == EL_NUT)
4330 Feld[x][y + 1] = EL_NUT_BREAKING;
4331 PlayLevelSound(x, y, SND_NUT_BREAKING);
4332 RaiseScoreElement(EL_NUT);
4335 else if (smashed == EL_PEARL)
4337 ResetGfxAnimation(x, y);
4339 Feld[x][y + 1] = EL_PEARL_BREAKING;
4340 PlayLevelSound(x, y, SND_PEARL_BREAKING);
4343 else if (smashed == EL_DIAMOND)
4345 Feld[x][y + 1] = EL_DIAMOND_BREAKING;
4346 PlayLevelSound(x, y, SND_DIAMOND_BREAKING);
4349 else if (IS_BELT_SWITCH(smashed))
4351 ToggleBeltSwitch(x, y + 1);
4353 else if (smashed == EL_SWITCHGATE_SWITCH_UP ||
4354 smashed == EL_SWITCHGATE_SWITCH_DOWN)
4356 ToggleSwitchgateSwitch(x, y + 1);
4358 else if (smashed == EL_LIGHT_SWITCH ||
4359 smashed == EL_LIGHT_SWITCH_ACTIVE)
4361 ToggleLightSwitch(x, y + 1);
4366 TestIfElementSmashesCustomElement(x, y, MV_DOWN);
4369 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4371 CheckElementChangeBySide(x, y + 1, smashed, element,
4372 CE_SWITCHED, CH_SIDE_TOP);
4373 CheckTriggeredElementChangeBySide(x, y + 1, smashed, CE_SWITCH_OF_X,
4379 CheckElementChange(x, y + 1, smashed, element, CE_SMASHED);
4384 /* play sound of magic wall / mill */
4386 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
4387 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
4389 if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
4390 PlayLevelSound(x, y, SND_MAGIC_WALL_FILLING);
4391 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
4392 PlayLevelSound(x, y, SND_BD_MAGIC_WALL_FILLING);
4397 /* play sound of object that hits the ground */
4398 if (last_line || object_hit)
4399 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
4402 inline static void TurnRoundExt(int x, int y)
4414 { 0, 0 }, { 0, 0 }, { 0, 0 },
4419 int left, right, back;
4423 { MV_DOWN, MV_UP, MV_RIGHT },
4424 { MV_UP, MV_DOWN, MV_LEFT },
4426 { MV_LEFT, MV_RIGHT, MV_DOWN },
4430 { MV_RIGHT, MV_LEFT, MV_UP }
4433 int element = Feld[x][y];
4434 int move_pattern = element_info[element].move_pattern;
4436 int old_move_dir = MovDir[x][y];
4437 int left_dir = turn[old_move_dir].left;
4438 int right_dir = turn[old_move_dir].right;
4439 int back_dir = turn[old_move_dir].back;
4441 int left_dx = move_xy[left_dir].dx, left_dy = move_xy[left_dir].dy;
4442 int right_dx = move_xy[right_dir].dx, right_dy = move_xy[right_dir].dy;
4443 int move_dx = move_xy[old_move_dir].dx, move_dy = move_xy[old_move_dir].dy;
4444 int back_dx = move_xy[back_dir].dx, back_dy = move_xy[back_dir].dy;
4446 int left_x = x + left_dx, left_y = y + left_dy;
4447 int right_x = x + right_dx, right_y = y + right_dy;
4448 int move_x = x + move_dx, move_y = y + move_dy;
4452 if (element == EL_BUG || element == EL_BD_BUTTERFLY)
4454 TestIfBadThingTouchesOtherBadThing(x, y);
4456 if (ENEMY_CAN_ENTER_FIELD(element, right_x, right_y))
4457 MovDir[x][y] = right_dir;
4458 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4459 MovDir[x][y] = left_dir;
4461 if (element == EL_BUG && MovDir[x][y] != old_move_dir)
4463 else if (element == EL_BD_BUTTERFLY) /* && MovDir[x][y] == left_dir) */
4466 else if (element == EL_SPACESHIP || element == EL_BD_FIREFLY)
4468 TestIfBadThingTouchesOtherBadThing(x, y);
4470 if (ENEMY_CAN_ENTER_FIELD(element, left_x, left_y))
4471 MovDir[x][y] = left_dir;
4472 else if (!ENEMY_CAN_ENTER_FIELD(element, move_x, move_y))
4473 MovDir[x][y] = right_dir;
4475 if (element == EL_SPACESHIP && MovDir[x][y] != old_move_dir)
4477 else if (element == EL_BD_FIREFLY) /* && MovDir[x][y] == right_dir) */
4480 else if (element == EL_SP_SNIKSNAK || element == EL_SP_ELECTRON)
4482 TestIfBadThingTouchesOtherBadThing(x, y);
4484 if (ELEMENT_CAN_ENTER_FIELD_BASE_4(element, left_x, left_y, 0))
4485 MovDir[x][y] = left_dir;
4486 else if (!ELEMENT_CAN_ENTER_FIELD_BASE_4(element, move_x, move_y, 0))
4487 MovDir[x][y] = right_dir;
4489 if (MovDir[x][y] != old_move_dir)
4492 else if (element == EL_YAMYAM)
4494 boolean can_turn_left = YAMYAM_CAN_ENTER_FIELD(element, left_x, left_y);
4495 boolean can_turn_right = YAMYAM_CAN_ENTER_FIELD(element, right_x, right_y);
4497 if (can_turn_left && can_turn_right)
4498 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4499 else if (can_turn_left)
4500 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4501 else if (can_turn_right)
4502 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4504 MovDir[x][y] = back_dir;
4506 MovDelay[x][y] = 16 + 16 * RND(3);
4508 else if (element == EL_DARK_YAMYAM)
4510 boolean can_turn_left = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4512 boolean can_turn_right = DARK_YAMYAM_CAN_ENTER_FIELD(element,
4515 if (can_turn_left && can_turn_right)
4516 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4517 else if (can_turn_left)
4518 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4519 else if (can_turn_right)
4520 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4522 MovDir[x][y] = back_dir;
4524 MovDelay[x][y] = 16 + 16 * RND(3);
4526 else if (element == EL_PACMAN)
4528 boolean can_turn_left = PACMAN_CAN_ENTER_FIELD(element, left_x, left_y);
4529 boolean can_turn_right = PACMAN_CAN_ENTER_FIELD(element, right_x, right_y);
4531 if (can_turn_left && can_turn_right)
4532 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4533 else if (can_turn_left)
4534 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4535 else if (can_turn_right)
4536 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4538 MovDir[x][y] = back_dir;
4540 MovDelay[x][y] = 6 + RND(40);
4542 else if (element == EL_PIG)
4544 boolean can_turn_left = PIG_CAN_ENTER_FIELD(element, left_x, left_y);
4545 boolean can_turn_right = PIG_CAN_ENTER_FIELD(element, right_x, right_y);
4546 boolean can_move_on = PIG_CAN_ENTER_FIELD(element, move_x, move_y);
4547 boolean should_turn_left, should_turn_right, should_move_on;
4549 int rnd = RND(rnd_value);
4551 should_turn_left = (can_turn_left &&
4553 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + left_dx,
4554 y + back_dy + left_dy)));
4555 should_turn_right = (can_turn_right &&
4557 IN_LEV_FIELD_AND_NOT_FREE(x + back_dx + right_dx,
4558 y + back_dy + right_dy)));
4559 should_move_on = (can_move_on &&
4562 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + left_dx,
4563 y + move_dy + left_dy) ||
4564 IN_LEV_FIELD_AND_NOT_FREE(x + move_dx + right_dx,
4565 y + move_dy + right_dy)));
4567 if (should_turn_left || should_turn_right || should_move_on)
4569 if (should_turn_left && should_turn_right && should_move_on)
4570 MovDir[x][y] = (rnd < rnd_value / 3 ? left_dir :
4571 rnd < 2 * rnd_value / 3 ? right_dir :
4573 else if (should_turn_left && should_turn_right)
4574 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4575 else if (should_turn_left && should_move_on)
4576 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : old_move_dir);
4577 else if (should_turn_right && should_move_on)
4578 MovDir[x][y] = (rnd < rnd_value / 2 ? right_dir : old_move_dir);
4579 else if (should_turn_left)
4580 MovDir[x][y] = left_dir;
4581 else if (should_turn_right)
4582 MovDir[x][y] = right_dir;
4583 else if (should_move_on)
4584 MovDir[x][y] = old_move_dir;
4586 else if (can_move_on && rnd > rnd_value / 8)
4587 MovDir[x][y] = old_move_dir;
4588 else if (can_turn_left && can_turn_right)
4589 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4590 else if (can_turn_left && rnd > rnd_value / 8)
4591 MovDir[x][y] = left_dir;
4592 else if (can_turn_right && rnd > rnd_value/8)
4593 MovDir[x][y] = right_dir;
4595 MovDir[x][y] = back_dir;
4597 xx = x + move_xy[MovDir[x][y]].dx;
4598 yy = y + move_xy[MovDir[x][y]].dy;
4600 if (!IN_LEV_FIELD(xx, yy) ||
4601 (!IS_FREE(xx, yy) && !IS_FOOD_PIG(Feld[xx][yy])))
4602 MovDir[x][y] = old_move_dir;
4606 else if (element == EL_DRAGON)
4608 boolean can_turn_left = DRAGON_CAN_ENTER_FIELD(element, left_x, left_y);
4609 boolean can_turn_right = DRAGON_CAN_ENTER_FIELD(element, right_x, right_y);
4610 boolean can_move_on = DRAGON_CAN_ENTER_FIELD(element, move_x, move_y);
4612 int rnd = RND(rnd_value);
4614 if (can_move_on && rnd > rnd_value / 8)
4615 MovDir[x][y] = old_move_dir;
4616 else if (can_turn_left && can_turn_right)
4617 MovDir[x][y] = (rnd < rnd_value / 2 ? left_dir : right_dir);
4618 else if (can_turn_left && rnd > rnd_value / 8)
4619 MovDir[x][y] = left_dir;
4620 else if (can_turn_right && rnd > rnd_value / 8)
4621 MovDir[x][y] = right_dir;
4623 MovDir[x][y] = back_dir;
4625 xx = x + move_xy[MovDir[x][y]].dx;
4626 yy = y + move_xy[MovDir[x][y]].dy;
4628 if (!IN_LEV_FIELD_AND_IS_FREE(xx, yy))
4629 MovDir[x][y] = old_move_dir;
4633 else if (element == EL_MOLE)
4635 boolean can_move_on =
4636 (MOLE_CAN_ENTER_FIELD(element, move_x, move_y,
4637 IS_AMOEBOID(Feld[move_x][move_y]) ||
4638 Feld[move_x][move_y] == EL_AMOEBA_SHRINKING));
4641 boolean can_turn_left =
4642 (MOLE_CAN_ENTER_FIELD(element, left_x, left_y,
4643 IS_AMOEBOID(Feld[left_x][left_y])));
4645 boolean can_turn_right =
4646 (MOLE_CAN_ENTER_FIELD(element, right_x, right_y,
4647 IS_AMOEBOID(Feld[right_x][right_y])));
4649 if (can_turn_left && can_turn_right)
4650 MovDir[x][y] = (RND(2) ? left_dir : right_dir);
4651 else if (can_turn_left)
4652 MovDir[x][y] = left_dir;
4654 MovDir[x][y] = right_dir;
4657 if (MovDir[x][y] != old_move_dir)
4660 else if (element == EL_BALLOON)
4662 MovDir[x][y] = game.wind_direction;
4665 else if (element == EL_SPRING)
4668 if (MovDir[x][y] & MV_HORIZONTAL)
4670 if (SPRING_CAN_BUMP_FROM_FIELD(move_x, move_y) &&
4671 !SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4673 Feld[move_x][move_y] = EL_EMC_SPRING_BUMPER_ACTIVE;
4674 ResetGfxAnimation(move_x, move_y);
4675 DrawLevelField(move_x, move_y);
4677 MovDir[x][y] = back_dir;
4679 else if (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4680 SPRING_CAN_ENTER_FIELD(element, x, y + 1))
4681 MovDir[x][y] = MV_NONE;
4684 if (MovDir[x][y] & MV_HORIZONTAL &&
4685 (!SPRING_CAN_ENTER_FIELD(element, move_x, move_y) ||
4686 SPRING_CAN_ENTER_FIELD(element, x, y + 1)))
4687 MovDir[x][y] = MV_NONE;
4692 else if (element == EL_ROBOT ||
4693 element == EL_SATELLITE ||
4694 element == EL_PENGUIN)
4696 int attr_x = -1, attr_y = -1;
4707 for (i = 0; i < MAX_PLAYERS; i++)
4709 struct PlayerInfo *player = &stored_player[i];
4710 int jx = player->jx, jy = player->jy;
4712 if (!player->active)
4716 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4724 if (element == EL_ROBOT && ZX >= 0 && ZY >= 0 &&
4725 (Feld[ZX][ZY] == EL_ROBOT_WHEEL_ACTIVE ||
4726 game.engine_version < VERSION_IDENT(3,1,0,0)))
4732 if (element == EL_PENGUIN)
4735 static int xy[4][2] =
4743 for (i = 0; i < NUM_DIRECTIONS; i++)
4745 int ex = x + xy[i][0];
4746 int ey = y + xy[i][1];
4748 if (IN_LEV_FIELD(ex, ey) && Feld[ex][ey] == EL_EXIT_OPEN)
4757 MovDir[x][y] = MV_NONE;
4759 MovDir[x][y] |= (AllPlayersGone ? MV_RIGHT : MV_LEFT);
4760 else if (attr_x > x)
4761 MovDir[x][y] |= (AllPlayersGone ? MV_LEFT : MV_RIGHT);
4763 MovDir[x][y] |= (AllPlayersGone ? MV_DOWN : MV_UP);
4764 else if (attr_y > y)
4765 MovDir[x][y] |= (AllPlayersGone ? MV_UP : MV_DOWN);
4767 if (element == EL_ROBOT)
4771 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4772 MovDir[x][y] &= (RND(2) ? MV_HORIZONTAL : MV_VERTICAL);
4773 Moving2Blocked(x, y, &newx, &newy);
4775 if (IN_LEV_FIELD(newx, newy) && IS_FREE_OR_PLAYER(newx, newy))
4776 MovDelay[x][y] = 8 + 8 * !RND(3);
4778 MovDelay[x][y] = 16;
4780 else if (element == EL_PENGUIN)
4786 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4788 boolean first_horiz = RND(2);
4789 int new_move_dir = MovDir[x][y];
4792 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4793 Moving2Blocked(x, y, &newx, &newy);
4795 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4799 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4800 Moving2Blocked(x, y, &newx, &newy);
4802 if (PENGUIN_CAN_ENTER_FIELD(EL_PENGUIN, newx, newy))
4805 MovDir[x][y] = old_move_dir;
4809 else /* (element == EL_SATELLITE) */
4815 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4817 boolean first_horiz = RND(2);
4818 int new_move_dir = MovDir[x][y];
4821 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4822 Moving2Blocked(x, y, &newx, &newy);
4824 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4828 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4829 Moving2Blocked(x, y, &newx, &newy);
4831 if (SATELLITE_CAN_ENTER_FIELD(newx, newy))
4834 MovDir[x][y] = old_move_dir;
4839 else if (move_pattern == MV_TURNING_LEFT ||
4840 move_pattern == MV_TURNING_RIGHT ||
4841 move_pattern == MV_TURNING_LEFT_RIGHT ||
4842 move_pattern == MV_TURNING_RIGHT_LEFT ||
4843 move_pattern == MV_TURNING_RANDOM ||
4844 move_pattern == MV_ALL_DIRECTIONS)
4846 boolean can_turn_left =
4847 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y);
4848 boolean can_turn_right =
4849 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x,right_y);
4851 if (element_info[element].move_stepsize == 0) /* "not moving" */
4854 if (move_pattern == MV_TURNING_LEFT)
4855 MovDir[x][y] = left_dir;
4856 else if (move_pattern == MV_TURNING_RIGHT)
4857 MovDir[x][y] = right_dir;
4858 else if (move_pattern == MV_TURNING_LEFT_RIGHT)
4859 MovDir[x][y] = (can_turn_left || !can_turn_right ? left_dir : right_dir);
4860 else if (move_pattern == MV_TURNING_RIGHT_LEFT)
4861 MovDir[x][y] = (can_turn_right || !can_turn_left ? right_dir : left_dir);
4862 else if (move_pattern == MV_TURNING_RANDOM)
4863 MovDir[x][y] = (can_turn_left && !can_turn_right ? left_dir :
4864 can_turn_right && !can_turn_left ? right_dir :
4865 RND(2) ? left_dir : right_dir);
4866 else if (can_turn_left && can_turn_right)
4867 MovDir[x][y] = (RND(3) ? (RND(2) ? left_dir : right_dir) : back_dir);
4868 else if (can_turn_left)
4869 MovDir[x][y] = (RND(2) ? left_dir : back_dir);
4870 else if (can_turn_right)
4871 MovDir[x][y] = (RND(2) ? right_dir : back_dir);
4873 MovDir[x][y] = back_dir;
4875 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4877 else if (move_pattern == MV_HORIZONTAL ||
4878 move_pattern == MV_VERTICAL)
4880 if (move_pattern & old_move_dir)
4881 MovDir[x][y] = back_dir;
4882 else if (move_pattern == MV_HORIZONTAL)
4883 MovDir[x][y] = (RND(2) ? MV_LEFT : MV_RIGHT);
4884 else if (move_pattern == MV_VERTICAL)
4885 MovDir[x][y] = (RND(2) ? MV_UP : MV_DOWN);
4887 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4889 else if (move_pattern & MV_ANY_DIRECTION)
4891 MovDir[x][y] = move_pattern;
4892 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4894 else if (move_pattern & MV_WIND_DIRECTION)
4896 MovDir[x][y] = game.wind_direction;
4897 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4899 else if (move_pattern == MV_ALONG_LEFT_SIDE)
4901 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, left_x, left_y))
4902 MovDir[x][y] = left_dir;
4903 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4904 MovDir[x][y] = right_dir;
4906 if (MovDir[x][y] != old_move_dir)
4907 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4909 else if (move_pattern == MV_ALONG_RIGHT_SIDE)
4911 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, right_x, right_y))
4912 MovDir[x][y] = right_dir;
4913 else if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4914 MovDir[x][y] = left_dir;
4916 if (MovDir[x][y] != old_move_dir)
4917 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4919 else if (move_pattern == MV_TOWARDS_PLAYER ||
4920 move_pattern == MV_AWAY_FROM_PLAYER)
4922 int attr_x = -1, attr_y = -1;
4924 boolean move_away = (move_pattern == MV_AWAY_FROM_PLAYER);
4935 for (i = 0; i < MAX_PLAYERS; i++)
4937 struct PlayerInfo *player = &stored_player[i];
4938 int jx = player->jx, jy = player->jy;
4940 if (!player->active)
4944 ABS(jx - x) + ABS(jy - y) < ABS(attr_x - x) + ABS(attr_y - y))
4952 MovDir[x][y] = MV_NONE;
4954 MovDir[x][y] |= (move_away ? MV_RIGHT : MV_LEFT);
4955 else if (attr_x > x)
4956 MovDir[x][y] |= (move_away ? MV_LEFT : MV_RIGHT);
4958 MovDir[x][y] |= (move_away ? MV_DOWN : MV_UP);
4959 else if (attr_y > y)
4960 MovDir[x][y] |= (move_away ? MV_UP : MV_DOWN);
4962 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
4964 if (MovDir[x][y] & MV_HORIZONTAL && MovDir[x][y] & MV_VERTICAL)
4966 boolean first_horiz = RND(2);
4967 int new_move_dir = MovDir[x][y];
4969 if (element_info[element].move_stepsize == 0) /* "not moving" */
4971 first_horiz = (ABS(attr_x - x) >= ABS(attr_y - y));
4972 MovDir[x][y] &= (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4978 new_move_dir & (first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4979 Moving2Blocked(x, y, &newx, &newy);
4981 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4985 new_move_dir & (!first_horiz ? MV_HORIZONTAL : MV_VERTICAL);
4986 Moving2Blocked(x, y, &newx, &newy);
4988 if (CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
4991 MovDir[x][y] = old_move_dir;
4994 else if (move_pattern == MV_WHEN_PUSHED ||
4995 move_pattern == MV_WHEN_DROPPED)
4997 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, move_x, move_y))
4998 MovDir[x][y] = MV_NONE;
5002 else if (move_pattern & MV_MAZE_RUNNER_STYLE)
5004 static int test_xy[7][2] =
5014 static int test_dir[7] =
5024 boolean hunter_mode = (move_pattern == MV_MAZE_HUNTER);
5025 int move_preference = -1000000; /* start with very low preference */
5026 int new_move_dir = MV_NONE;
5027 int start_test = RND(4);
5030 for (i = 0; i < NUM_DIRECTIONS; i++)
5032 int move_dir = test_dir[start_test + i];
5033 int move_dir_preference;
5035 xx = x + test_xy[start_test + i][0];
5036 yy = y + test_xy[start_test + i][1];
5038 if (hunter_mode && IN_LEV_FIELD(xx, yy) &&
5039 (IS_PLAYER(xx, yy) || Feld[xx][yy] == EL_PLAYER_IS_LEAVING))
5041 new_move_dir = move_dir;
5046 if (!CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, xx, yy))
5049 move_dir_preference = -1 * RunnerVisit[xx][yy];
5050 if (hunter_mode && PlayerVisit[xx][yy] > 0)
5051 move_dir_preference = PlayerVisit[xx][yy];
5053 if (move_dir_preference > move_preference)
5055 /* prefer field that has not been visited for the longest time */
5056 move_preference = move_dir_preference;
5057 new_move_dir = move_dir;
5059 else if (move_dir_preference == move_preference &&
5060 move_dir == old_move_dir)
5062 /* prefer last direction when all directions are preferred equally */
5063 move_preference = move_dir_preference;
5064 new_move_dir = move_dir;
5068 MovDir[x][y] = new_move_dir;
5069 if (old_move_dir != new_move_dir)
5070 MovDelay[x][y] = GET_NEW_MOVE_DELAY(element);
5074 static void TurnRound(int x, int y)
5076 int direction = MovDir[x][y];
5080 GfxDir[x][y] = MovDir[x][y];
5082 if (direction != MovDir[x][y])
5086 GfxAction[x][y] = ACTION_TURNING_FROM_LEFT + MV_DIR_BIT(direction);
5089 static boolean JustBeingPushed(int x, int y)
5093 for (i = 0; i < MAX_PLAYERS; i++)
5095 struct PlayerInfo *player = &stored_player[i];
5097 if (player->active && player->is_pushing && player->MovPos)
5099 int next_jx = player->jx + (player->jx - player->last_jx);
5100 int next_jy = player->jy + (player->jy - player->last_jy);
5102 if (x == next_jx && y == next_jy)
5110 void StartMoving(int x, int y)
5112 boolean started_moving = FALSE; /* some elements can fall _and_ move */
5113 int element = Feld[x][y];
5118 if (MovDelay[x][y] == 0)
5119 GfxAction[x][y] = ACTION_DEFAULT;
5121 if (CAN_FALL(element) && y < lev_fieldy - 1)
5123 if ((x > 0 && IS_PLAYER(x - 1, y)) ||
5124 (x < lev_fieldx - 1 && IS_PLAYER(x + 1, y)))
5125 if (JustBeingPushed(x, y))
5128 if (element == EL_QUICKSAND_FULL)
5130 if (IS_FREE(x, y + 1))
5132 InitMovingField(x, y, MV_DOWN);
5133 started_moving = TRUE;
5135 Feld[x][y] = EL_QUICKSAND_EMPTYING;
5136 Store[x][y] = EL_ROCK;
5138 PlayLevelSoundAction(x, y, ACTION_EMPTYING);
5140 else if (Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5142 if (!MovDelay[x][y])
5143 MovDelay[x][y] = TILEY + 1;
5152 Feld[x][y] = EL_QUICKSAND_EMPTY;
5153 Feld[x][y + 1] = EL_QUICKSAND_FULL;
5154 Store[x][y + 1] = Store[x][y];
5157 PlayLevelSoundAction(x, y, ACTION_FILLING);
5160 else if ((element == EL_ROCK || element == EL_BD_ROCK) &&
5161 Feld[x][y + 1] == EL_QUICKSAND_EMPTY)
5163 InitMovingField(x, y, MV_DOWN);
5164 started_moving = TRUE;
5166 Feld[x][y] = EL_QUICKSAND_FILLING;
5167 Store[x][y] = element;
5169 PlayLevelSoundAction(x, y, ACTION_FILLING);
5171 else if (element == EL_MAGIC_WALL_FULL)
5173 if (IS_FREE(x, y + 1))
5175 InitMovingField(x, y, MV_DOWN);
5176 started_moving = TRUE;
5178 Feld[x][y] = EL_MAGIC_WALL_EMPTYING;
5179 Store[x][y] = EL_CHANGED(Store[x][y]);
5181 else if (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE)
5183 if (!MovDelay[x][y])
5184 MovDelay[x][y] = TILEY/4 + 1;
5193 Feld[x][y] = EL_MAGIC_WALL_ACTIVE;
5194 Feld[x][y + 1] = EL_MAGIC_WALL_FULL;
5195 Store[x][y + 1] = EL_CHANGED(Store[x][y]);
5199 else if (element == EL_BD_MAGIC_WALL_FULL)
5201 if (IS_FREE(x, y + 1))
5203 InitMovingField(x, y, MV_DOWN);
5204 started_moving = TRUE;
5206 Feld[x][y] = EL_BD_MAGIC_WALL_EMPTYING;
5207 Store[x][y] = EL_CHANGED2(Store[x][y]);
5209 else if (Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE)
5211 if (!MovDelay[x][y])
5212 MovDelay[x][y] = TILEY/4 + 1;
5221 Feld[x][y] = EL_BD_MAGIC_WALL_ACTIVE;
5222 Feld[x][y + 1] = EL_BD_MAGIC_WALL_FULL;
5223 Store[x][y + 1] = EL_CHANGED2(Store[x][y]);
5227 else if (CAN_PASS_MAGIC_WALL(element) &&
5228 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ||
5229 Feld[x][y + 1] == EL_BD_MAGIC_WALL_ACTIVE))
5231 InitMovingField(x, y, MV_DOWN);
5232 started_moving = TRUE;
5235 (Feld[x][y + 1] == EL_MAGIC_WALL_ACTIVE ? EL_MAGIC_WALL_FILLING :
5236 EL_BD_MAGIC_WALL_FILLING);
5237 Store[x][y] = element;
5239 else if (CAN_FALL(element) && Feld[x][y + 1] == EL_ACID)
5241 SplashAcid(x, y + 1);
5243 InitMovingField(x, y, MV_DOWN);
5244 started_moving = TRUE;
5246 Store[x][y] = EL_ACID;
5248 else if ((game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5249 CheckCollision[x][y] && !IS_FREE(x, y + 1)) ||
5251 (game.engine_version >= VERSION_IDENT(3,0,7,0) &&
5252 CAN_FALL(element) && WasJustFalling[x][y] &&
5253 (Feld[x][y + 1] == EL_BLOCKED || IS_PLAYER(x, y + 1))) ||
5255 (game.engine_version < VERSION_IDENT(2,2,0,7) &&
5256 CAN_FALL(element) && WasJustMoving[x][y] && !Pushed[x][y + 1] &&
5257 (Feld[x][y + 1] == EL_BLOCKED)))
5259 /* this is needed for a special case not covered by calling "Impact()"
5260 from "ContinueMoving()": if an element moves to a tile directly below
5261 another element which was just falling on that tile (which was empty
5262 in the previous frame), the falling element above would just stop
5263 instead of smashing the element below (in previous version, the above
5264 element was just checked for "moving" instead of "falling", resulting
5265 in incorrect smashes caused by horizontal movement of the above
5266 element; also, the case of the player being the element to smash was
5267 simply not covered here... :-/ ) */
5269 CheckCollision[x][y] = 0;
5273 else if (IS_FREE(x, y + 1) && element == EL_SPRING && level.use_spring_bug)
5275 if (MovDir[x][y] == MV_NONE)
5277 InitMovingField(x, y, MV_DOWN);
5278 started_moving = TRUE;
5281 else if (IS_FREE(x, y + 1) || Feld[x][y + 1] == EL_DIAMOND_BREAKING)
5283 if (WasJustFalling[x][y]) /* prevent animation from being restarted */
5284 MovDir[x][y] = MV_DOWN;
5286 InitMovingField(x, y, MV_DOWN);
5287 started_moving = TRUE;
5289 else if (element == EL_AMOEBA_DROP)
5291 Feld[x][y] = EL_AMOEBA_GROWING;
5292 Store[x][y] = EL_AMOEBA_WET;
5294 else if (((IS_SLIPPERY(Feld[x][y + 1]) && !IS_PLAYER(x, y + 1)) ||
5295 (IS_EM_SLIPPERY_WALL(Feld[x][y + 1]) && IS_GEM(element))) &&
5296 !IS_FALLING(x, y + 1) && !WasJustMoving[x][y + 1] &&
5297 element != EL_DX_SUPABOMB && element != EL_SP_DISK_ORANGE)
5299 boolean can_fall_left = (x > 0 && IS_FREE(x - 1, y) &&
5300 (IS_FREE(x - 1, y + 1) ||
5301 Feld[x - 1][y + 1] == EL_ACID));
5302 boolean can_fall_right = (x < lev_fieldx - 1 && IS_FREE(x + 1, y) &&
5303 (IS_FREE(x + 1, y + 1) ||
5304 Feld[x + 1][y + 1] == EL_ACID));
5305 boolean can_fall_any = (can_fall_left || can_fall_right);
5306 boolean can_fall_both = (can_fall_left && can_fall_right);
5307 int slippery_type = element_info[Feld[x][y + 1]].slippery_type;
5309 #if USE_NEW_ALL_SLIPPERY
5310 if (can_fall_any && slippery_type != SLIPPERY_ANY_RANDOM)
5312 if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5313 can_fall_right = FALSE;
5314 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5315 can_fall_left = FALSE;
5316 else if (slippery_type == SLIPPERY_ONLY_LEFT)
5317 can_fall_right = FALSE;
5318 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5319 can_fall_left = FALSE;
5321 can_fall_any = (can_fall_left || can_fall_right);
5322 can_fall_both = FALSE;
5325 if (can_fall_any && IS_CUSTOM_ELEMENT(Feld[x][y + 1]))
5327 if (slippery_type == SLIPPERY_ONLY_LEFT)
5328 can_fall_right = FALSE;
5329 else if (slippery_type == SLIPPERY_ONLY_RIGHT)
5330 can_fall_left = FALSE;
5331 else if (slippery_type == SLIPPERY_ANY_LEFT_RIGHT && can_fall_both)
5332 can_fall_right = FALSE;
5333 else if (slippery_type == SLIPPERY_ANY_RIGHT_LEFT && can_fall_both)
5334 can_fall_left = FALSE;
5336 can_fall_any = (can_fall_left || can_fall_right);
5337 can_fall_both = (can_fall_left && can_fall_right);
5341 #if USE_NEW_ALL_SLIPPERY
5343 #if USE_NEW_SP_SLIPPERY
5344 /* !!! better use the same properties as for custom elements here !!! */
5345 else if (game.engine_version >= VERSION_IDENT(3,1,1,0) &&
5346 can_fall_both && IS_SP_ELEMENT(Feld[x][y + 1]))
5348 can_fall_right = FALSE; /* slip down on left side */
5349 can_fall_both = FALSE;
5354 #if USE_NEW_ALL_SLIPPERY
5357 if (element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5358 can_fall_right = FALSE; /* slip down on left side */
5360 can_fall_left = !(can_fall_right = RND(2));
5362 can_fall_both = FALSE;
5367 if (game.emulation == EMU_BOULDERDASH ||
5368 element == EL_BD_ROCK || element == EL_BD_DIAMOND)
5369 can_fall_right = FALSE; /* slip down on left side */
5371 can_fall_left = !(can_fall_right = RND(2));
5373 can_fall_both = FALSE;
5379 /* if not determined otherwise, prefer left side for slipping down */
5380 InitMovingField(x, y, can_fall_left ? MV_LEFT : MV_RIGHT);
5381 started_moving = TRUE;
5385 else if (IS_BELT_ACTIVE(Feld[x][y + 1]) && !CAN_MOVE(element))
5387 else if (IS_BELT_ACTIVE(Feld[x][y + 1]))
5390 boolean left_is_free = (x > 0 && IS_FREE(x - 1, y));
5391 boolean right_is_free = (x < lev_fieldx - 1 && IS_FREE(x + 1, y));
5392 int belt_nr = getBeltNrFromBeltActiveElement(Feld[x][y + 1]);
5393 int belt_dir = game.belt_dir[belt_nr];
5395 if ((belt_dir == MV_LEFT && left_is_free) ||
5396 (belt_dir == MV_RIGHT && right_is_free))
5398 int nextx = (belt_dir == MV_LEFT ? x - 1 : x + 1);
5400 InitMovingField(x, y, belt_dir);
5401 started_moving = TRUE;
5403 Pushed[x][y] = TRUE;
5404 Pushed[nextx][y] = TRUE;
5406 GfxAction[x][y] = ACTION_DEFAULT;
5410 MovDir[x][y] = 0; /* if element was moving, stop it */
5415 /* not "else if" because of elements that can fall and move (EL_SPRING) */
5417 if (CAN_MOVE(element) && !started_moving && MovDir[x][y] != MV_NONE)
5419 if (CAN_MOVE(element) && !started_moving)
5422 int move_pattern = element_info[element].move_pattern;
5427 if (MovDir[x][y] == MV_NONE)
5429 printf("StartMoving(): %d,%d: element %d ['%s'] not moving\n",
5430 x, y, element, element_info[element].token_name);
5431 printf("StartMoving(): This should never happen!\n");
5436 Moving2Blocked(x, y, &newx, &newy);
5438 if (IS_PUSHABLE(element) && JustBeingPushed(x, y))
5441 if (game.engine_version >= VERSION_IDENT(3,1,0,0) &&
5442 CheckCollision[x][y] && !IN_LEV_FIELD_AND_IS_FREE(newx, newy))
5444 WasJustMoving[x][y] = 0;
5445 CheckCollision[x][y] = 0;
5447 TestIfElementHitsCustomElement(x, y, MovDir[x][y]);
5449 if (Feld[x][y] != element) /* element has changed */
5453 if (!MovDelay[x][y]) /* start new movement phase */
5455 /* all objects that can change their move direction after each step
5456 (YAMYAM, DARK_YAMYAM and PACMAN go straight until they hit a wall */
5458 if (element != EL_YAMYAM &&
5459 element != EL_DARK_YAMYAM &&
5460 element != EL_PACMAN &&
5461 !(move_pattern & MV_ANY_DIRECTION) &&
5462 move_pattern != MV_TURNING_LEFT &&
5463 move_pattern != MV_TURNING_RIGHT &&
5464 move_pattern != MV_TURNING_LEFT_RIGHT &&
5465 move_pattern != MV_TURNING_RIGHT_LEFT &&
5466 move_pattern != MV_TURNING_RANDOM)
5470 if (MovDelay[x][y] && (element == EL_BUG ||
5471 element == EL_SPACESHIP ||
5472 element == EL_SP_SNIKSNAK ||
5473 element == EL_SP_ELECTRON ||
5474 element == EL_MOLE))
5475 DrawLevelField(x, y);
5479 if (MovDelay[x][y]) /* wait some time before next movement */
5483 if (element == EL_ROBOT ||
5484 element == EL_YAMYAM ||
5485 element == EL_DARK_YAMYAM)
5487 DrawLevelElementAnimationIfNeeded(x, y, element);
5488 PlayLevelSoundAction(x, y, ACTION_WAITING);
5490 else if (element == EL_SP_ELECTRON)
5491 DrawLevelElementAnimationIfNeeded(x, y, element);
5492 else if (element == EL_DRAGON)
5495 int dir = MovDir[x][y];
5496 int dx = (dir == MV_LEFT ? -1 : dir == MV_RIGHT ? +1 : 0);
5497 int dy = (dir == MV_UP ? -1 : dir == MV_DOWN ? +1 : 0);
5498 int graphic = (dir == MV_LEFT ? IMG_FLAMES_1_LEFT :
5499 dir == MV_RIGHT ? IMG_FLAMES_1_RIGHT :
5500 dir == MV_UP ? IMG_FLAMES_1_UP :
5501 dir == MV_DOWN ? IMG_FLAMES_1_DOWN : IMG_EMPTY);
5502 int frame = getGraphicAnimationFrame(graphic, GfxFrame[x][y]);
5504 GfxAction[x][y] = ACTION_ATTACKING;
5506 if (IS_PLAYER(x, y))
5507 DrawPlayerField(x, y);
5509 DrawLevelField(x, y);
5511 PlayLevelSoundActionIfLoop(x, y, ACTION_ATTACKING);
5513 for (i = 1; i <= 3; i++)
5515 int xx = x + i * dx;
5516 int yy = y + i * dy;
5517 int sx = SCREENX(xx);
5518 int sy = SCREENY(yy);
5519 int flame_graphic = graphic + (i - 1);
5521 if (!IN_LEV_FIELD(xx, yy) || IS_DRAGONFIRE_PROOF(Feld[xx][yy]))
5526 int flamed = MovingOrBlocked2Element(xx, yy);
5530 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5532 else if (IS_MOVING(xx, yy) || IS_BLOCKED(xx, yy))
5533 RemoveMovingField(xx, yy);
5535 RemoveField(xx, yy);
5537 if (IS_CLASSIC_ENEMY(flamed) || CAN_EXPLODE_BY_DRAGONFIRE(flamed))
5540 RemoveMovingField(xx, yy);
5543 ChangeDelay[xx][yy] = 0;
5545 Feld[xx][yy] = EL_FLAMES;
5547 if (IN_SCR_FIELD(sx, sy))
5549 DrawLevelFieldCrumbledSand(xx, yy);
5550 DrawGraphic(sx, sy, flame_graphic, frame);
5555 if (Feld[xx][yy] == EL_FLAMES)
5556 Feld[xx][yy] = EL_EMPTY;
5557 DrawLevelField(xx, yy);
5562 if (MovDelay[x][y]) /* element still has to wait some time */
5564 PlayLevelSoundAction(x, y, ACTION_WAITING);
5570 /* now make next step */
5572 Moving2Blocked(x, y, &newx, &newy); /* get next screen position */
5574 if (DONT_COLLIDE_WITH(element) &&
5575 IN_LEV_FIELD(newx, newy) && IS_PLAYER(newx, newy) &&
5576 !PLAYER_ENEMY_PROTECTED(newx, newy))
5578 TestIfBadThingRunsIntoPlayer(x, y, MovDir[x][y]);
5583 else if (CAN_MOVE_INTO_ACID(element) &&
5584 IN_LEV_FIELD(newx, newy) && Feld[newx][newy] == EL_ACID &&
5585 (MovDir[x][y] == MV_DOWN ||
5586 game.engine_version >= VERSION_IDENT(3,1,0,0)))
5588 SplashAcid(newx, newy);
5589 Store[x][y] = EL_ACID;
5591 else if (element == EL_PENGUIN && IN_LEV_FIELD(newx, newy))
5593 if (Feld[newx][newy] == EL_EXIT_OPEN)
5596 DrawLevelField(x, y);
5598 PlayLevelSound(newx, newy, SND_PENGUIN_PASSING);
5599 if (IN_SCR_FIELD(SCREENX(newx), SCREENY(newy)))
5600 DrawGraphicThruMask(SCREENX(newx),SCREENY(newy), el2img(element), 0);
5602 local_player->friends_still_needed--;
5603 if (!local_player->friends_still_needed &&
5604 !local_player->GameOver && AllPlayersGone)
5605 local_player->LevelSolved = local_player->GameOver = TRUE;
5609 else if (IS_FOOD_PENGUIN(Feld[newx][newy]))
5611 if (DigField(local_player, x, y, newx, newy, 0,0, DF_DIG) == MF_MOVING)
5612 DrawLevelField(newx, newy);
5614 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
5616 else if (!IS_FREE(newx, newy))
5618 GfxAction[x][y] = ACTION_WAITING;
5620 if (IS_PLAYER(x, y))
5621 DrawPlayerField(x, y);
5623 DrawLevelField(x, y);
5628 else if (element == EL_PIG && IN_LEV_FIELD(newx, newy))
5630 if (IS_FOOD_PIG(Feld[newx][newy]))
5632 if (IS_MOVING(newx, newy))
5633 RemoveMovingField(newx, newy);
5636 Feld[newx][newy] = EL_EMPTY;
5637 DrawLevelField(newx, newy);
5640 PlayLevelSound(x, y, SND_PIG_DIGGING);
5642 else if (!IS_FREE(newx, newy))
5644 if (IS_PLAYER(x, y))
5645 DrawPlayerField(x, y);
5647 DrawLevelField(x, y);
5652 else if (IS_CUSTOM_ELEMENT(element) &&
5653 CUSTOM_ELEMENT_CAN_ENTER_FIELD(element, newx, newy))
5655 int new_element = Feld[newx][newy];
5657 if (!IS_FREE(newx, newy))
5659 int action = (IS_DIGGABLE(new_element) ? ACTION_DIGGING :
5660 IS_COLLECTIBLE(new_element) ? ACTION_COLLECTING :
5663 /* no element can dig solid indestructible elements */
5664 if (IS_INDESTRUCTIBLE(new_element) &&
5665 !IS_DIGGABLE(new_element) &&
5666 !IS_COLLECTIBLE(new_element))
5669 if (AmoebaNr[newx][newy] &&
5670 (new_element == EL_AMOEBA_FULL ||
5671 new_element == EL_BD_AMOEBA ||
5672 new_element == EL_AMOEBA_GROWING))
5674 AmoebaCnt[AmoebaNr[newx][newy]]--;
5675 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5678 if (IS_MOVING(newx, newy))
5679 RemoveMovingField(newx, newy);
5682 RemoveField(newx, newy);
5683 DrawLevelField(newx, newy);
5686 /* if digged element was about to explode, prevent the explosion */
5687 ExplodeField[newx][newy] = EX_TYPE_NONE;
5689 PlayLevelSoundAction(x, y, action);
5692 Store[newx][newy] = EL_EMPTY;
5694 /* this makes it possible to leave the removed element again */
5695 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5696 Store[newx][newy] = new_element;
5698 if (IS_EQUAL_OR_IN_GROUP(new_element, MOVE_ENTER_EL(element)))
5700 int move_leave_element = element_info[element].move_leave_element;
5702 /* this makes it possible to leave the removed element again */
5703 Store[newx][newy] = (move_leave_element == EL_TRIGGER_ELEMENT ?
5704 new_element : move_leave_element);
5708 if (move_pattern & MV_MAZE_RUNNER_STYLE)
5710 RunnerVisit[x][y] = FrameCounter;
5711 PlayerVisit[x][y] /= 8; /* expire player visit path */
5714 else if (element == EL_DRAGON && IN_LEV_FIELD(newx, newy))
5716 if (!IS_FREE(newx, newy))
5718 if (IS_PLAYER(x, y))
5719 DrawPlayerField(x, y);
5721 DrawLevelField(x, y);
5727 boolean wanna_flame = !RND(10);
5728 int dx = newx - x, dy = newy - y;
5729 int newx1 = newx + 1 * dx, newy1 = newy + 1 * dy;
5730 int newx2 = newx + 2 * dx, newy2 = newy + 2 * dy;
5731 int element1 = (IN_LEV_FIELD(newx1, newy1) ?
5732 MovingOrBlocked2Element(newx1, newy1) : EL_STEELWALL);
5733 int element2 = (IN_LEV_FIELD(newx2, newy2) ?
5734 MovingOrBlocked2Element(newx2, newy2) : EL_STEELWALL);
5737 IS_CLASSIC_ENEMY(element1) ||
5738 IS_CLASSIC_ENEMY(element2)) &&
5739 element1 != EL_DRAGON && element2 != EL_DRAGON &&
5740 element1 != EL_FLAMES && element2 != EL_FLAMES)
5742 ResetGfxAnimation(x, y);
5743 GfxAction[x][y] = ACTION_ATTACKING;
5745 if (IS_PLAYER(x, y))
5746 DrawPlayerField(x, y);
5748 DrawLevelField(x, y);
5750 PlayLevelSound(x, y, SND_DRAGON_ATTACKING);
5752 MovDelay[x][y] = 50;
5756 RemoveField(newx, newy);
5758 Feld[newx][newy] = EL_FLAMES;
5759 if (IN_LEV_FIELD(newx1, newy1) && Feld[newx1][newy1] == EL_EMPTY)
5762 RemoveField(newx1, newy1);
5764 Feld[newx1][newy1] = EL_FLAMES;
5766 if (IN_LEV_FIELD(newx2, newy2) && Feld[newx2][newy2] == EL_EMPTY)
5769 RemoveField(newx2, newy2);
5771 Feld[newx2][newy2] = EL_FLAMES;
5778 else if (element == EL_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5779 Feld[newx][newy] == EL_DIAMOND)
5781 if (IS_MOVING(newx, newy))
5782 RemoveMovingField(newx, newy);
5785 Feld[newx][newy] = EL_EMPTY;
5786 DrawLevelField(newx, newy);
5789 PlayLevelSound(x, y, SND_YAMYAM_DIGGING);
5791 else if (element == EL_DARK_YAMYAM && IN_LEV_FIELD(newx, newy) &&
5792 IS_FOOD_DARK_YAMYAM(Feld[newx][newy]))
5794 if (AmoebaNr[newx][newy])
5796 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5797 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5798 Feld[newx][newy] == EL_BD_AMOEBA)
5799 AmoebaCnt[AmoebaNr[newx][newy]]--;
5804 if (IS_MOVING(newx, newy) || IS_BLOCKED(newx, newy))
5806 RemoveMovingField(newx, newy);
5809 if (IS_MOVING(newx, newy))
5811 RemoveMovingField(newx, newy);
5816 Feld[newx][newy] = EL_EMPTY;
5817 DrawLevelField(newx, newy);
5820 PlayLevelSound(x, y, SND_DARK_YAMYAM_DIGGING);
5822 else if ((element == EL_PACMAN || element == EL_MOLE)
5823 && IN_LEV_FIELD(newx, newy) && IS_AMOEBOID(Feld[newx][newy]))
5825 if (AmoebaNr[newx][newy])
5827 AmoebaCnt2[AmoebaNr[newx][newy]]--;
5828 if (Feld[newx][newy] == EL_AMOEBA_FULL ||
5829 Feld[newx][newy] == EL_BD_AMOEBA)
5830 AmoebaCnt[AmoebaNr[newx][newy]]--;
5833 if (element == EL_MOLE)
5835 Feld[newx][newy] = EL_AMOEBA_SHRINKING;
5836 PlayLevelSound(x, y, SND_MOLE_DIGGING);
5838 ResetGfxAnimation(x, y);
5839 GfxAction[x][y] = ACTION_DIGGING;
5840 DrawLevelField(x, y);
5842 MovDelay[newx][newy] = 0; /* start amoeba shrinking delay */
5844 return; /* wait for shrinking amoeba */
5846 else /* element == EL_PACMAN */
5848 Feld[newx][newy] = EL_EMPTY;
5849 DrawLevelField(newx, newy);
5850 PlayLevelSound(x, y, SND_PACMAN_DIGGING);
5853 else if (element == EL_MOLE && IN_LEV_FIELD(newx, newy) &&
5854 (Feld[newx][newy] == EL_AMOEBA_SHRINKING ||
5855 (Feld[newx][newy] == EL_EMPTY && Stop[newx][newy])))
5857 /* wait for shrinking amoeba to completely disappear */
5860 else if (!IN_LEV_FIELD(newx, newy) || !IS_FREE(newx, newy))
5862 /* object was running against a wall */
5867 /* !!! NEW "CE_BLOCKED" STUFF !!! -- DOES NOT WORK YET... !!! */
5868 if (move_pattern & MV_ANY_DIRECTION &&
5869 move_pattern == MovDir[x][y])
5871 int blocking_element =
5872 (IN_LEV_FIELD(newx, newy) ? Feld[newx][newy] : BorderElement);
5874 CheckElementChangeBySide(x, y, element, blocking_element, CE_BLOCKED,
5877 element = Feld[x][y]; /* element might have changed */
5881 if (GFX_ELEMENT(element) != EL_SAND) /* !!! FIX THIS (crumble) !!! */
5882 DrawLevelElementAnimation(x, y, element);
5884 if (DONT_TOUCH(element))
5885 TestIfBadThingTouchesPlayer(x, y);
5890 InitMovingField(x, y, MovDir[x][y]);
5892 PlayLevelSoundAction(x, y, ACTION_MOVING);
5896 ContinueMoving(x, y);
5899 void ContinueMoving(int x, int y)
5901 int element = Feld[x][y];
5902 struct ElementInfo *ei = &element_info[element];
5903 int direction = MovDir[x][y];
5904 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
5905 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
5906 int newx = x + dx, newy = y + dy;
5907 int stored = Store[x][y];
5908 int stored_new = Store[newx][newy];
5909 boolean pushed_by_player = (Pushed[x][y] && IS_PLAYER(x, y));
5910 boolean pushed_by_conveyor = (Pushed[x][y] && !IS_PLAYER(x, y));
5911 boolean last_line = (newy == lev_fieldy - 1);
5913 MovPos[x][y] += getElementMoveStepsize(x, y);
5915 if (pushed_by_player) /* special case: moving object pushed by player */
5916 MovPos[x][y] = SIGN(MovPos[x][y]) * (TILEX - ABS(PLAYERINFO(x,y)->MovPos));
5918 if (ABS(MovPos[x][y]) < TILEX)
5920 DrawLevelField(x, y);
5922 return; /* element is still moving */
5925 /* element reached destination field */
5927 Feld[x][y] = EL_EMPTY;
5928 Feld[newx][newy] = element;
5929 MovPos[x][y] = 0; /* force "not moving" for "crumbled sand" */
5931 if (Store[x][y] == EL_ACID) /* element is moving into acid pool */
5933 element = Feld[newx][newy] = EL_ACID;
5935 else if (element == EL_MOLE)
5937 Feld[x][y] = EL_SAND;
5939 DrawLevelFieldCrumbledSandNeighbours(x, y);
5941 else if (element == EL_QUICKSAND_FILLING)
5943 element = Feld[newx][newy] = get_next_element(element);
5944 Store[newx][newy] = Store[x][y];
5946 else if (element == EL_QUICKSAND_EMPTYING)
5948 Feld[x][y] = get_next_element(element);
5949 element = Feld[newx][newy] = Store[x][y];
5951 else if (element == EL_MAGIC_WALL_FILLING)
5953 element = Feld[newx][newy] = get_next_element(element);
5954 if (!game.magic_wall_active)
5955 element = Feld[newx][newy] = EL_MAGIC_WALL_DEAD;
5956 Store[newx][newy] = Store[x][y];
5958 else if (element == EL_MAGIC_WALL_EMPTYING)
5960 Feld[x][y] = get_next_element(element);
5961 if (!game.magic_wall_active)
5962 Feld[x][y] = EL_MAGIC_WALL_DEAD;
5963 element = Feld[newx][newy] = Store[x][y];
5965 #if USE_NEW_CUSTOM_VALUE
5966 InitField(newx, newy, FALSE);
5969 else if (element == EL_BD_MAGIC_WALL_FILLING)
5971 element = Feld[newx][newy] = get_next_element(element);
5972 if (!game.magic_wall_active)
5973 element = Feld[newx][newy] = EL_BD_MAGIC_WALL_DEAD;
5974 Store[newx][newy] = Store[x][y];
5976 else if (element == EL_BD_MAGIC_WALL_EMPTYING)
5978 Feld[x][y] = get_next_element(element);
5979 if (!game.magic_wall_active)
5980 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
5981 element = Feld[newx][newy] = Store[x][y];
5983 #if USE_NEW_CUSTOM_VALUE
5984 InitField(newx, newy, FALSE);
5987 else if (element == EL_AMOEBA_DROPPING)
5989 Feld[x][y] = get_next_element(element);
5990 element = Feld[newx][newy] = Store[x][y];
5992 else if (element == EL_SOKOBAN_OBJECT)
5995 Feld[x][y] = Back[x][y];
5997 if (Back[newx][newy])
5998 Feld[newx][newy] = EL_SOKOBAN_FIELD_FULL;
6000 Back[x][y] = Back[newx][newy] = 0;
6003 Store[x][y] = EL_EMPTY;
6008 MovDelay[newx][newy] = 0;
6011 if (CAN_CHANGE_OR_HAS_ACTION(element))
6013 if (CAN_CHANGE(element))
6016 /* copy element change control values to new field */
6017 ChangeDelay[newx][newy] = ChangeDelay[x][y];
6018 ChangePage[newx][newy] = ChangePage[x][y];
6019 ChangeCount[newx][newy] = ChangeCount[x][y];
6020 ChangeEvent[newx][newy] = ChangeEvent[x][y];
6023 #if USE_NEW_CUSTOM_VALUE
6024 CustomValue[newx][newy] = CustomValue[x][y];
6030 #if USE_NEW_CUSTOM_VALUE
6031 CustomValue[newx][newy] = CustomValue[x][y];
6035 ChangeDelay[x][y] = 0;
6036 ChangePage[x][y] = -1;
6037 ChangeCount[x][y] = 0;
6038 ChangeEvent[x][y] = -1;
6040 #if USE_NEW_CUSTOM_VALUE
6041 CustomValue[x][y] = 0;
6044 /* copy animation control values to new field */
6045 GfxFrame[newx][newy] = GfxFrame[x][y];
6046 GfxRandom[newx][newy] = GfxRandom[x][y]; /* keep same random value */
6047 GfxAction[newx][newy] = GfxAction[x][y]; /* keep action one frame */
6048 GfxDir[newx][newy] = GfxDir[x][y]; /* keep element direction */
6050 Pushed[x][y] = Pushed[newx][newy] = FALSE;
6052 /* some elements can leave other elements behind after moving */
6053 if (IS_CUSTOM_ELEMENT(element) && ei->move_leave_element != EL_EMPTY &&
6054 (ei->move_leave_type == LEAVE_TYPE_UNLIMITED || stored != EL_EMPTY) &&
6055 (!IS_PLAYER(x, y) || IS_WALKABLE(ei->move_leave_element)))
6057 int move_leave_element = ei->move_leave_element;
6060 /* this makes it possible to leave the removed element again */
6061 if (ei->move_leave_element == EL_TRIGGER_ELEMENT)
6062 move_leave_element = stored;
6064 /* this makes it possible to leave the removed element again */
6065 if (ei->move_leave_type == LEAVE_TYPE_LIMITED &&
6066 ei->move_leave_element == EL_TRIGGER_ELEMENT)
6067 move_leave_element = stored;
6070 Feld[x][y] = move_leave_element;
6072 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
6073 MovDir[x][y] = direction;
6075 InitField(x, y, FALSE);
6077 if (GFX_CRUMBLED(Feld[x][y]))
6078 DrawLevelFieldCrumbledSandNeighbours(x, y);
6080 if (ELEM_IS_PLAYER(move_leave_element))
6081 RelocatePlayer(x, y, move_leave_element);
6084 /* do this after checking for left-behind element */
6085 ResetGfxAnimation(x, y); /* reset animation values for old field */
6087 if (!CAN_MOVE(element) ||
6088 (CAN_FALL(element) && direction == MV_DOWN &&
6089 (element == EL_SPRING ||
6090 element_info[element].move_pattern == MV_WHEN_PUSHED ||
6091 element_info[element].move_pattern == MV_WHEN_DROPPED)))
6092 GfxDir[x][y] = MovDir[newx][newy] = 0;
6094 DrawLevelField(x, y);
6095 DrawLevelField(newx, newy);
6097 Stop[newx][newy] = TRUE; /* ignore this element until the next frame */
6099 /* prevent pushed element from moving on in pushed direction */
6100 if (pushed_by_player && CAN_MOVE(element) &&
6101 element_info[element].move_pattern & MV_ANY_DIRECTION &&
6102 !(element_info[element].move_pattern & direction))
6103 TurnRound(newx, newy);
6105 /* prevent elements on conveyor belt from moving on in last direction */
6106 if (pushed_by_conveyor && CAN_FALL(element) &&
6107 direction & MV_HORIZONTAL)
6108 MovDir[newx][newy] = 0;
6110 if (!pushed_by_player)
6112 int nextx = newx + dx, nexty = newy + dy;
6113 boolean check_collision_again = IN_LEV_FIELD_AND_IS_FREE(nextx, nexty);
6115 WasJustMoving[newx][newy] = 3;
6117 if (CAN_FALL(element) && direction == MV_DOWN)
6118 WasJustFalling[newx][newy] = 3;
6120 if ((!CAN_FALL(element) || direction == MV_DOWN) && check_collision_again)
6121 CheckCollision[newx][newy] = 2;
6124 if (DONT_TOUCH(element)) /* object may be nasty to player or others */
6126 TestIfBadThingTouchesPlayer(newx, newy);
6127 TestIfBadThingTouchesFriend(newx, newy);
6129 if (!IS_CUSTOM_ELEMENT(element))
6130 TestIfBadThingTouchesOtherBadThing(newx, newy);
6132 else if (element == EL_PENGUIN)
6133 TestIfFriendTouchesBadThing(newx, newy);
6135 /* give the player one last chance (one more frame) to move away */
6136 if (CAN_FALL(element) && direction == MV_DOWN &&
6137 (last_line || (!IS_FREE(x, newy + 1) &&
6138 (!IS_PLAYER(x, newy + 1) ||
6139 game.engine_version < VERSION_IDENT(3,1,1,0)))))
6142 if (pushed_by_player && !game.use_change_when_pushing_bug)
6144 int push_side = MV_DIR_OPPOSITE(direction);
6145 struct PlayerInfo *player = PLAYERINFO(x, y);
6147 CheckElementChangeByPlayer(newx, newy, element, CE_PUSHED_BY_PLAYER,
6148 player->index_bit, push_side);
6149 CheckTriggeredElementChangeByPlayer(newx,newy, element, CE_PLAYER_PUSHES_X,
6150 player->index_bit, push_side);
6153 CheckTriggeredElementChangeBySide(x, y, element, CE_MOVE_OF_X, direction);
6155 TestIfElementTouchesCustomElement(x, y); /* empty or new element */
6157 TestIfElementHitsCustomElement(newx, newy, direction);
6158 TestIfPlayerTouchesCustomElement(newx, newy);
6159 TestIfElementTouchesCustomElement(newx, newy);
6162 if (IS_CUSTOM_ELEMENT(element) && ei->move_enter_element != EL_EMPTY &&
6163 IS_EQUAL_OR_IN_GROUP(stored_new, ei->move_enter_element))
6164 CheckElementChangeBySide(newx, newy, element, stored_new, CE_DIGGING_X,
6165 MV_DIR_OPPOSITE(direction));
6169 int AmoebeNachbarNr(int ax, int ay)
6172 int element = Feld[ax][ay];
6174 static int xy[4][2] =
6182 for (i = 0; i < NUM_DIRECTIONS; i++)
6184 int x = ax + xy[i][0];
6185 int y = ay + xy[i][1];
6187 if (!IN_LEV_FIELD(x, y))
6190 if (Feld[x][y] == element && AmoebaNr[x][y] > 0)
6191 group_nr = AmoebaNr[x][y];
6197 void AmoebenVereinigen(int ax, int ay)
6199 int i, x, y, xx, yy;
6200 int new_group_nr = AmoebaNr[ax][ay];
6201 static int xy[4][2] =
6209 if (new_group_nr == 0)
6212 for (i = 0; i < NUM_DIRECTIONS; i++)
6217 if (!IN_LEV_FIELD(x, y))
6220 if ((Feld[x][y] == EL_AMOEBA_FULL ||
6221 Feld[x][y] == EL_BD_AMOEBA ||
6222 Feld[x][y] == EL_AMOEBA_DEAD) &&
6223 AmoebaNr[x][y] != new_group_nr)
6225 int old_group_nr = AmoebaNr[x][y];
6227 if (old_group_nr == 0)
6230 AmoebaCnt[new_group_nr] += AmoebaCnt[old_group_nr];
6231 AmoebaCnt[old_group_nr] = 0;
6232 AmoebaCnt2[new_group_nr] += AmoebaCnt2[old_group_nr];
6233 AmoebaCnt2[old_group_nr] = 0;
6236 SCAN_PLAYFIELD(xx, yy)
6238 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
6241 if (AmoebaNr[xx][yy] == old_group_nr)
6242 AmoebaNr[xx][yy] = new_group_nr;
6248 void AmoebeUmwandeln(int ax, int ay)
6252 if (Feld[ax][ay] == EL_AMOEBA_DEAD)
6254 int group_nr = AmoebaNr[ax][ay];
6259 printf("AmoebeUmwandeln(): ax = %d, ay = %d\n", ax, ay);
6260 printf("AmoebeUmwandeln(): This should never happen!\n");
6266 SCAN_PLAYFIELD(x, y)
6268 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6271 if (Feld[x][y] == EL_AMOEBA_DEAD && AmoebaNr[x][y] == group_nr)
6274 Feld[x][y] = EL_AMOEBA_TO_DIAMOND;
6278 PlayLevelSound(ax, ay, (IS_GEM(level.amoeba_content) ?
6279 SND_AMOEBA_TURNING_TO_GEM :
6280 SND_AMOEBA_TURNING_TO_ROCK));
6285 static int xy[4][2] =
6293 for (i = 0; i < NUM_DIRECTIONS; i++)
6298 if (!IN_LEV_FIELD(x, y))
6301 if (Feld[x][y] == EL_AMOEBA_TO_DIAMOND)
6303 PlayLevelSound(x, y, (IS_GEM(level.amoeba_content) ?
6304 SND_AMOEBA_TURNING_TO_GEM :
6305 SND_AMOEBA_TURNING_TO_ROCK));
6312 void AmoebeUmwandelnBD(int ax, int ay, int new_element)
6315 int group_nr = AmoebaNr[ax][ay];
6316 boolean done = FALSE;
6321 printf("AmoebeUmwandelnBD(): ax = %d, ay = %d\n", ax, ay);
6322 printf("AmoebeUmwandelnBD(): This should never happen!\n");
6328 SCAN_PLAYFIELD(x, y)
6330 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6333 if (AmoebaNr[x][y] == group_nr &&
6334 (Feld[x][y] == EL_AMOEBA_DEAD ||
6335 Feld[x][y] == EL_BD_AMOEBA ||
6336 Feld[x][y] == EL_AMOEBA_GROWING))
6339 Feld[x][y] = new_element;
6340 InitField(x, y, FALSE);
6341 DrawLevelField(x, y);
6347 PlayLevelSound(ax, ay, (new_element == EL_BD_ROCK ?
6348 SND_BD_AMOEBA_TURNING_TO_ROCK :
6349 SND_BD_AMOEBA_TURNING_TO_GEM));
6352 void AmoebeWaechst(int x, int y)
6354 static unsigned long sound_delay = 0;
6355 static unsigned long sound_delay_value = 0;
6357 if (!MovDelay[x][y]) /* start new growing cycle */
6361 if (DelayReached(&sound_delay, sound_delay_value))
6363 PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
6364 sound_delay_value = 30;
6368 if (MovDelay[x][y]) /* wait some time before growing bigger */
6371 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6373 int frame = getGraphicAnimationFrame(IMG_AMOEBA_GROWING,
6374 6 - MovDelay[x][y]);
6376 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_GROWING, frame);
6379 if (!MovDelay[x][y])
6381 Feld[x][y] = Store[x][y];
6383 DrawLevelField(x, y);
6388 void AmoebaDisappearing(int x, int y)
6390 static unsigned long sound_delay = 0;
6391 static unsigned long sound_delay_value = 0;
6393 if (!MovDelay[x][y]) /* start new shrinking cycle */
6397 if (DelayReached(&sound_delay, sound_delay_value))
6398 sound_delay_value = 30;
6401 if (MovDelay[x][y]) /* wait some time before shrinking */
6404 if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6406 int frame = getGraphicAnimationFrame(IMG_AMOEBA_SHRINKING,
6407 6 - MovDelay[x][y]);
6409 DrawGraphic(SCREENX(x), SCREENY(y), IMG_AMOEBA_SHRINKING, frame);
6412 if (!MovDelay[x][y])
6414 Feld[x][y] = EL_EMPTY;
6415 DrawLevelField(x, y);
6417 /* don't let mole enter this field in this cycle;
6418 (give priority to objects falling to this field from above) */
6424 void AmoebeAbleger(int ax, int ay)
6427 int element = Feld[ax][ay];
6428 int graphic = el2img(element);
6429 int newax = ax, neway = ay;
6430 static int xy[4][2] =
6438 if (!level.amoeba_speed)
6440 Feld[ax][ay] = EL_AMOEBA_DEAD;
6441 DrawLevelField(ax, ay);
6445 if (IS_ANIMATED(graphic))
6446 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6448 if (!MovDelay[ax][ay]) /* start making new amoeba field */
6449 MovDelay[ax][ay] = RND(FRAMES_PER_SECOND * 25 / (1 + level.amoeba_speed));
6451 if (MovDelay[ax][ay]) /* wait some time before making new amoeba */
6454 if (MovDelay[ax][ay])
6458 if (element == EL_AMOEBA_WET) /* object is an acid / amoeba drop */
6461 int x = ax + xy[start][0];
6462 int y = ay + xy[start][1];
6464 if (!IN_LEV_FIELD(x, y))
6467 if (IS_FREE(x, y) ||
6468 CAN_GROW_INTO(Feld[x][y]) ||
6469 Feld[x][y] == EL_QUICKSAND_EMPTY)
6475 if (newax == ax && neway == ay)
6478 else /* normal or "filled" (BD style) amoeba */
6481 boolean waiting_for_player = FALSE;
6483 for (i = 0; i < NUM_DIRECTIONS; i++)
6485 int j = (start + i) % 4;
6486 int x = ax + xy[j][0];
6487 int y = ay + xy[j][1];
6489 if (!IN_LEV_FIELD(x, y))
6492 if (IS_FREE(x, y) ||
6493 CAN_GROW_INTO(Feld[x][y]) ||
6494 Feld[x][y] == EL_QUICKSAND_EMPTY)
6500 else if (IS_PLAYER(x, y))
6501 waiting_for_player = TRUE;
6504 if (newax == ax && neway == ay) /* amoeba cannot grow */
6506 if (i == 4 && (!waiting_for_player || element == EL_BD_AMOEBA))
6508 Feld[ax][ay] = EL_AMOEBA_DEAD;
6509 DrawLevelField(ax, ay);
6510 AmoebaCnt[AmoebaNr[ax][ay]]--;
6512 if (AmoebaCnt[AmoebaNr[ax][ay]] <= 0) /* amoeba is completely dead */
6514 if (element == EL_AMOEBA_FULL)
6515 AmoebeUmwandeln(ax, ay);
6516 else if (element == EL_BD_AMOEBA)
6517 AmoebeUmwandelnBD(ax, ay, level.amoeba_content);
6522 else if (element == EL_AMOEBA_FULL || element == EL_BD_AMOEBA)
6524 /* amoeba gets larger by growing in some direction */
6526 int new_group_nr = AmoebaNr[ax][ay];
6529 if (new_group_nr == 0)
6531 printf("AmoebeAbleger(): newax = %d, neway = %d\n", newax, neway);
6532 printf("AmoebeAbleger(): This should never happen!\n");
6537 AmoebaNr[newax][neway] = new_group_nr;
6538 AmoebaCnt[new_group_nr]++;
6539 AmoebaCnt2[new_group_nr]++;
6541 /* if amoeba touches other amoeba(s) after growing, unify them */
6542 AmoebenVereinigen(newax, neway);
6544 if (element == EL_BD_AMOEBA && AmoebaCnt2[new_group_nr] >= 200)
6546 AmoebeUmwandelnBD(newax, neway, EL_BD_ROCK);
6552 if (element != EL_AMOEBA_WET || neway < ay || !IS_FREE(newax, neway) ||
6553 (neway == lev_fieldy - 1 && newax != ax))
6555 Feld[newax][neway] = EL_AMOEBA_GROWING; /* creation of new amoeba */
6556 Store[newax][neway] = element;
6558 else if (neway == ay)
6560 Feld[newax][neway] = EL_AMOEBA_DROP; /* drop left/right of amoeba */
6562 PlayLevelSoundAction(newax, neway, ACTION_GROWING);
6566 InitMovingField(ax, ay, MV_DOWN); /* drop dripping from amoeba */
6567 Feld[ax][ay] = EL_AMOEBA_DROPPING;
6568 Store[ax][ay] = EL_AMOEBA_DROP;
6569 ContinueMoving(ax, ay);
6573 DrawLevelField(newax, neway);
6576 void Life(int ax, int ay)
6580 static int life[4] = { 2, 3, 3, 3 }; /* parameters for "game of life" */
6583 int element = Feld[ax][ay];
6584 int graphic = el2img(element);
6585 int *life_parameter = (element == EL_GAME_OF_LIFE ? level.game_of_life :
6587 boolean changed = FALSE;
6589 if (IS_ANIMATED(graphic))
6590 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6595 if (!MovDelay[ax][ay]) /* start new "game of life" cycle */
6596 MovDelay[ax][ay] = life_time;
6598 if (MovDelay[ax][ay]) /* wait some time before next cycle */
6601 if (MovDelay[ax][ay])
6605 for (y1 = -1; y1 < 2; y1++) for (x1 = -1; x1 < 2; x1++)
6607 int xx = ax+x1, yy = ay+y1;
6610 if (!IN_LEV_FIELD(xx, yy))
6613 for (y2 = -1; y2 < 2; y2++) for (x2 = -1; x2 < 2; x2++)
6615 int x = xx+x2, y = yy+y2;
6617 if (!IN_LEV_FIELD(x, y) || (x == xx && y == yy))
6620 if (((Feld[x][y] == element ||
6621 (element == EL_GAME_OF_LIFE && IS_PLAYER(x, y))) &&
6623 (IS_FREE(x, y) && Stop[x][y]))
6627 if (xx == ax && yy == ay) /* field in the middle */
6629 if (nachbarn < life_parameter[0] ||
6630 nachbarn > life_parameter[1])
6632 Feld[xx][yy] = EL_EMPTY;
6634 DrawLevelField(xx, yy);
6635 Stop[xx][yy] = TRUE;
6639 else if (IS_FREE(xx, yy) || CAN_GROW_INTO(Feld[xx][yy]))
6640 { /* free border field */
6641 if (nachbarn >= life_parameter[2] &&
6642 nachbarn <= life_parameter[3])
6644 Feld[xx][yy] = element;
6645 MovDelay[xx][yy] = (element == EL_GAME_OF_LIFE ? 0 : life_time-1);
6647 DrawLevelField(xx, yy);
6648 Stop[xx][yy] = TRUE;
6655 PlayLevelSound(ax, ay, element == EL_BIOMAZE ? SND_BIOMAZE_GROWING :
6656 SND_GAME_OF_LIFE_GROWING);
6659 static void InitRobotWheel(int x, int y)
6661 ChangeDelay[x][y] = level.time_wheel * FRAMES_PER_SECOND;
6664 static void RunRobotWheel(int x, int y)
6666 PlayLevelSound(x, y, SND_ROBOT_WHEEL_ACTIVE);
6669 static void StopRobotWheel(int x, int y)
6671 if (ZX == x && ZY == y)
6675 static void InitTimegateWheel(int x, int y)
6677 ChangeDelay[x][y] = level.time_timegate * FRAMES_PER_SECOND;
6680 static void RunTimegateWheel(int x, int y)
6682 PlayLevelSound(x, y, SND_TIMEGATE_SWITCH_ACTIVE);
6685 static void InitMagicBallDelay(int x, int y)
6688 ChangeDelay[x][y] = (level.ball_time + 1) * 8 + 1;
6690 ChangeDelay[x][y] = level.ball_time * FRAMES_PER_SECOND + 1;
6694 static void ActivateMagicBall(int bx, int by)
6698 if (level.ball_random)
6700 int pos_border = RND(8); /* select one of the eight border elements */
6701 int pos_content = (pos_border > 3 ? pos_border + 1 : pos_border);
6702 int xx = pos_content % 3;
6703 int yy = pos_content / 3;
6708 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
6709 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
6713 for (y = by - 1; y <= by + 1; y++) for (x = bx - 1; x <= bx + 1; x++)
6715 int xx = x - bx + 1;
6716 int yy = y - by + 1;
6718 if (IN_LEV_FIELD(x, y) && Feld[x][y] == EL_EMPTY)
6719 CreateField(x, y, level.ball_content[game.ball_content_nr].e[xx][yy]);
6723 game.ball_content_nr = (game.ball_content_nr + 1) % level.num_ball_contents;
6726 void CheckExit(int x, int y)
6728 if (local_player->gems_still_needed > 0 ||
6729 local_player->sokobanfields_still_needed > 0 ||
6730 local_player->lights_still_needed > 0)
6732 int element = Feld[x][y];
6733 int graphic = el2img(element);
6735 if (IS_ANIMATED(graphic))
6736 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6741 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6744 Feld[x][y] = EL_EXIT_OPENING;
6746 PlayLevelSoundNearest(x, y, SND_CLASS_EXIT_OPENING);
6749 void CheckExitSP(int x, int y)
6751 if (local_player->gems_still_needed > 0)
6753 int element = Feld[x][y];
6754 int graphic = el2img(element);
6756 if (IS_ANIMATED(graphic))
6757 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
6762 if (AllPlayersGone) /* do not re-open exit door closed after last player */
6765 Feld[x][y] = EL_SP_EXIT_OPENING;
6767 PlayLevelSoundNearest(x, y, SND_CLASS_SP_EXIT_OPENING);
6770 static void CloseAllOpenTimegates()
6775 SCAN_PLAYFIELD(x, y)
6777 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
6780 int element = Feld[x][y];
6782 if (element == EL_TIMEGATE_OPEN || element == EL_TIMEGATE_OPENING)
6784 Feld[x][y] = EL_TIMEGATE_CLOSING;
6786 PlayLevelSoundAction(x, y, ACTION_CLOSING);
6791 void EdelsteinFunkeln(int x, int y)
6793 if (!IN_SCR_FIELD(SCREENX(x), SCREENY(y)) || IS_MOVING(x, y))
6796 if (Feld[x][y] == EL_BD_DIAMOND)
6799 if (MovDelay[x][y] == 0) /* next animation frame */
6800 MovDelay[x][y] = 11 * !SimpleRND(500);
6802 if (MovDelay[x][y] != 0) /* wait some time before next frame */
6806 if (setup.direct_draw && MovDelay[x][y])
6807 SetDrawtoField(DRAW_BUFFERED);
6809 DrawLevelElementAnimation(x, y, Feld[x][y]);
6811 if (MovDelay[x][y] != 0)
6813 int frame = getGraphicAnimationFrame(IMG_TWINKLE_WHITE,
6814 10 - MovDelay[x][y]);
6816 DrawGraphicThruMask(SCREENX(x), SCREENY(y), IMG_TWINKLE_WHITE, frame);
6818 if (setup.direct_draw)
6822 dest_x = FX + SCREENX(x) * TILEX;
6823 dest_y = FY + SCREENY(y) * TILEY;
6825 BlitBitmap(drawto_field, window,
6826 dest_x, dest_y, TILEX, TILEY, dest_x, dest_y);
6827 SetDrawtoField(DRAW_DIRECT);
6833 void MauerWaechst(int x, int y)
6837 if (!MovDelay[x][y]) /* next animation frame */
6838 MovDelay[x][y] = 3 * delay;
6840 if (MovDelay[x][y]) /* wait some time before next frame */
6844 if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
6846 int graphic = el_dir2img(Feld[x][y], GfxDir[x][y]);
6847 int frame = getGraphicAnimationFrame(graphic, 17 - MovDelay[x][y]);
6849 DrawGraphic(SCREENX(x), SCREENY(y), graphic, frame);
6852 if (!MovDelay[x][y])
6854 if (MovDir[x][y] == MV_LEFT)
6856 if (IN_LEV_FIELD(x - 1, y) && IS_WALL(Feld[x - 1][y]))
6857 DrawLevelField(x - 1, y);
6859 else if (MovDir[x][y] == MV_RIGHT)
6861 if (IN_LEV_FIELD(x + 1, y) && IS_WALL(Feld[x + 1][y]))
6862 DrawLevelField(x + 1, y);
6864 else if (MovDir[x][y] == MV_UP)
6866 if (IN_LEV_FIELD(x, y - 1) && IS_WALL(Feld[x][y - 1]))
6867 DrawLevelField(x, y - 1);
6871 if (IN_LEV_FIELD(x, y + 1) && IS_WALL(Feld[x][y + 1]))
6872 DrawLevelField(x, y + 1);
6875 Feld[x][y] = Store[x][y];
6877 GfxDir[x][y] = MovDir[x][y] = MV_NONE;
6878 DrawLevelField(x, y);
6883 void MauerAbleger(int ax, int ay)
6885 int element = Feld[ax][ay];
6886 int graphic = el2img(element);
6887 boolean oben_frei = FALSE, unten_frei = FALSE;
6888 boolean links_frei = FALSE, rechts_frei = FALSE;
6889 boolean oben_massiv = FALSE, unten_massiv = FALSE;
6890 boolean links_massiv = FALSE, rechts_massiv = FALSE;
6891 boolean new_wall = FALSE;
6893 if (IS_ANIMATED(graphic))
6894 DrawLevelGraphicAnimationIfNeeded(ax, ay, graphic);
6896 if (!MovDelay[ax][ay]) /* start building new wall */
6897 MovDelay[ax][ay] = 6;
6899 if (MovDelay[ax][ay]) /* wait some time before building new wall */
6902 if (MovDelay[ax][ay])
6906 if (IN_LEV_FIELD(ax, ay-1) && IS_FREE(ax, ay-1))
6908 if (IN_LEV_FIELD(ax, ay+1) && IS_FREE(ax, ay+1))
6910 if (IN_LEV_FIELD(ax-1, ay) && IS_FREE(ax-1, ay))
6912 if (IN_LEV_FIELD(ax+1, ay) && IS_FREE(ax+1, ay))
6915 if (element == EL_EXPANDABLE_WALL_VERTICAL ||
6916 element == EL_EXPANDABLE_WALL_ANY)
6920 Feld[ax][ay-1] = EL_EXPANDABLE_WALL_GROWING;
6921 Store[ax][ay-1] = element;
6922 GfxDir[ax][ay-1] = MovDir[ax][ay-1] = MV_UP;
6923 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay-1)))
6924 DrawGraphic(SCREENX(ax), SCREENY(ay - 1),
6925 IMG_EXPANDABLE_WALL_GROWING_UP, 0);
6930 Feld[ax][ay+1] = EL_EXPANDABLE_WALL_GROWING;
6931 Store[ax][ay+1] = element;
6932 GfxDir[ax][ay+1] = MovDir[ax][ay+1] = MV_DOWN;
6933 if (IN_SCR_FIELD(SCREENX(ax), SCREENY(ay+1)))
6934 DrawGraphic(SCREENX(ax), SCREENY(ay + 1),
6935 IMG_EXPANDABLE_WALL_GROWING_DOWN, 0);
6940 if (element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6941 element == EL_EXPANDABLE_WALL_ANY ||
6942 element == EL_EXPANDABLE_WALL)
6946 Feld[ax-1][ay] = EL_EXPANDABLE_WALL_GROWING;
6947 Store[ax-1][ay] = element;
6948 GfxDir[ax-1][ay] = MovDir[ax-1][ay] = MV_LEFT;
6949 if (IN_SCR_FIELD(SCREENX(ax-1), SCREENY(ay)))
6950 DrawGraphic(SCREENX(ax - 1), SCREENY(ay),
6951 IMG_EXPANDABLE_WALL_GROWING_LEFT, 0);
6957 Feld[ax+1][ay] = EL_EXPANDABLE_WALL_GROWING;
6958 Store[ax+1][ay] = element;
6959 GfxDir[ax+1][ay] = MovDir[ax+1][ay] = MV_RIGHT;
6960 if (IN_SCR_FIELD(SCREENX(ax+1), SCREENY(ay)))
6961 DrawGraphic(SCREENX(ax + 1), SCREENY(ay),
6962 IMG_EXPANDABLE_WALL_GROWING_RIGHT, 0);
6967 if (element == EL_EXPANDABLE_WALL && (links_frei || rechts_frei))
6968 DrawLevelField(ax, ay);
6970 if (!IN_LEV_FIELD(ax, ay-1) || IS_WALL(Feld[ax][ay-1]))
6972 if (!IN_LEV_FIELD(ax, ay+1) || IS_WALL(Feld[ax][ay+1]))
6973 unten_massiv = TRUE;
6974 if (!IN_LEV_FIELD(ax-1, ay) || IS_WALL(Feld[ax-1][ay]))
6975 links_massiv = TRUE;
6976 if (!IN_LEV_FIELD(ax+1, ay) || IS_WALL(Feld[ax+1][ay]))
6977 rechts_massiv = TRUE;
6979 if (((oben_massiv && unten_massiv) ||
6980 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
6981 element == EL_EXPANDABLE_WALL) &&
6982 ((links_massiv && rechts_massiv) ||
6983 element == EL_EXPANDABLE_WALL_VERTICAL))
6984 Feld[ax][ay] = EL_WALL;
6987 PlayLevelSoundAction(ax, ay, ACTION_GROWING);
6990 void CheckForDragon(int x, int y)
6993 boolean dragon_found = FALSE;
6994 static int xy[4][2] =
7002 for (i = 0; i < NUM_DIRECTIONS; i++)
7004 for (j = 0; j < 4; j++)
7006 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7008 if (IN_LEV_FIELD(xx, yy) &&
7009 (Feld[xx][yy] == EL_FLAMES || Feld[xx][yy] == EL_DRAGON))
7011 if (Feld[xx][yy] == EL_DRAGON)
7012 dragon_found = TRUE;
7021 for (i = 0; i < NUM_DIRECTIONS; i++)
7023 for (j = 0; j < 3; j++)
7025 int xx = x + j * xy[i][0], yy = y + j * xy[i][1];
7027 if (IN_LEV_FIELD(xx, yy) && Feld[xx][yy] == EL_FLAMES)
7029 Feld[xx][yy] = EL_EMPTY;
7030 DrawLevelField(xx, yy);
7039 static void InitBuggyBase(int x, int y)
7041 int element = Feld[x][y];
7042 int activating_delay = FRAMES_PER_SECOND / 4;
7045 (element == EL_SP_BUGGY_BASE ?
7046 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND) - activating_delay :
7047 element == EL_SP_BUGGY_BASE_ACTIVATING ?
7049 element == EL_SP_BUGGY_BASE_ACTIVE ?
7050 1 * FRAMES_PER_SECOND + RND(1 * FRAMES_PER_SECOND) : 1);
7053 static void WarnBuggyBase(int x, int y)
7056 static int xy[4][2] =
7064 for (i = 0; i < NUM_DIRECTIONS; i++)
7066 int xx = x + xy[i][0], yy = y + xy[i][1];
7068 if (IS_PLAYER(xx, yy))
7070 PlayLevelSound(x, y, SND_SP_BUGGY_BASE_ACTIVE);
7077 static void InitTrap(int x, int y)
7079 ChangeDelay[x][y] = 2 * FRAMES_PER_SECOND + RND(5 * FRAMES_PER_SECOND);
7082 static void ActivateTrap(int x, int y)
7084 PlayLevelSound(x, y, SND_TRAP_ACTIVATING);
7087 static void ChangeActiveTrap(int x, int y)
7089 int graphic = IMG_TRAP_ACTIVE;
7091 /* if new animation frame was drawn, correct crumbled sand border */
7092 if (IS_NEW_FRAME(GfxFrame[x][y], graphic))
7093 DrawLevelFieldCrumbledSand(x, y);
7096 static int getSpecialActionElement(int element, int number, int base_element)
7098 return (element != EL_EMPTY ? element :
7099 number != -1 ? base_element + number - 1 :
7103 static int getModifiedActionNumber(int value_old, int operator, int operand,
7104 int value_min, int value_max)
7106 int value_new = (operator == CA_MODE_SET ? operand :
7107 operator == CA_MODE_ADD ? value_old + operand :
7108 operator == CA_MODE_SUBTRACT ? value_old - operand :
7109 operator == CA_MODE_MULTIPLY ? value_old * operand :
7110 operator == CA_MODE_DIVIDE ? value_old / MAX(1, operand) :
7111 operator == CA_MODE_MODULO ? value_old % MAX(1, operand) :
7114 return (value_new < value_min ? value_min :
7115 value_new > value_max ? value_max :
7119 static void ExecuteCustomElementAction(int x, int y, int element, int page)
7121 struct ElementInfo *ei = &element_info[element];
7122 struct ElementChangeInfo *change = &ei->change_page[page];
7123 int action_type = change->action_type;
7124 int action_mode = change->action_mode;
7125 int action_arg = change->action_arg;
7128 if (!change->has_action)
7131 /* ---------- determine action paramater values -------------------------- */
7133 int level_time_value =
7134 (level.time > 0 ? TimeLeft :
7137 int action_arg_element =
7138 (action_arg == CA_ARG_PLAYER_TRIGGER ? change->actual_trigger_player :
7139 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_element :
7140 action_arg == CA_ARG_ELEMENT_TARGET ? change->target_element :
7143 int action_arg_direction =
7144 (action_arg >= CA_ARG_DIRECTION_LEFT &&
7145 action_arg <= CA_ARG_DIRECTION_DOWN ? action_arg - CA_ARG_DIRECTION :
7146 action_arg == CA_ARG_DIRECTION_TRIGGER ?
7147 change->actual_trigger_side :
7148 action_arg == CA_ARG_DIRECTION_TRIGGER_BACK ?
7149 MV_DIR_OPPOSITE(change->actual_trigger_side) :
7152 int action_arg_number_min =
7153 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_NOT_MOVING :
7156 int action_arg_number_max =
7157 (action_type == CA_SET_PLAYER_SPEED ? STEPSIZE_EVEN_FASTER :
7158 action_type == CA_SET_LEVEL_GEMS ? 999 :
7159 action_type == CA_SET_LEVEL_TIME ? 9999 :
7160 action_type == CA_SET_LEVEL_SCORE ? 99999 :
7161 action_type == CA_SET_CE_SCORE ? 9999 :
7162 action_type == CA_SET_CE_VALUE ? 9999 :
7165 int action_arg_number_reset =
7166 (action_type == CA_SET_PLAYER_SPEED ? level.initial_player_stepsize :
7167 action_type == CA_SET_LEVEL_GEMS ? level.gems_needed :
7168 action_type == CA_SET_LEVEL_TIME ? level.time :
7169 action_type == CA_SET_LEVEL_SCORE ? 0 :
7170 action_type == CA_SET_CE_SCORE ? 0 :
7172 action_type == CA_SET_CE_VALUE ? GET_NEW_CUSTOM_VALUE(element) :
7174 action_type == CA_SET_CE_VALUE ? ei->custom_value_initial :
7178 int action_arg_number =
7179 (action_arg <= CA_ARG_MAX ? action_arg :
7180 action_arg >= CA_ARG_SPEED_NOT_MOVING &&
7181 action_arg <= CA_ARG_SPEED_EVEN_FASTER ? (action_arg - CA_ARG_SPEED) :
7182 action_arg == CA_ARG_SPEED_RESET ? action_arg_number_reset :
7183 action_arg == CA_ARG_NUMBER_MIN ? action_arg_number_min :
7184 action_arg == CA_ARG_NUMBER_MAX ? action_arg_number_max :
7185 action_arg == CA_ARG_NUMBER_RESET ? action_arg_number_reset :
7186 action_arg == CA_ARG_NUMBER_CE_SCORE ? ei->collect_score :
7187 #if USE_NEW_CUSTOM_VALUE
7188 action_arg == CA_ARG_NUMBER_CE_VALUE ? CustomValue[x][y] :
7190 action_arg == CA_ARG_NUMBER_CE_VALUE ? ei->custom_value_initial :
7192 action_arg == CA_ARG_NUMBER_CE_DELAY ? GET_CE_DELAY_VALUE(change) :
7193 action_arg == CA_ARG_NUMBER_LEVEL_TIME ? level_time_value :
7194 action_arg == CA_ARG_NUMBER_LEVEL_GEMS ? local_player->gems_still_needed :
7195 action_arg == CA_ARG_NUMBER_LEVEL_SCORE ? local_player->score :
7196 action_arg == CA_ARG_ELEMENT_TARGET ? GET_NEW_CUSTOM_VALUE(change->target_element) :
7197 action_arg == CA_ARG_ELEMENT_TRIGGER ? change->actual_trigger_ce_value :
7200 int action_arg_number_old =
7201 (action_type == CA_SET_LEVEL_GEMS ? local_player->gems_still_needed :
7202 action_type == CA_SET_LEVEL_TIME ? TimeLeft :
7203 action_type == CA_SET_LEVEL_SCORE ? local_player->score :
7204 action_type == CA_SET_CE_SCORE ? ei->collect_score :
7205 action_type == CA_SET_CE_VALUE ? CustomValue[x][y] :
7208 int action_arg_number_new =
7209 getModifiedActionNumber(action_arg_number_old,
7210 action_mode, action_arg_number,
7211 action_arg_number_min, action_arg_number_max);
7213 int trigger_player_bits =
7214 (change->actual_trigger_player >= EL_PLAYER_1 &&
7215 change->actual_trigger_player <= EL_PLAYER_4 ?
7216 (1 << (change->actual_trigger_player - EL_PLAYER_1)) :
7219 int action_arg_player_bits =
7220 (action_arg >= CA_ARG_PLAYER_1 &&
7221 action_arg <= CA_ARG_PLAYER_4 ? action_arg - CA_ARG_PLAYER :
7222 action_arg == CA_ARG_PLAYER_TRIGGER ? trigger_player_bits :
7225 /* ---------- execute action -------------------------------------------- */
7234 /* ---------- level actions ------------------------------------------- */
7236 case CA_RESTART_LEVEL:
7238 game.restart_level = TRUE;
7243 case CA_SHOW_ENVELOPE:
7245 int element = getSpecialActionElement(action_arg_element,
7246 action_arg_number, EL_ENVELOPE_1);
7248 if (IS_ENVELOPE(element))
7249 local_player->show_envelope = element;
7254 case CA_SET_LEVEL_TIME:
7256 if (level.time > 0) /* only modify limited time value */
7258 TimeLeft = action_arg_number_new;
7260 DrawGameValue_Time(TimeLeft);
7262 if (!TimeLeft && setup.time_limit)
7263 for (i = 0; i < MAX_PLAYERS; i++)
7264 KillPlayer(&stored_player[i]);
7270 case CA_SET_LEVEL_SCORE:
7272 local_player->score = action_arg_number_new;
7274 DrawGameValue_Score(local_player->score);
7279 case CA_SET_LEVEL_GEMS:
7281 local_player->gems_still_needed = action_arg_number_new;
7283 DrawGameValue_Emeralds(local_player->gems_still_needed);
7288 case CA_SET_LEVEL_GRAVITY:
7290 game.gravity = (action_arg == CA_ARG_GRAVITY_OFF ? FALSE :
7291 action_arg == CA_ARG_GRAVITY_ON ? TRUE :
7292 action_arg == CA_ARG_GRAVITY_TOGGLE ? !game.gravity :
7297 case CA_SET_LEVEL_WIND:
7299 game.wind_direction = action_arg_direction;
7304 /* ---------- player actions ------------------------------------------ */
7306 case CA_MOVE_PLAYER:
7308 /* automatically move to the next field in specified direction */
7309 for (i = 0; i < MAX_PLAYERS; i++)
7310 if (trigger_player_bits & (1 << i))
7311 stored_player[i].programmed_action = action_arg_direction;
7316 case CA_EXIT_PLAYER:
7318 for (i = 0; i < MAX_PLAYERS; i++)
7319 if (action_arg_player_bits & (1 << i))
7320 stored_player[i].LevelSolved = stored_player[i].GameOver = TRUE;
7325 case CA_KILL_PLAYER:
7327 for (i = 0; i < MAX_PLAYERS; i++)
7328 if (action_arg_player_bits & (1 << i))
7329 KillPlayer(&stored_player[i]);
7334 case CA_SET_PLAYER_KEYS:
7336 int key_state = (action_mode == CA_MODE_ADD ? TRUE : FALSE);
7337 int element = getSpecialActionElement(action_arg_element,
7338 action_arg_number, EL_KEY_1);
7340 if (IS_KEY(element))
7342 for (i = 0; i < MAX_PLAYERS; i++)
7344 if (trigger_player_bits & (1 << i))
7346 stored_player[i].key[KEY_NR(element)] = key_state;
7348 DrawGameValue_Keys(stored_player[i].key);
7350 redraw_mask |= REDRAW_DOOR_1;
7358 case CA_SET_PLAYER_SPEED:
7360 for (i = 0; i < MAX_PLAYERS; i++)
7362 if (trigger_player_bits & (1 << i))
7364 int move_stepsize = TILEX / stored_player[i].move_delay_value;
7366 if (action_arg == CA_ARG_SPEED_FASTER &&
7367 stored_player[i].cannot_move)
7369 action_arg_number = STEPSIZE_VERY_SLOW;
7371 else if (action_arg == CA_ARG_SPEED_SLOWER ||
7372 action_arg == CA_ARG_SPEED_FASTER)
7374 action_arg_number = 2;
7375 action_mode = (action_arg == CA_ARG_SPEED_SLOWER ? CA_MODE_DIVIDE :
7380 getModifiedActionNumber(move_stepsize,
7383 action_arg_number_min,
7384 action_arg_number_max);
7387 SetPlayerMoveSpeed(&stored_player[i], move_stepsize, FALSE);
7389 /* make sure that value is power of 2 */
7390 move_stepsize = (1 << log_2(move_stepsize));
7392 /* do no immediately change -- the player might just be moving */
7393 stored_player[i].move_delay_value_next = TILEX / move_stepsize;
7395 stored_player[i].cannot_move =
7396 (action_arg == CA_ARG_SPEED_NOT_MOVING ? TRUE : FALSE);
7404 case CA_SET_PLAYER_SHIELD:
7406 for (i = 0; i < MAX_PLAYERS; i++)
7408 if (trigger_player_bits & (1 << i))
7410 if (action_arg == CA_ARG_SHIELD_OFF)
7412 stored_player[i].shield_normal_time_left = 0;
7413 stored_player[i].shield_deadly_time_left = 0;
7415 else if (action_arg == CA_ARG_SHIELD_NORMAL)
7417 stored_player[i].shield_normal_time_left = 999999;
7419 else if (action_arg == CA_ARG_SHIELD_DEADLY)
7421 stored_player[i].shield_normal_time_left = 999999;
7422 stored_player[i].shield_deadly_time_left = 999999;
7430 case CA_SET_PLAYER_ARTWORK:
7432 for (i = 0; i < MAX_PLAYERS; i++)
7434 if (trigger_player_bits & (1 << i))
7436 int artwork_element = action_arg_element;
7438 if (action_arg == CA_ARG_ELEMENT_RESET)
7440 (level.use_artwork_element[i] ? level.artwork_element[i] :
7441 stored_player[i].element_nr);
7443 stored_player[i].artwork_element = artwork_element;
7445 SetPlayerWaiting(&stored_player[i], FALSE);
7447 /* set number of special actions for bored and sleeping animation */
7448 stored_player[i].num_special_action_bored =
7449 get_num_special_action(artwork_element,
7450 ACTION_BORING_1, ACTION_BORING_LAST);
7451 stored_player[i].num_special_action_sleeping =
7452 get_num_special_action(artwork_element,
7453 ACTION_SLEEPING_1, ACTION_SLEEPING_LAST);
7460 /* ---------- CE actions ---------------------------------------------- */
7462 case CA_SET_CE_SCORE:
7464 ei->collect_score = action_arg_number_new;
7469 case CA_SET_CE_VALUE:
7471 #if USE_NEW_CUSTOM_VALUE
7472 int last_custom_value = CustomValue[x][y];
7474 CustomValue[x][y] = action_arg_number_new;
7477 printf("::: Count == %d\n", CustomValue[x][y]);
7480 if (CustomValue[x][y] == 0 && last_custom_value > 0)
7483 printf("::: CE_VALUE_GETS_ZERO\n");
7486 CheckElementChange(x, y, element, EL_UNDEFINED, CE_VALUE_GETS_ZERO);
7487 CheckTriggeredElementChange(x, y, element, CE_VALUE_GETS_ZERO_OF_X);
7494 /* ---------- engine actions ------------------------------------------ */
7496 case CA_SET_ENGINE_SCAN_MODE:
7498 InitPlayfieldScanMode(action_arg);
7508 static void CreateFieldExt(int x, int y, int element, boolean is_change)
7510 int previous_move_direction = MovDir[x][y];
7511 #if USE_NEW_CUSTOM_VALUE
7512 int last_ce_value = CustomValue[x][y];
7514 boolean add_player = (ELEM_IS_PLAYER(element) &&
7515 IS_WALKABLE(Feld[x][y]));
7517 /* check if element under player changes from accessible to unaccessible
7518 (needed for special case of dropping element which then changes) */
7519 if (IS_PLAYER(x, y) && !PLAYER_EXPLOSION_PROTECTED(x, y) &&
7520 IS_ACCESSIBLE(Feld[x][y]) && !IS_ACCESSIBLE(element))
7529 if (IS_MOVING(x, y) || IS_BLOCKED(x, y))
7530 RemoveMovingField(x, y);
7534 Feld[x][y] = element;
7536 ResetGfxAnimation(x, y);
7537 ResetRandomAnimationValue(x, y);
7539 if (element_info[Feld[x][y]].move_direction_initial == MV_START_PREVIOUS)
7540 MovDir[x][y] = previous_move_direction;
7542 #if USE_NEW_CUSTOM_VALUE
7543 if (element_info[Feld[x][y]].use_last_ce_value)
7544 CustomValue[x][y] = last_ce_value;
7547 InitField_WithBug1(x, y, FALSE);
7549 DrawLevelField(x, y);
7551 if (GFX_CRUMBLED(Feld[x][y]))
7552 DrawLevelFieldCrumbledSandNeighbours(x, y);
7555 /* "ChangeCount" not set yet to allow "entered by player" change one time */
7556 if (ELEM_IS_PLAYER(element))
7557 RelocatePlayer(x, y, element);
7560 ChangeCount[x][y]++; /* count number of changes in the same frame */
7562 TestIfBadThingTouchesPlayer(x, y);
7563 TestIfPlayerTouchesCustomElement(x, y);
7564 TestIfElementTouchesCustomElement(x, y);
7567 static void CreateField(int x, int y, int element)
7569 CreateFieldExt(x, y, element, FALSE);
7572 static void CreateElementFromChange(int x, int y, int element)
7574 CreateFieldExt(x, y, element, TRUE);
7577 static boolean ChangeElement(int x, int y, int element, int page)
7579 struct ElementChangeInfo *change = &element_info[element].change_page[page];
7581 int old_element = Feld[x][y];
7583 /* always use default change event to prevent running into a loop */
7584 if (ChangeEvent[x][y] == -1)
7585 ChangeEvent[x][y] = CE_DELAY;
7587 if (ChangeEvent[x][y] == CE_DELAY)
7589 /* reset actual trigger element, trigger player and action element */
7590 change->actual_trigger_element = EL_EMPTY;
7591 change->actual_trigger_player = EL_PLAYER_1;
7592 change->actual_trigger_side = CH_SIDE_NONE;
7593 change->actual_trigger_ce_value = 0;
7596 /* do not change elements more than a specified maximum number of changes */
7597 if (ChangeCount[x][y] >= game.max_num_changes_per_frame)
7600 ChangeCount[x][y]++; /* count number of changes in the same frame */
7602 if (change->explode)
7609 if (change->use_target_content)
7611 boolean complete_replace = TRUE;
7612 boolean can_replace[3][3];
7615 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7618 boolean is_walkable;
7619 boolean is_diggable;
7620 boolean is_collectible;
7621 boolean is_removable;
7622 boolean is_destructible;
7623 int ex = x + xx - 1;
7624 int ey = y + yy - 1;
7625 int content_element = change->target_content.e[xx][yy];
7628 can_replace[xx][yy] = TRUE;
7630 if (ex == x && ey == y) /* do not check changing element itself */
7633 if (content_element == EL_EMPTY_SPACE)
7635 can_replace[xx][yy] = FALSE; /* do not replace border with space */
7640 if (!IN_LEV_FIELD(ex, ey))
7642 can_replace[xx][yy] = FALSE;
7643 complete_replace = FALSE;
7650 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7651 e = MovingOrBlocked2Element(ex, ey);
7653 is_empty = (IS_FREE(ex, ey) ||
7654 (IS_FREE_OR_PLAYER(ex, ey) && IS_WALKABLE(content_element)));
7656 is_walkable = (is_empty || IS_WALKABLE(e));
7657 is_diggable = (is_empty || IS_DIGGABLE(e));
7658 is_collectible = (is_empty || IS_COLLECTIBLE(e));
7659 is_destructible = (is_empty || !IS_INDESTRUCTIBLE(e));
7660 is_removable = (is_diggable || is_collectible);
7662 can_replace[xx][yy] =
7663 (((change->replace_when == CP_WHEN_EMPTY && is_empty) ||
7664 (change->replace_when == CP_WHEN_WALKABLE && is_walkable) ||
7665 (change->replace_when == CP_WHEN_DIGGABLE && is_diggable) ||
7666 (change->replace_when == CP_WHEN_COLLECTIBLE && is_collectible) ||
7667 (change->replace_when == CP_WHEN_REMOVABLE && is_removable) ||
7668 (change->replace_when == CP_WHEN_DESTRUCTIBLE && is_destructible)) &&
7669 !(IS_PLAYER(ex, ey) && ELEM_IS_PLAYER(content_element)));
7671 if (!can_replace[xx][yy])
7672 complete_replace = FALSE;
7675 if (!change->only_if_complete || complete_replace)
7677 boolean something_has_changed = FALSE;
7679 if (change->only_if_complete && change->use_random_replace &&
7680 RND(100) < change->random_percentage)
7683 for (yy = 0; yy < 3; yy++) for (xx = 0; xx < 3 ; xx++)
7685 int ex = x + xx - 1;
7686 int ey = y + yy - 1;
7687 int content_element;
7689 if (can_replace[xx][yy] && (!change->use_random_replace ||
7690 RND(100) < change->random_percentage))
7692 if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
7693 RemoveMovingField(ex, ey);
7695 ChangeEvent[ex][ey] = ChangeEvent[x][y];
7697 content_element = change->target_content.e[xx][yy];
7698 target_element = GET_TARGET_ELEMENT(content_element, change);
7700 CreateElementFromChange(ex, ey, target_element);
7702 something_has_changed = TRUE;
7704 /* for symmetry reasons, freeze newly created border elements */
7705 if (ex != x || ey != y)
7706 Stop[ex][ey] = TRUE; /* no more moving in this frame */
7710 if (something_has_changed)
7712 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7713 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
7719 target_element = GET_TARGET_ELEMENT(change->target_element, change);
7721 CreateElementFromChange(x, y, target_element);
7723 PlayLevelSoundElementAction(x, y, element, ACTION_CHANGING);
7724 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + page);
7727 /* this uses direct change before indirect change */
7728 CheckTriggeredElementChangeByPage(x, y, old_element, CE_CHANGE_OF_X, page);
7733 #if USE_NEW_DELAYED_ACTION
7735 static void HandleElementChange(int x, int y, int page)
7737 int element = MovingOrBlocked2Element(x, y);
7738 struct ElementInfo *ei = &element_info[element];
7739 struct ElementChangeInfo *change = &ei->change_page[page];
7742 if (!CAN_CHANGE_OR_HAS_ACTION(element) &&
7743 !CAN_CHANGE_OR_HAS_ACTION(Back[x][y]))
7746 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
7747 x, y, element, element_info[element].token_name);
7748 printf("HandleElementChange(): This should never happen!\n");
7753 /* this can happen with classic bombs on walkable, changing elements */
7754 if (!CAN_CHANGE_OR_HAS_ACTION(element))
7757 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7758 ChangeDelay[x][y] = 0;
7764 if (ChangeDelay[x][y] == 0) /* initialize element change */
7766 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
7768 if (change->can_change)
7770 ResetGfxAnimation(x, y);
7771 ResetRandomAnimationValue(x, y);
7773 if (change->pre_change_function)
7774 change->pre_change_function(x, y);
7778 ChangeDelay[x][y]--;
7780 if (ChangeDelay[x][y] != 0) /* continue element change */
7782 if (change->can_change)
7784 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7786 if (IS_ANIMATED(graphic))
7787 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7789 if (change->change_function)
7790 change->change_function(x, y);
7793 else /* finish element change */
7795 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7797 page = ChangePage[x][y];
7798 ChangePage[x][y] = -1;
7800 change = &ei->change_page[page];
7803 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7805 ChangeDelay[x][y] = 1; /* try change after next move step */
7806 ChangePage[x][y] = page; /* remember page to use for change */
7811 if (change->can_change)
7813 if (ChangeElement(x, y, element, page))
7815 if (change->post_change_function)
7816 change->post_change_function(x, y);
7820 if (change->has_action)
7821 ExecuteCustomElementAction(x, y, element, page);
7827 static void HandleElementChange(int x, int y, int page)
7829 int element = MovingOrBlocked2Element(x, y);
7830 struct ElementInfo *ei = &element_info[element];
7831 struct ElementChangeInfo *change = &ei->change_page[page];
7834 if (!CAN_CHANGE(element) && !CAN_CHANGE(Back[x][y]))
7837 printf("HandleElementChange(): %d,%d: element = %d ('%s')\n",
7838 x, y, element, element_info[element].token_name);
7839 printf("HandleElementChange(): This should never happen!\n");
7844 /* this can happen with classic bombs on walkable, changing elements */
7845 if (!CAN_CHANGE(element))
7848 if (!CAN_CHANGE(Back[x][y])) /* prevent permanent repetition */
7849 ChangeDelay[x][y] = 0;
7855 if (ChangeDelay[x][y] == 0) /* initialize element change */
7857 ChangeDelay[x][y] = GET_CHANGE_DELAY(change) + 1;
7859 ResetGfxAnimation(x, y);
7860 ResetRandomAnimationValue(x, y);
7862 if (change->pre_change_function)
7863 change->pre_change_function(x, y);
7866 ChangeDelay[x][y]--;
7868 if (ChangeDelay[x][y] != 0) /* continue element change */
7870 int graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
7872 if (IS_ANIMATED(graphic))
7873 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
7875 if (change->change_function)
7876 change->change_function(x, y);
7878 else /* finish element change */
7880 if (ChangePage[x][y] != -1) /* remember page from delayed change */
7882 page = ChangePage[x][y];
7883 ChangePage[x][y] = -1;
7885 change = &ei->change_page[page];
7888 if (IS_MOVING(x, y)) /* never change a running system ;-) */
7890 ChangeDelay[x][y] = 1; /* try change after next move step */
7891 ChangePage[x][y] = page; /* remember page to use for change */
7896 if (ChangeElement(x, y, element, page))
7898 if (change->post_change_function)
7899 change->post_change_function(x, y);
7906 static boolean CheckTriggeredElementChangeExt(int trigger_x, int trigger_y,
7907 int trigger_element,
7913 boolean change_done_any = FALSE;
7914 int trigger_page_bits = (trigger_page < 0 ? CH_PAGE_ANY : 1 << trigger_page);
7917 if (!(trigger_events[trigger_element][trigger_event]))
7920 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
7922 int element = EL_CUSTOM_START + i;
7923 boolean change_done = FALSE;
7926 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
7927 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
7930 for (p = 0; p < element_info[element].num_change_pages; p++)
7932 struct ElementChangeInfo *change = &element_info[element].change_page[p];
7934 if (change->can_change_or_has_action &&
7935 change->has_event[trigger_event] &&
7936 change->trigger_side & trigger_side &&
7937 change->trigger_player & trigger_player &&
7938 change->trigger_page & trigger_page_bits &&
7939 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element))
7941 change->actual_trigger_element = trigger_element;
7942 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
7943 change->actual_trigger_side = trigger_side;
7944 change->actual_trigger_ce_value = CustomValue[trigger_x][trigger_y];
7946 if ((change->can_change && !change_done) || change->has_action)
7951 SCAN_PLAYFIELD(x, y)
7953 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
7956 if (Feld[x][y] == element)
7958 if (change->can_change && !change_done)
7960 ChangeDelay[x][y] = 1;
7961 ChangeEvent[x][y] = trigger_event;
7963 HandleElementChange(x, y, p);
7965 #if USE_NEW_DELAYED_ACTION
7966 else if (change->has_action)
7968 ExecuteCustomElementAction(x, y, element, p);
7969 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7972 if (change->has_action)
7974 ExecuteCustomElementAction(x, y, element, p);
7975 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
7981 if (change->can_change)
7984 change_done_any = TRUE;
7991 return change_done_any;
7994 static boolean CheckElementChangeExt(int x, int y,
7996 int trigger_element,
8001 boolean change_done = FALSE;
8004 if (!CAN_CHANGE_OR_HAS_ACTION(element) ||
8005 !HAS_ANY_CHANGE_EVENT(element, trigger_event))
8008 if (Feld[x][y] == EL_BLOCKED)
8010 Blocked2Moving(x, y, &x, &y);
8011 element = Feld[x][y];
8014 if (Feld[x][y] != element) /* check if element has already changed */
8017 for (p = 0; p < element_info[element].num_change_pages; p++)
8019 struct ElementChangeInfo *change = &element_info[element].change_page[p];
8021 boolean check_trigger_element =
8022 (trigger_event == CE_TOUCHING_X ||
8023 trigger_event == CE_HITTING_X ||
8024 trigger_event == CE_HIT_BY_X);
8026 if (change->can_change_or_has_action &&
8027 change->has_event[trigger_event] &&
8028 change->trigger_side & trigger_side &&
8029 change->trigger_player & trigger_player &&
8030 (!check_trigger_element ||
8031 IS_EQUAL_OR_IN_GROUP(trigger_element, change->trigger_element)))
8033 change->actual_trigger_element = trigger_element;
8034 change->actual_trigger_player = EL_PLAYER_1 + log_2(trigger_player);
8035 change->actual_trigger_side = trigger_side;
8036 change->actual_trigger_ce_value = CustomValue[x][y];
8038 /* special case: trigger element not at (x,y) position for some events */
8039 if (check_trigger_element)
8051 { 0, 0 }, { 0, 0 }, { 0, 0 },
8055 int xx = x + move_xy[MV_DIR_OPPOSITE(trigger_side)].dx;
8056 int yy = y + move_xy[MV_DIR_OPPOSITE(trigger_side)].dy;
8058 change->actual_trigger_ce_value = CustomValue[xx][yy];
8061 if (change->can_change && !change_done)
8063 ChangeDelay[x][y] = 1;
8064 ChangeEvent[x][y] = trigger_event;
8066 HandleElementChange(x, y, p);
8070 #if USE_NEW_DELAYED_ACTION
8071 else if (change->has_action)
8073 ExecuteCustomElementAction(x, y, element, p);
8074 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8077 if (change->has_action)
8079 ExecuteCustomElementAction(x, y, element, p);
8080 PlayLevelSoundElementAction(x, y, element, ACTION_PAGE_1 + p);
8089 static void PlayPlayerSound(struct PlayerInfo *player)
8091 int jx = player->jx, jy = player->jy;
8092 int sound_element = player->artwork_element;
8093 int last_action = player->last_action_waiting;
8094 int action = player->action_waiting;
8096 if (player->is_waiting)
8098 if (action != last_action)
8099 PlayLevelSoundElementAction(jx, jy, sound_element, action);
8101 PlayLevelSoundElementActionIfLoop(jx, jy, sound_element, action);
8105 if (action != last_action)
8106 StopSound(element_info[sound_element].sound[last_action]);
8108 if (last_action == ACTION_SLEEPING)
8109 PlayLevelSoundElementAction(jx, jy, sound_element, ACTION_AWAKENING);
8113 static void PlayAllPlayersSound()
8117 for (i = 0; i < MAX_PLAYERS; i++)
8118 if (stored_player[i].active)
8119 PlayPlayerSound(&stored_player[i]);
8122 static void SetPlayerWaiting(struct PlayerInfo *player, boolean is_waiting)
8124 boolean last_waiting = player->is_waiting;
8125 int move_dir = player->MovDir;
8127 player->last_action_waiting = player->action_waiting;
8131 if (!last_waiting) /* not waiting -> waiting */
8133 player->is_waiting = TRUE;
8135 player->frame_counter_bored =
8137 game.player_boring_delay_fixed +
8138 SimpleRND(game.player_boring_delay_random);
8139 player->frame_counter_sleeping =
8141 game.player_sleeping_delay_fixed +
8142 SimpleRND(game.player_sleeping_delay_random);
8144 InitPlayerGfxAnimation(player, ACTION_WAITING, player->MovDir);
8147 if (game.player_sleeping_delay_fixed +
8148 game.player_sleeping_delay_random > 0 &&
8149 player->anim_delay_counter == 0 &&
8150 player->post_delay_counter == 0 &&
8151 FrameCounter >= player->frame_counter_sleeping)
8152 player->is_sleeping = TRUE;
8153 else if (game.player_boring_delay_fixed +
8154 game.player_boring_delay_random > 0 &&
8155 FrameCounter >= player->frame_counter_bored)
8156 player->is_bored = TRUE;
8158 player->action_waiting = (player->is_sleeping ? ACTION_SLEEPING :
8159 player->is_bored ? ACTION_BORING :
8162 if (player->is_sleeping)
8164 if (player->num_special_action_sleeping > 0)
8166 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8168 int last_special_action = player->special_action_sleeping;
8169 int num_special_action = player->num_special_action_sleeping;
8170 int special_action =
8171 (last_special_action == ACTION_DEFAULT ? ACTION_SLEEPING_1 :
8172 last_special_action == ACTION_SLEEPING ? ACTION_SLEEPING :
8173 last_special_action < ACTION_SLEEPING_1 + num_special_action - 1 ?
8174 last_special_action + 1 : ACTION_SLEEPING);
8175 int special_graphic =
8176 el_act_dir2img(player->artwork_element, special_action, move_dir);
8178 player->anim_delay_counter =
8179 graphic_info[special_graphic].anim_delay_fixed +
8180 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8181 player->post_delay_counter =
8182 graphic_info[special_graphic].post_delay_fixed +
8183 SimpleRND(graphic_info[special_graphic].post_delay_random);
8185 player->special_action_sleeping = special_action;
8188 if (player->anim_delay_counter > 0)
8190 player->action_waiting = player->special_action_sleeping;
8191 player->anim_delay_counter--;
8193 else if (player->post_delay_counter > 0)
8195 player->post_delay_counter--;
8199 else if (player->is_bored)
8201 if (player->num_special_action_bored > 0)
8203 if (player->anim_delay_counter == 0 && player->post_delay_counter == 0)
8205 int special_action =
8206 ACTION_BORING_1 + SimpleRND(player->num_special_action_bored);
8207 int special_graphic =
8208 el_act_dir2img(player->artwork_element, special_action, move_dir);
8210 player->anim_delay_counter =
8211 graphic_info[special_graphic].anim_delay_fixed +
8212 SimpleRND(graphic_info[special_graphic].anim_delay_random);
8213 player->post_delay_counter =
8214 graphic_info[special_graphic].post_delay_fixed +
8215 SimpleRND(graphic_info[special_graphic].post_delay_random);
8217 player->special_action_bored = special_action;
8220 if (player->anim_delay_counter > 0)
8222 player->action_waiting = player->special_action_bored;
8223 player->anim_delay_counter--;
8225 else if (player->post_delay_counter > 0)
8227 player->post_delay_counter--;
8232 else if (last_waiting) /* waiting -> not waiting */
8234 player->is_waiting = FALSE;
8235 player->is_bored = FALSE;
8236 player->is_sleeping = FALSE;
8238 player->frame_counter_bored = -1;
8239 player->frame_counter_sleeping = -1;
8241 player->anim_delay_counter = 0;
8242 player->post_delay_counter = 0;
8244 player->action_waiting = ACTION_DEFAULT;
8246 player->special_action_bored = ACTION_DEFAULT;
8247 player->special_action_sleeping = ACTION_DEFAULT;
8251 static byte PlayerActions(struct PlayerInfo *player, byte player_action)
8253 boolean moved = FALSE, snapped = FALSE, dropped = FALSE;
8254 int left = player_action & JOY_LEFT;
8255 int right = player_action & JOY_RIGHT;
8256 int up = player_action & JOY_UP;
8257 int down = player_action & JOY_DOWN;
8258 int button1 = player_action & JOY_BUTTON_1;
8259 int button2 = player_action & JOY_BUTTON_2;
8260 int dx = (left ? -1 : right ? 1 : 0);
8261 int dy = (up ? -1 : down ? 1 : 0);
8263 if (!player->active || tape.pausing)
8269 snapped = SnapField(player, dx, dy);
8273 dropped = DropElement(player);
8275 moved = MovePlayer(player, dx, dy);
8278 if (tape.single_step && tape.recording && !tape.pausing)
8280 if (button1 || (dropped && !moved))
8282 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
8283 SnapField(player, 0, 0); /* stop snapping */
8287 SetPlayerWaiting(player, FALSE);
8289 return player_action;
8293 /* no actions for this player (no input at player's configured device) */
8295 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
8296 SnapField(player, 0, 0);
8297 CheckGravityMovementWhenNotMoving(player);
8299 if (player->MovPos == 0)
8300 SetPlayerWaiting(player, TRUE);
8302 if (player->MovPos == 0) /* needed for tape.playing */
8303 player->is_moving = FALSE;
8305 player->is_dropping = FALSE;
8311 void AdvanceFrameAndPlayerCounters(int player_nr)
8315 /* advance frame counters (global frame counter and time frame counter) */
8319 /* advance player counters (counters for move delay, move animation etc.) */
8320 for (i = 0; i < MAX_PLAYERS; i++)
8322 boolean advance_player_counters = (player_nr == -1 || player_nr == i);
8323 int move_delay_value = stored_player[i].move_delay_value;
8324 int move_frames = MOVE_DELAY_NORMAL_SPEED / move_delay_value;
8326 if (!advance_player_counters) /* not all players may be affected */
8329 #if USE_NEW_PLAYER_ANIM
8330 if (move_frames == 0) /* less than one move per game frame */
8332 int stepsize = TILEX / move_delay_value;
8333 int delay = move_delay_value / MOVE_DELAY_NORMAL_SPEED;
8334 int count = (stored_player[i].is_moving ?
8335 ABS(stored_player[i].MovPos) / stepsize : FrameCounter);
8337 if (count % delay == 0)
8342 stored_player[i].Frame += move_frames;
8344 if (stored_player[i].MovPos != 0)
8345 stored_player[i].StepFrame += move_frames;
8347 if (stored_player[i].move_delay > 0)
8348 stored_player[i].move_delay--;
8350 /* due to bugs in previous versions, counter must count up, not down */
8351 if (stored_player[i].push_delay != -1)
8352 stored_player[i].push_delay++;
8354 if (stored_player[i].drop_delay > 0)
8355 stored_player[i].drop_delay--;
8361 static unsigned long game_frame_delay = 0;
8362 unsigned long game_frame_delay_value;
8363 int magic_wall_x = 0, magic_wall_y = 0;
8364 int i, x, y, element, graphic;
8365 byte *recorded_player_action;
8366 byte summarized_player_action = 0;
8367 byte tape_action[MAX_PLAYERS];
8369 if (game_status != GAME_MODE_PLAYING)
8372 game_frame_delay_value =
8373 (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
8375 if (tape.playing && tape.warp_forward && !tape.pausing)
8376 game_frame_delay_value = 0;
8378 /* ---------- main game synchronization point ---------- */
8380 WaitUntilDelayReached(&game_frame_delay, game_frame_delay_value);
8382 InitPlayfieldScanModeVars();
8384 #if USE_ONE_MORE_CHANGE_PER_FRAME
8385 if (game.engine_version >= VERSION_IDENT(3,2,0,7))
8387 SCAN_PLAYFIELD(x, y)
8389 ChangeCount[x][y] = 0;
8390 ChangeEvent[x][y] = -1;
8395 if (network_playing && !network_player_action_received)
8397 /* try to get network player actions in time */
8399 #if defined(NETWORK_AVALIABLE)
8400 /* last chance to get network player actions without main loop delay */
8404 /* game was quit by network peer */
8405 if (game_status != GAME_MODE_PLAYING)
8408 if (!network_player_action_received)
8409 return; /* failed to get network player actions in time */
8415 recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
8418 /* !!! CHECK THIS (tape.pausing is always FALSE here!) !!! */
8419 if (recorded_player_action == NULL && tape.pausing)
8423 for (i = 0; i < MAX_PLAYERS; i++)
8425 summarized_player_action |= stored_player[i].action;
8427 if (!network_playing)
8428 stored_player[i].effective_action = stored_player[i].action;
8431 #if defined(NETWORK_AVALIABLE)
8432 if (network_playing)
8433 SendToServer_MovePlayer(summarized_player_action);
8436 if (!options.network && !setup.team_mode)
8437 local_player->effective_action = summarized_player_action;
8439 if (recorded_player_action != NULL)
8440 for (i = 0; i < MAX_PLAYERS; i++)
8441 stored_player[i].effective_action = recorded_player_action[i];
8443 for (i = 0; i < MAX_PLAYERS; i++)
8445 tape_action[i] = stored_player[i].effective_action;
8447 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8448 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8451 /* only save actions from input devices, but not programmed actions */
8453 TapeRecordAction(tape_action);
8455 for (i = 0; i < MAX_PLAYERS; i++)
8457 int actual_player_action = stored_player[i].effective_action;
8460 /* !!! THIS BREAKS THE FOLLOWING TAPES: !!!
8461 - rnd_equinox_tetrachloride 048
8462 - rnd_equinox_tetrachloride_ii 096
8463 - rnd_emanuel_schmieg 002
8464 - doctor_sloan_ww 001, 020
8466 if (stored_player[i].MovPos == 0)
8467 CheckGravityMovement(&stored_player[i]);
8470 /* overwrite programmed action with tape action */
8471 if (stored_player[i].programmed_action)
8472 actual_player_action = stored_player[i].programmed_action;
8475 PlayerActions(&stored_player[i], actual_player_action);
8477 tape_action[i] = PlayerActions(&stored_player[i], actual_player_action);
8479 if (tape.recording && tape_action[i] && !tape.player_participates[i])
8480 tape.player_participates[i] = TRUE; /* player just appeared from CE */
8483 ScrollPlayer(&stored_player[i], SCROLL_GO_ON);
8486 network_player_action_received = FALSE;
8488 ScrollScreen(NULL, SCROLL_GO_ON);
8490 /* for backwards compatibility, the following code emulates a fixed bug that
8491 occured when pushing elements (causing elements that just made their last
8492 pushing step to already (if possible) make their first falling step in the
8493 same game frame, which is bad); this code is also needed to use the famous
8494 "spring push bug" which is used in older levels and might be wanted to be
8495 used also in newer levels, but in this case the buggy pushing code is only
8496 affecting the "spring" element and no other elements */
8498 if (game.engine_version < VERSION_IDENT(2,2,0,7) || level.use_spring_bug)
8500 for (i = 0; i < MAX_PLAYERS; i++)
8502 struct PlayerInfo *player = &stored_player[i];
8506 if (player->active && player->is_pushing && player->is_moving &&
8508 (game.engine_version < VERSION_IDENT(2,2,0,7) ||
8509 Feld[x][y] == EL_SPRING))
8511 ContinueMoving(x, y);
8513 /* continue moving after pushing (this is actually a bug) */
8514 if (!IS_MOVING(x, y))
8523 SCAN_PLAYFIELD(x, y)
8525 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8528 ChangeCount[x][y] = 0;
8529 ChangeEvent[x][y] = -1;
8531 /* this must be handled before main playfield loop */
8532 if (Feld[x][y] == EL_PLAYER_IS_LEAVING)
8535 if (MovDelay[x][y] <= 0)
8539 #if USE_NEW_SNAP_DELAY
8540 if (Feld[x][y] == EL_ELEMENT_SNAPPING)
8543 if (MovDelay[x][y] <= 0)
8546 DrawLevelField(x, y);
8548 TestIfElementTouchesCustomElement(x, y); /* for empty space */
8554 if (ChangePage[x][y] != -1 && ChangeDelay[x][y] != 1)
8556 printf("GameActions(): x = %d, y = %d: ChangePage != -1\n", x, y);
8557 printf("GameActions(): This should never happen!\n");
8559 ChangePage[x][y] = -1;
8564 if (WasJustMoving[x][y] > 0)
8565 WasJustMoving[x][y]--;
8566 if (WasJustFalling[x][y] > 0)
8567 WasJustFalling[x][y]--;
8568 if (CheckCollision[x][y] > 0)
8569 CheckCollision[x][y]--;
8573 /* reset finished pushing action (not done in ContinueMoving() to allow
8574 continuous pushing animation for elements with zero push delay) */
8575 if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
8577 ResetGfxAnimation(x, y);
8578 DrawLevelField(x, y);
8582 if (IS_BLOCKED(x, y))
8586 Blocked2Moving(x, y, &oldx, &oldy);
8587 if (!IS_MOVING(oldx, oldy))
8589 printf("GameActions(): (BLOCKED => MOVING) context corrupted!\n");
8590 printf("GameActions(): BLOCKED: x = %d, y = %d\n", x, y);
8591 printf("GameActions(): !MOVING: oldx = %d, oldy = %d\n", oldx, oldy);
8592 printf("GameActions(): This should never happen!\n");
8599 SCAN_PLAYFIELD(x, y)
8601 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8604 element = Feld[x][y];
8605 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8608 printf("::: %d,%d\n", x, y);
8610 if (element == EL_ROCK)
8611 printf("::: Yo man! Rocks can fall!\n");
8614 if (graphic_info[graphic].anim_global_sync)
8615 GfxFrame[x][y] = FrameCounter;
8616 else if (ANIM_MODE(graphic) == ANIM_CE_VALUE)
8618 int old_gfx_frame = GfxFrame[x][y];
8620 GfxFrame[x][y] = CustomValue[x][y];
8623 if (GfxFrame[x][y] != old_gfx_frame)
8625 DrawLevelGraphicAnimation(x, y, graphic);
8627 else if (ANIM_MODE(graphic) == ANIM_CE_SCORE)
8629 int old_gfx_frame = GfxFrame[x][y];
8631 GfxFrame[x][y] = element_info[element].collect_score;
8634 if (GfxFrame[x][y] != old_gfx_frame)
8636 DrawLevelGraphicAnimation(x, y, graphic);
8639 if (ANIM_MODE(graphic) == ANIM_RANDOM &&
8640 IS_NEXT_FRAME(GfxFrame[x][y], graphic))
8641 ResetRandomAnimationValue(x, y);
8643 SetRandomAnimationValue(x, y);
8645 PlayLevelSoundActionIfLoop(x, y, GfxAction[x][y]);
8647 if (IS_INACTIVE(element))
8649 if (IS_ANIMATED(graphic))
8650 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8655 /* this may take place after moving, so 'element' may have changed */
8656 if (IS_CHANGING(x, y) &&
8657 (game.engine_version < VERSION_IDENT(3,0,7,1) || !Stop[x][y]))
8659 int page = element_info[element].event_page_nr[CE_DELAY];
8661 HandleElementChange(x, y, ChangePage[x][y] != -1 ? ChangePage[x][y] : page);
8665 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
8669 if (element == EL_CUSTOM_255)
8670 printf("::: ChangeDelay == %d\n", ChangeDelay[x][y]);
8674 HandleElementChange(x, y, page);
8676 if (CAN_CHANGE(element))
8677 HandleElementChange(x, y, page);
8679 if (HAS_ACTION(element))
8680 ExecuteCustomElementAction(x, y, element, page);
8685 element = Feld[x][y];
8686 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8689 if (!IS_MOVING(x, y) && (CAN_FALL(element) || CAN_MOVE(element)))
8693 element = Feld[x][y];
8694 graphic = el_act_dir2img(element, GfxAction[x][y], GfxDir[x][y]);
8696 if (IS_ANIMATED(graphic) &&
8699 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8701 if (IS_GEM(element) || element == EL_SP_INFOTRON)
8702 EdelsteinFunkeln(x, y);
8704 else if ((element == EL_ACID ||
8705 element == EL_EXIT_OPEN ||
8706 element == EL_SP_EXIT_OPEN ||
8707 element == EL_SP_TERMINAL ||
8708 element == EL_SP_TERMINAL_ACTIVE ||
8709 element == EL_EXTRA_TIME ||
8710 element == EL_SHIELD_NORMAL ||
8711 element == EL_SHIELD_DEADLY) &&
8712 IS_ANIMATED(graphic))
8713 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8714 else if (IS_MOVING(x, y))
8715 ContinueMoving(x, y);
8716 else if (IS_ACTIVE_BOMB(element))
8717 CheckDynamite(x, y);
8718 else if (element == EL_AMOEBA_GROWING)
8719 AmoebeWaechst(x, y);
8720 else if (element == EL_AMOEBA_SHRINKING)
8721 AmoebaDisappearing(x, y);
8723 #if !USE_NEW_AMOEBA_CODE
8724 else if (IS_AMOEBALIVE(element))
8725 AmoebeAbleger(x, y);
8728 else if (element == EL_GAME_OF_LIFE || element == EL_BIOMAZE)
8730 else if (element == EL_EXIT_CLOSED)
8732 else if (element == EL_SP_EXIT_CLOSED)
8734 else if (element == EL_EXPANDABLE_WALL_GROWING)
8736 else if (element == EL_EXPANDABLE_WALL ||
8737 element == EL_EXPANDABLE_WALL_HORIZONTAL ||
8738 element == EL_EXPANDABLE_WALL_VERTICAL ||
8739 element == EL_EXPANDABLE_WALL_ANY)
8741 else if (element == EL_FLAMES)
8742 CheckForDragon(x, y);
8743 else if (element == EL_EXPLOSION)
8744 ; /* drawing of correct explosion animation is handled separately */
8745 else if (element == EL_ELEMENT_SNAPPING)
8748 graphic = el_act_dir2img(GfxElement[x][y], GfxAction[x][y],GfxDir[x][y]);
8750 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8753 else if (IS_ANIMATED(graphic) && !IS_CHANGING(x, y))
8754 DrawLevelGraphicAnimationIfNeeded(x, y, graphic);
8757 if (element == EL_CUSTOM_255 ||
8758 element == EL_CUSTOM_256)
8759 DrawLevelGraphicAnimation(x, y, graphic);
8762 if (IS_BELT_ACTIVE(element))
8763 PlayLevelSoundAction(x, y, ACTION_ACTIVE);
8765 if (game.magic_wall_active)
8767 int jx = local_player->jx, jy = local_player->jy;
8769 /* play the element sound at the position nearest to the player */
8770 if ((element == EL_MAGIC_WALL_FULL ||
8771 element == EL_MAGIC_WALL_ACTIVE ||
8772 element == EL_MAGIC_WALL_EMPTYING ||
8773 element == EL_BD_MAGIC_WALL_FULL ||
8774 element == EL_BD_MAGIC_WALL_ACTIVE ||
8775 element == EL_BD_MAGIC_WALL_EMPTYING) &&
8776 ABS(x-jx) + ABS(y-jy) < ABS(magic_wall_x-jx) + ABS(magic_wall_y-jy))
8784 #if USE_NEW_AMOEBA_CODE
8785 /* new experimental amoeba growth stuff */
8786 if (!(FrameCounter % 8))
8788 static unsigned long random = 1684108901;
8790 for (i = 0; i < level.amoeba_speed * 28 / 8; i++)
8792 x = RND(lev_fieldx);
8793 y = RND(lev_fieldy);
8794 element = Feld[x][y];
8796 if (!IS_PLAYER(x,y) &&
8797 (element == EL_EMPTY ||
8798 CAN_GROW_INTO(element) ||
8799 element == EL_QUICKSAND_EMPTY ||
8800 element == EL_ACID_SPLASH_LEFT ||
8801 element == EL_ACID_SPLASH_RIGHT))
8803 if ((IN_LEV_FIELD(x, y-1) && Feld[x][y-1] == EL_AMOEBA_WET) ||
8804 (IN_LEV_FIELD(x-1, y) && Feld[x-1][y] == EL_AMOEBA_WET) ||
8805 (IN_LEV_FIELD(x+1, y) && Feld[x+1][y] == EL_AMOEBA_WET) ||
8806 (IN_LEV_FIELD(x, y+1) && Feld[x][y+1] == EL_AMOEBA_WET))
8807 Feld[x][y] = EL_AMOEBA_DROP;
8810 random = random * 129 + 1;
8816 if (game.explosions_delayed)
8819 game.explosions_delayed = FALSE;
8822 SCAN_PLAYFIELD(x, y)
8824 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8827 element = Feld[x][y];
8829 if (ExplodeField[x][y])
8830 Explode(x, y, EX_PHASE_START, ExplodeField[x][y]);
8831 else if (element == EL_EXPLOSION)
8832 Explode(x, y, ExplodePhase[x][y], EX_TYPE_NORMAL);
8834 ExplodeField[x][y] = EX_TYPE_NONE;
8837 game.explosions_delayed = TRUE;
8840 if (game.magic_wall_active)
8842 if (!(game.magic_wall_time_left % 4))
8844 int element = Feld[magic_wall_x][magic_wall_y];
8846 if (element == EL_BD_MAGIC_WALL_FULL ||
8847 element == EL_BD_MAGIC_WALL_ACTIVE ||
8848 element == EL_BD_MAGIC_WALL_EMPTYING)
8849 PlayLevelSound(magic_wall_x, magic_wall_y, SND_BD_MAGIC_WALL_ACTIVE);
8851 PlayLevelSound(magic_wall_x, magic_wall_y, SND_MAGIC_WALL_ACTIVE);
8854 if (game.magic_wall_time_left > 0)
8856 game.magic_wall_time_left--;
8857 if (!game.magic_wall_time_left)
8860 SCAN_PLAYFIELD(x, y)
8862 for (y = 0; y < lev_fieldy; y++) for (x = 0; x < lev_fieldx; x++)
8865 element = Feld[x][y];
8867 if (element == EL_MAGIC_WALL_ACTIVE ||
8868 element == EL_MAGIC_WALL_FULL)
8870 Feld[x][y] = EL_MAGIC_WALL_DEAD;
8871 DrawLevelField(x, y);
8873 else if (element == EL_BD_MAGIC_WALL_ACTIVE ||
8874 element == EL_BD_MAGIC_WALL_FULL)
8876 Feld[x][y] = EL_BD_MAGIC_WALL_DEAD;
8877 DrawLevelField(x, y);
8881 game.magic_wall_active = FALSE;
8886 if (game.light_time_left > 0)
8888 game.light_time_left--;
8890 if (game.light_time_left == 0)
8891 RedrawAllLightSwitchesAndInvisibleElements();
8894 if (game.timegate_time_left > 0)
8896 game.timegate_time_left--;
8898 if (game.timegate_time_left == 0)
8899 CloseAllOpenTimegates();
8902 if (game.lenses_time_left > 0)
8904 game.lenses_time_left--;
8906 if (game.lenses_time_left == 0)
8907 RedrawAllInvisibleElementsForLenses();
8910 if (game.magnify_time_left > 0)
8912 game.magnify_time_left--;
8914 if (game.magnify_time_left == 0)
8915 RedrawAllInvisibleElementsForMagnifier();
8918 for (i = 0; i < MAX_PLAYERS; i++)
8920 struct PlayerInfo *player = &stored_player[i];
8922 if (SHIELD_ON(player))
8924 if (player->shield_deadly_time_left)
8925 PlayLevelSound(player->jx, player->jy, SND_SHIELD_DEADLY_ACTIVE);
8926 else if (player->shield_normal_time_left)
8927 PlayLevelSound(player->jx, player->jy, SND_SHIELD_NORMAL_ACTIVE);
8931 if (TimeFrames >= FRAMES_PER_SECOND)
8936 for (i = 0; i < MAX_PLAYERS; i++)
8938 struct PlayerInfo *player = &stored_player[i];
8940 if (SHIELD_ON(player))
8942 player->shield_normal_time_left--;
8944 if (player->shield_deadly_time_left > 0)
8945 player->shield_deadly_time_left--;
8949 if (!level.use_step_counter)
8957 if (TimeLeft <= 10 && setup.time_limit)
8958 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
8960 DrawGameValue_Time(TimeLeft);
8962 if (!TimeLeft && setup.time_limit)
8963 for (i = 0; i < MAX_PLAYERS; i++)
8964 KillPlayer(&stored_player[i]);
8966 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
8967 DrawGameValue_Time(TimePlayed);
8970 if (tape.recording || tape.playing)
8971 DrawVideoDisplay(VIDEO_STATE_TIME_ON, TapeTime);
8975 PlayAllPlayersSound();
8977 if (options.debug) /* calculate frames per second */
8979 static unsigned long fps_counter = 0;
8980 static int fps_frames = 0;
8981 unsigned long fps_delay_ms = Counter() - fps_counter;
8985 if (fps_delay_ms >= 500) /* calculate fps every 0.5 seconds */
8987 global.frames_per_second = 1000 * (float)fps_frames / fps_delay_ms;
8990 fps_counter = Counter();
8993 redraw_mask |= REDRAW_FPS;
8996 AdvanceFrameAndPlayerCounters(-1); /* advance counters for all players */
8998 if (local_player->show_envelope != 0 && local_player->MovPos == 0)
9000 ShowEnvelope(local_player->show_envelope - EL_ENVELOPE_1);
9002 local_player->show_envelope = 0;
9005 /* use random number generator in every frame to make it less predictable */
9006 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9010 static boolean AllPlayersInSight(struct PlayerInfo *player, int x, int y)
9012 int min_x = x, min_y = y, max_x = x, max_y = y;
9015 for (i = 0; i < MAX_PLAYERS; i++)
9017 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9019 if (!stored_player[i].active || &stored_player[i] == player)
9022 min_x = MIN(min_x, jx);
9023 min_y = MIN(min_y, jy);
9024 max_x = MAX(max_x, jx);
9025 max_y = MAX(max_y, jy);
9028 return (max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
9031 static boolean AllPlayersInVisibleScreen()
9035 for (i = 0; i < MAX_PLAYERS; i++)
9037 int jx = stored_player[i].jx, jy = stored_player[i].jy;
9039 if (!stored_player[i].active)
9042 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9049 void ScrollLevel(int dx, int dy)
9051 int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
9054 BlitBitmap(drawto_field, drawto_field,
9055 FX + TILEX * (dx == -1) - softscroll_offset,
9056 FY + TILEY * (dy == -1) - softscroll_offset,
9057 SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
9058 SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
9059 FX + TILEX * (dx == 1) - softscroll_offset,
9060 FY + TILEY * (dy == 1) - softscroll_offset);
9064 x = (dx == 1 ? BX1 : BX2);
9065 for (y = BY1; y <= BY2; y++)
9066 DrawScreenField(x, y);
9071 y = (dy == 1 ? BY1 : BY2);
9072 for (x = BX1; x <= BX2; x++)
9073 DrawScreenField(x, y);
9076 redraw_mask |= REDRAW_FIELD;
9079 static boolean canFallDown(struct PlayerInfo *player)
9081 int jx = player->jx, jy = player->jy;
9083 return (IN_LEV_FIELD(jx, jy + 1) &&
9084 (IS_FREE(jx, jy + 1) ||
9085 (Feld[jx][jy + 1] == EL_ACID && player->can_fall_into_acid)) &&
9086 IS_WALKABLE_FROM(Feld[jx][jy], MV_DOWN) &&
9087 !IS_WALKABLE_INSIDE(Feld[jx][jy]));
9090 static boolean canPassField(int x, int y, int move_dir)
9092 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9093 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9094 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9097 int element = Feld[x][y];
9099 return (IS_PASSABLE_FROM(element, opposite_dir) &&
9100 !CAN_MOVE(element) &&
9101 IN_LEV_FIELD(nextx, nexty) && !IS_PLAYER(nextx, nexty) &&
9102 IS_WALKABLE_FROM(Feld[nextx][nexty], move_dir) &&
9103 (level.can_pass_to_walkable || IS_FREE(nextx, nexty)));
9106 static boolean canMoveToValidFieldWithGravity(int x, int y, int move_dir)
9108 int opposite_dir = MV_DIR_OPPOSITE(move_dir);
9109 int dx = (move_dir & MV_LEFT ? -1 : move_dir & MV_RIGHT ? +1 : 0);
9110 int dy = (move_dir & MV_UP ? -1 : move_dir & MV_DOWN ? +1 : 0);
9114 return (IN_LEV_FIELD(newx, newy) && !IS_FREE_OR_PLAYER(newx, newy) &&
9115 IS_GRAVITY_REACHABLE(Feld[newx][newy]) &&
9116 (IS_DIGGABLE(Feld[newx][newy]) ||
9117 IS_WALKABLE_FROM(Feld[newx][newy], opposite_dir) ||
9118 canPassField(newx, newy, move_dir)));
9121 static void CheckGravityMovement(struct PlayerInfo *player)
9123 if (game.gravity && !player->programmed_action)
9125 int move_dir_horizontal = player->effective_action & MV_HORIZONTAL;
9126 int move_dir_vertical = player->effective_action & MV_VERTICAL;
9127 boolean player_is_snapping = player->effective_action & JOY_BUTTON_1;
9128 int jx = player->jx, jy = player->jy;
9129 boolean player_is_moving_to_valid_field =
9130 (!player_is_snapping &&
9131 (canMoveToValidFieldWithGravity(jx, jy, move_dir_horizontal) ||
9132 canMoveToValidFieldWithGravity(jx, jy, move_dir_vertical)));
9133 boolean player_can_fall_down = canFallDown(player);
9135 if (player_can_fall_down &&
9136 !player_is_moving_to_valid_field)
9137 player->programmed_action = MV_DOWN;
9141 static void CheckGravityMovementWhenNotMoving(struct PlayerInfo *player)
9143 return CheckGravityMovement(player);
9145 if (game.gravity && !player->programmed_action)
9147 int jx = player->jx, jy = player->jy;
9148 boolean field_under_player_is_free =
9149 (IN_LEV_FIELD(jx, jy + 1) && IS_FREE(jx, jy + 1));
9150 boolean player_is_standing_on_valid_field =
9151 (IS_WALKABLE_INSIDE(Feld[jx][jy]) ||
9152 (IS_WALKABLE(Feld[jx][jy]) &&
9153 !(element_info[Feld[jx][jy]].access_direction & MV_DOWN)));
9155 if (field_under_player_is_free && !player_is_standing_on_valid_field)
9156 player->programmed_action = MV_DOWN;
9162 -----------------------------------------------------------------------------
9163 dx, dy: direction (non-diagonal) to try to move the player to
9164 real_dx, real_dy: direction as read from input device (can be diagonal)
9167 boolean MovePlayerOneStep(struct PlayerInfo *player,
9168 int dx, int dy, int real_dx, int real_dy)
9170 int jx = player->jx, jy = player->jy;
9171 int new_jx = jx + dx, new_jy = jy + dy;
9172 #if !USE_FIXED_DONT_RUN_INTO
9176 boolean player_can_move = !player->cannot_move;
9178 if (!player->active || (!dx && !dy))
9179 return MF_NO_ACTION;
9181 player->MovDir = (dx < 0 ? MV_LEFT :
9184 dy > 0 ? MV_DOWN : MV_NONE);
9186 if (!IN_LEV_FIELD(new_jx, new_jy))
9187 return MF_NO_ACTION;
9189 if (!player_can_move)
9192 if (player->MovPos == 0)
9194 player->is_moving = FALSE;
9195 player->is_digging = FALSE;
9196 player->is_collecting = FALSE;
9197 player->is_snapping = FALSE;
9198 player->is_pushing = FALSE;
9201 DigField(player, 0, 0, 0, 0, 0, 0, DF_NO_PUSH);
9202 SnapField(player, 0, 0);
9206 return MF_NO_ACTION;
9210 if (!options.network && !AllPlayersInSight(player, new_jx, new_jy))
9211 return MF_NO_ACTION;
9213 #if !USE_FIXED_DONT_RUN_INTO
9214 element = MovingOrBlocked2ElementIfNotLeaving(new_jx, new_jy);
9216 /* (moved to DigField()) */
9217 if (player_can_move && DONT_RUN_INTO(element))
9219 if (element == EL_ACID && dx == 0 && dy == 1)
9221 SplashAcid(new_jx, new_jy);
9222 Feld[jx][jy] = EL_PLAYER_1;
9223 InitMovingField(jx, jy, MV_DOWN);
9224 Store[jx][jy] = EL_ACID;
9225 ContinueMoving(jx, jy);
9229 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
9235 can_move = DigField(player, jx, jy, new_jx, new_jy, real_dx,real_dy, DF_DIG);
9236 if (can_move != MF_MOVING)
9239 /* check if DigField() has caused relocation of the player */
9240 if (player->jx != jx || player->jy != jy)
9241 return MF_NO_ACTION; /* <-- !!! CHECK THIS [-> MF_ACTION ?] !!! */
9243 StorePlayer[jx][jy] = 0;
9244 player->last_jx = jx;
9245 player->last_jy = jy;
9246 player->jx = new_jx;
9247 player->jy = new_jy;
9248 StorePlayer[new_jx][new_jy] = player->element_nr;
9250 if (player->move_delay_value_next != -1)
9252 player->move_delay_value = player->move_delay_value_next;
9253 player->move_delay_value_next = -1;
9257 (dx > 0 || dy > 0 ? -1 : 1) * (TILEX - TILEX / player->move_delay_value);
9259 player->step_counter++;
9261 PlayerVisit[jx][jy] = FrameCounter;
9263 ScrollPlayer(player, SCROLL_INIT);
9268 boolean MovePlayer(struct PlayerInfo *player, int dx, int dy)
9270 int jx = player->jx, jy = player->jy;
9271 int old_jx = jx, old_jy = jy;
9272 int moved = MF_NO_ACTION;
9274 if (!player->active)
9279 if (player->MovPos == 0)
9281 player->is_moving = FALSE;
9282 player->is_digging = FALSE;
9283 player->is_collecting = FALSE;
9284 player->is_snapping = FALSE;
9285 player->is_pushing = FALSE;
9291 if (player->move_delay > 0)
9294 player->move_delay = -1; /* set to "uninitialized" value */
9296 /* store if player is automatically moved to next field */
9297 player->is_auto_moving = (player->programmed_action != MV_NONE);
9299 /* remove the last programmed player action */
9300 player->programmed_action = 0;
9304 /* should only happen if pre-1.2 tape recordings are played */
9305 /* this is only for backward compatibility */
9307 int original_move_delay_value = player->move_delay_value;
9310 printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.2 LEVEL TAPES. [%ld]\n",
9314 /* scroll remaining steps with finest movement resolution */
9315 player->move_delay_value = MOVE_DELAY_NORMAL_SPEED;
9317 while (player->MovPos)
9319 ScrollPlayer(player, SCROLL_GO_ON);
9320 ScrollScreen(NULL, SCROLL_GO_ON);
9322 AdvanceFrameAndPlayerCounters(player->index_nr);
9328 player->move_delay_value = original_move_delay_value;
9331 if (player->last_move_dir & MV_HORIZONTAL)
9333 if (!(moved |= MovePlayerOneStep(player, 0, dy, dx, dy)))
9334 moved |= MovePlayerOneStep(player, dx, 0, dx, dy);
9338 if (!(moved |= MovePlayerOneStep(player, dx, 0, dx, dy)))
9339 moved |= MovePlayerOneStep(player, 0, dy, dx, dy);
9345 if (moved & MF_MOVING && !ScreenMovPos &&
9346 (player == local_player || !options.network))
9348 int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
9349 int offset = (setup.scroll_delay ? 3 : 0);
9351 if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
9353 /* actual player has left the screen -- scroll in that direction */
9354 if (jx != old_jx) /* player has moved horizontally */
9355 scroll_x += (jx - old_jx);
9356 else /* player has moved vertically */
9357 scroll_y += (jy - old_jy);
9361 if (jx != old_jx) /* player has moved horizontally */
9363 if ((player->MovDir == MV_LEFT && scroll_x > jx - MIDPOSX + offset) ||
9364 (player->MovDir == MV_RIGHT && scroll_x < jx - MIDPOSX - offset))
9365 scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
9367 /* don't scroll over playfield boundaries */
9368 if (scroll_x < SBX_Left || scroll_x > SBX_Right)
9369 scroll_x = (scroll_x < SBX_Left ? SBX_Left : SBX_Right);
9371 /* don't scroll more than one field at a time */
9372 scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
9374 /* don't scroll against the player's moving direction */
9375 if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
9376 (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
9377 scroll_x = old_scroll_x;
9379 else /* player has moved vertically */
9381 if ((player->MovDir == MV_UP && scroll_y > jy - MIDPOSY + offset) ||
9382 (player->MovDir == MV_DOWN && scroll_y < jy - MIDPOSY - offset))
9383 scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
9385 /* don't scroll over playfield boundaries */
9386 if (scroll_y < SBY_Upper || scroll_y > SBY_Lower)
9387 scroll_y = (scroll_y < SBY_Upper ? SBY_Upper : SBY_Lower);
9389 /* don't scroll more than one field at a time */
9390 scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
9392 /* don't scroll against the player's moving direction */
9393 if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
9394 (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
9395 scroll_y = old_scroll_y;
9399 if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
9401 if (!options.network && !AllPlayersInVisibleScreen())
9403 scroll_x = old_scroll_x;
9404 scroll_y = old_scroll_y;
9408 ScrollScreen(player, SCROLL_INIT);
9409 ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
9414 player->StepFrame = 0;
9416 if (moved & MF_MOVING)
9418 if (old_jx != jx && old_jy == jy)
9419 player->MovDir = (old_jx < jx ? MV_RIGHT : MV_LEFT);
9420 else if (old_jx == jx && old_jy != jy)
9421 player->MovDir = (old_jy < jy ? MV_DOWN : MV_UP);
9423 DrawLevelField(jx, jy); /* for "crumbled sand" */
9425 player->last_move_dir = player->MovDir;
9426 player->is_moving = TRUE;
9427 player->is_snapping = FALSE;
9428 player->is_switching = FALSE;
9429 player->is_dropping = FALSE;
9433 CheckGravityMovementWhenNotMoving(player);
9435 player->is_moving = FALSE;
9437 /* at this point, the player is allowed to move, but cannot move right now
9438 (e.g. because of something blocking the way) -- ensure that the player
9439 is also allowed to move in the next frame (in old versions before 3.1.1,
9440 the player was forced to wait again for eight frames before next try) */
9442 if (game.engine_version >= VERSION_IDENT(3,1,1,0))
9443 player->move_delay = 0; /* allow direct movement in the next frame */
9446 if (player->move_delay == -1) /* not yet initialized by DigField() */
9447 player->move_delay = player->move_delay_value;
9449 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9451 TestIfPlayerTouchesBadThing(jx, jy);
9452 TestIfPlayerTouchesCustomElement(jx, jy);
9455 if (!player->active)
9456 RemovePlayer(player);
9461 void ScrollPlayer(struct PlayerInfo *player, int mode)
9463 int jx = player->jx, jy = player->jy;
9464 int last_jx = player->last_jx, last_jy = player->last_jy;
9465 int move_stepsize = TILEX / player->move_delay_value;
9467 #if USE_NEW_PLAYER_SPEED
9468 if (!player->active)
9471 if (player->MovPos == 0 && mode == SCROLL_GO_ON) /* player not moving */
9474 if (!player->active || player->MovPos == 0)
9478 if (mode == SCROLL_INIT)
9480 player->actual_frame_counter = FrameCounter;
9481 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9483 if ((player->block_last_field || player->block_delay_adjustment > 0) &&
9484 Feld[last_jx][last_jy] == EL_EMPTY)
9486 int last_field_block_delay = 0; /* start with no blocking at all */
9487 int block_delay_adjustment = player->block_delay_adjustment;
9489 /* if player blocks last field, add delay for exactly one move */
9490 if (player->block_last_field)
9492 last_field_block_delay += player->move_delay_value;
9494 /* when blocking enabled, prevent moving up despite gravity */
9495 if (game.gravity && player->MovDir == MV_UP)
9496 block_delay_adjustment = -1;
9499 /* add block delay adjustment (also possible when not blocking) */
9500 last_field_block_delay += block_delay_adjustment;
9502 Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
9503 MovDelay[last_jx][last_jy] = last_field_block_delay + 1;
9506 #if USE_NEW_PLAYER_SPEED
9507 if (player->MovPos != 0) /* player has not yet reached destination */
9513 else if (!FrameReached(&player->actual_frame_counter, 1))
9517 printf("::: player->MovPos: %d -> %d\n",
9519 player->MovPos + (player->MovPos > 0 ? -1 : 1) * move_stepsize);
9522 #if USE_NEW_PLAYER_SPEED
9523 if (player->MovPos != 0)
9525 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9526 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9528 /* before DrawPlayer() to draw correct player graphic for this case */
9529 if (player->MovPos == 0)
9530 CheckGravityMovement(player);
9533 player->MovPos += (player->MovPos > 0 ? -1 : 1) * move_stepsize;
9534 player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
9536 /* before DrawPlayer() to draw correct player graphic for this case */
9537 if (player->MovPos == 0)
9538 CheckGravityMovement(player);
9541 if (player->MovPos == 0) /* player reached destination field */
9544 printf("::: player reached destination field\n");
9547 if (player->move_delay_reset_counter > 0)
9549 player->move_delay_reset_counter--;
9551 if (player->move_delay_reset_counter == 0)
9553 /* continue with normal speed after quickly moving through gate */
9554 HALVE_PLAYER_SPEED(player);
9556 /* be able to make the next move without delay */
9557 player->move_delay = 0;
9561 player->last_jx = jx;
9562 player->last_jy = jy;
9564 if (Feld[jx][jy] == EL_EXIT_OPEN ||
9565 Feld[jx][jy] == EL_SP_EXIT_OPEN ||
9566 Feld[jx][jy] == EL_SP_EXIT_OPENING) /* <-- special case */
9568 DrawPlayer(player); /* needed here only to cleanup last field */
9569 RemovePlayer(player);
9571 if (local_player->friends_still_needed == 0 ||
9572 IS_SP_ELEMENT(Feld[jx][jy]))
9573 player->LevelSolved = player->GameOver = TRUE;
9576 /* this breaks one level: "machine", level 000 */
9578 int move_direction = player->MovDir;
9579 int enter_side = MV_DIR_OPPOSITE(move_direction);
9580 int leave_side = move_direction;
9581 int old_jx = last_jx;
9582 int old_jy = last_jy;
9583 int old_element = Feld[old_jx][old_jy];
9584 int new_element = Feld[jx][jy];
9586 if (IS_CUSTOM_ELEMENT(old_element))
9587 CheckElementChangeByPlayer(old_jx, old_jy, old_element,
9589 player->index_bit, leave_side);
9591 CheckTriggeredElementChangeByPlayer(old_jx, old_jy, old_element,
9593 player->index_bit, leave_side);
9595 if (IS_CUSTOM_ELEMENT(new_element))
9596 CheckElementChangeByPlayer(jx, jy, new_element, CE_ENTERED_BY_PLAYER,
9597 player->index_bit, enter_side);
9599 CheckTriggeredElementChangeByPlayer(jx, jy, new_element,
9601 player->index_bit, enter_side);
9603 CheckTriggeredElementChangeBySide(jx, jy, player->element_nr,
9604 CE_MOVE_OF_X, move_direction);
9607 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9609 TestIfPlayerTouchesBadThing(jx, jy);
9610 TestIfPlayerTouchesCustomElement(jx, jy);
9612 /* needed because pushed element has not yet reached its destination,
9613 so it would trigger a change event at its previous field location */
9614 if (!player->is_pushing)
9615 TestIfElementTouchesCustomElement(jx, jy); /* for empty space */
9617 if (!player->active)
9618 RemovePlayer(player);
9621 if (level.use_step_counter)
9631 if (TimeLeft <= 10 && setup.time_limit)
9632 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
9634 DrawGameValue_Time(TimeLeft);
9636 if (!TimeLeft && setup.time_limit)
9637 for (i = 0; i < MAX_PLAYERS; i++)
9638 KillPlayer(&stored_player[i]);
9640 else if (level.time == 0 && !AllPlayersGone) /* level w/o time limit */
9641 DrawGameValue_Time(TimePlayed);
9644 if (tape.single_step && tape.recording && !tape.pausing &&
9645 !player->programmed_action)
9646 TapeTogglePause(TAPE_TOGGLE_AUTOMATIC);
9650 void ScrollScreen(struct PlayerInfo *player, int mode)
9652 static unsigned long screen_frame_counter = 0;
9654 if (mode == SCROLL_INIT)
9656 /* set scrolling step size according to actual player's moving speed */
9657 ScrollStepSize = TILEX / player->move_delay_value;
9659 screen_frame_counter = FrameCounter;
9660 ScreenMovDir = player->MovDir;
9661 ScreenMovPos = player->MovPos;
9662 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9665 else if (!FrameReached(&screen_frame_counter, 1))
9670 ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * ScrollStepSize;
9671 ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
9672 redraw_mask |= REDRAW_FIELD;
9675 ScreenMovDir = MV_NONE;
9678 void TestIfPlayerTouchesCustomElement(int x, int y)
9680 static int xy[4][2] =
9687 static int trigger_sides[4][2] =
9689 /* center side border side */
9690 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9691 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9692 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9693 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9695 static int touch_dir[4] =
9702 int center_element = Feld[x][y]; /* should always be non-moving! */
9705 for (i = 0; i < NUM_DIRECTIONS; i++)
9707 int xx = x + xy[i][0];
9708 int yy = y + xy[i][1];
9709 int center_side = trigger_sides[i][0];
9710 int border_side = trigger_sides[i][1];
9713 if (!IN_LEV_FIELD(xx, yy))
9716 if (IS_PLAYER(x, y))
9718 struct PlayerInfo *player = PLAYERINFO(x, y);
9720 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9721 border_element = Feld[xx][yy]; /* may be moving! */
9722 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9723 border_element = Feld[xx][yy];
9724 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9725 border_element = MovingOrBlocked2Element(xx, yy);
9727 continue; /* center and border element do not touch */
9729 CheckElementChangeByPlayer(xx, yy, border_element, CE_TOUCHED_BY_PLAYER,
9730 player->index_bit, border_side);
9731 CheckTriggeredElementChangeByPlayer(xx, yy, border_element,
9732 CE_PLAYER_TOUCHES_X,
9733 player->index_bit, border_side);
9735 else if (IS_PLAYER(xx, yy))
9737 struct PlayerInfo *player = PLAYERINFO(xx, yy);
9739 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
9741 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
9742 continue; /* center and border element do not touch */
9745 CheckElementChangeByPlayer(x, y, center_element, CE_TOUCHED_BY_PLAYER,
9746 player->index_bit, center_side);
9747 CheckTriggeredElementChangeByPlayer(x, y, center_element,
9748 CE_PLAYER_TOUCHES_X,
9749 player->index_bit, center_side);
9755 void TestIfElementTouchesCustomElement(int x, int y)
9757 static int xy[4][2] =
9764 static int trigger_sides[4][2] =
9766 /* center side border side */
9767 { CH_SIDE_TOP, CH_SIDE_BOTTOM }, /* check top */
9768 { CH_SIDE_LEFT, CH_SIDE_RIGHT }, /* check left */
9769 { CH_SIDE_RIGHT, CH_SIDE_LEFT }, /* check right */
9770 { CH_SIDE_BOTTOM, CH_SIDE_TOP } /* check bottom */
9772 static int touch_dir[4] =
9779 boolean change_center_element = FALSE;
9780 int center_element = Feld[x][y]; /* should always be non-moving! */
9783 for (i = 0; i < NUM_DIRECTIONS; i++)
9785 int xx = x + xy[i][0];
9786 int yy = y + xy[i][1];
9787 int center_side = trigger_sides[i][0];
9788 int border_side = trigger_sides[i][1];
9791 if (!IN_LEV_FIELD(xx, yy))
9794 if (game.engine_version < VERSION_IDENT(3,0,7,0))
9795 border_element = Feld[xx][yy]; /* may be moving! */
9796 else if (!IS_MOVING(xx, yy) && !IS_BLOCKED(xx, yy))
9797 border_element = Feld[xx][yy];
9798 else if (MovDir[xx][yy] & touch_dir[i]) /* elements are touching */
9799 border_element = MovingOrBlocked2Element(xx, yy);
9801 continue; /* center and border element do not touch */
9803 /* check for change of center element (but change it only once) */
9804 if (!change_center_element)
9805 change_center_element =
9806 CheckElementChangeBySide(x, y, center_element, border_element,
9807 CE_TOUCHING_X, border_side);
9809 /* check for change of border element */
9810 CheckElementChangeBySide(xx, yy, border_element, center_element,
9811 CE_TOUCHING_X, center_side);
9815 void TestIfElementHitsCustomElement(int x, int y, int direction)
9817 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9818 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9819 int hitx = x + dx, hity = y + dy;
9820 int hitting_element = Feld[x][y];
9821 int touched_element;
9823 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9826 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9827 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9829 if (IN_LEV_FIELD(hitx, hity))
9831 int opposite_direction = MV_DIR_OPPOSITE(direction);
9832 int hitting_side = direction;
9833 int touched_side = opposite_direction;
9834 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9835 MovDir[hitx][hity] != direction ||
9836 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9842 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9843 CE_HITTING_X, touched_side);
9845 CheckElementChangeBySide(hitx, hity, touched_element,
9846 hitting_element, CE_HIT_BY_X, hitting_side);
9848 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
9849 CE_HIT_BY_SOMETHING, opposite_direction);
9853 /* "hitting something" is also true when hitting the playfield border */
9854 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9855 CE_HITTING_SOMETHING, direction);
9859 void TestIfElementSmashesCustomElement(int x, int y, int direction)
9861 int dx = (direction == MV_LEFT ? -1 : direction == MV_RIGHT ? +1 : 0);
9862 int dy = (direction == MV_UP ? -1 : direction == MV_DOWN ? +1 : 0);
9863 int hitx = x + dx, hity = y + dy;
9864 int hitting_element = Feld[x][y];
9865 int touched_element;
9867 boolean object_hit = (IN_LEV_FIELD(hitx, hity) &&
9868 !IS_FREE(hitx, hity) &&
9869 (!IS_MOVING(hitx, hity) ||
9870 MovDir[hitx][hity] != direction ||
9871 ABS(MovPos[hitx][hity]) <= TILEY / 2));
9874 if (IN_LEV_FIELD(hitx, hity) && IS_FREE(hitx, hity))
9878 if (IN_LEV_FIELD(hitx, hity) && !object_hit)
9882 touched_element = (IN_LEV_FIELD(hitx, hity) ?
9883 MovingOrBlocked2Element(hitx, hity) : EL_STEELWALL);
9885 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9886 EP_CAN_SMASH_EVERYTHING, direction);
9888 if (IN_LEV_FIELD(hitx, hity))
9890 int opposite_direction = MV_DIR_OPPOSITE(direction);
9891 int hitting_side = direction;
9892 int touched_side = opposite_direction;
9894 int touched_element = MovingOrBlocked2Element(hitx, hity);
9897 boolean object_hit = (!IS_MOVING(hitx, hity) ||
9898 MovDir[hitx][hity] != direction ||
9899 ABS(MovPos[hitx][hity]) <= TILEY / 2);
9908 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
9909 CE_SMASHED_BY_SOMETHING, opposite_direction);
9911 CheckElementChangeBySide(x, y, hitting_element, touched_element,
9912 CE_OTHER_IS_SMASHING, touched_side);
9914 CheckElementChangeBySide(hitx, hity, touched_element, hitting_element,
9915 CE_OTHER_GETS_SMASHED, hitting_side);
9921 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
9923 int i, kill_x = -1, kill_y = -1;
9925 int bad_element = -1;
9926 static int test_xy[4][2] =
9933 static int test_dir[4] =
9941 for (i = 0; i < NUM_DIRECTIONS; i++)
9943 int test_x, test_y, test_move_dir, test_element;
9945 test_x = good_x + test_xy[i][0];
9946 test_y = good_y + test_xy[i][1];
9948 if (!IN_LEV_FIELD(test_x, test_y))
9952 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
9954 test_element = MovingOrBlocked2ElementIfNotLeaving(test_x, test_y);
9956 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
9957 2nd case: DONT_TOUCH style bad thing does not move away from good thing
9959 if ((DONT_RUN_INTO(test_element) && good_move_dir == test_dir[i]) ||
9960 (DONT_TOUCH(test_element) && test_move_dir != test_dir[i]))
9964 bad_element = test_element;
9970 if (kill_x != -1 || kill_y != -1)
9972 if (IS_PLAYER(good_x, good_y))
9974 struct PlayerInfo *player = PLAYERINFO(good_x, good_y);
9976 if (player->shield_deadly_time_left > 0 &&
9977 !IS_INDESTRUCTIBLE(bad_element))
9978 Bang(kill_x, kill_y);
9979 else if (!PLAYER_ENEMY_PROTECTED(good_x, good_y))
9983 Bang(good_x, good_y);
9987 void TestIfBadThingHitsGoodThing(int bad_x, int bad_y, int bad_move_dir)
9989 int i, kill_x = -1, kill_y = -1;
9990 int bad_element = Feld[bad_x][bad_y];
9991 static int test_xy[4][2] =
9998 static int touch_dir[4] =
10000 MV_LEFT | MV_RIGHT,
10005 static int test_dir[4] =
10013 if (bad_element == EL_EXPLOSION) /* skip just exploding bad things */
10016 for (i = 0; i < NUM_DIRECTIONS; i++)
10018 int test_x, test_y, test_move_dir, test_element;
10020 test_x = bad_x + test_xy[i][0];
10021 test_y = bad_y + test_xy[i][1];
10022 if (!IN_LEV_FIELD(test_x, test_y))
10026 (IS_MOVING(test_x, test_y) ? MovDir[test_x][test_y] : MV_NONE);
10028 test_element = Feld[test_x][test_y];
10030 /* 1st case: good thing is moving towards DONT_RUN_INTO style bad thing;
10031 2nd case: DONT_TOUCH style bad thing does not move away from good thing
10033 if ((DONT_RUN_INTO(bad_element) && bad_move_dir == test_dir[i]) ||
10034 (DONT_TOUCH(bad_element) && test_move_dir != test_dir[i]))
10036 /* good thing is player or penguin that does not move away */
10037 if (IS_PLAYER(test_x, test_y))
10039 struct PlayerInfo *player = PLAYERINFO(test_x, test_y);
10041 if (bad_element == EL_ROBOT && player->is_moving)
10042 continue; /* robot does not kill player if he is moving */
10044 if (game.engine_version >= VERSION_IDENT(3,0,7,0))
10046 if (player->MovPos != 0 && !(player->MovDir & touch_dir[i]))
10047 continue; /* center and border element do not touch */
10054 else if (test_element == EL_PENGUIN)
10063 if (kill_x != -1 || kill_y != -1)
10065 if (IS_PLAYER(kill_x, kill_y))
10067 struct PlayerInfo *player = PLAYERINFO(kill_x, kill_y);
10069 if (player->shield_deadly_time_left > 0 &&
10070 !IS_INDESTRUCTIBLE(bad_element))
10071 Bang(bad_x, bad_y);
10072 else if (!PLAYER_ENEMY_PROTECTED(kill_x, kill_y))
10073 KillPlayer(player);
10076 Bang(kill_x, kill_y);
10080 void TestIfPlayerTouchesBadThing(int x, int y)
10082 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10085 void TestIfPlayerRunsIntoBadThing(int x, int y, int move_dir)
10087 TestIfGoodThingHitsBadThing(x, y, move_dir);
10090 void TestIfBadThingTouchesPlayer(int x, int y)
10092 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10095 void TestIfBadThingRunsIntoPlayer(int x, int y, int move_dir)
10097 TestIfBadThingHitsGoodThing(x, y, move_dir);
10100 void TestIfFriendTouchesBadThing(int x, int y)
10102 TestIfGoodThingHitsBadThing(x, y, MV_NONE);
10105 void TestIfBadThingTouchesFriend(int x, int y)
10107 TestIfBadThingHitsGoodThing(x, y, MV_NONE);
10110 void TestIfBadThingTouchesOtherBadThing(int bad_x, int bad_y)
10112 int i, kill_x = bad_x, kill_y = bad_y;
10113 static int xy[4][2] =
10121 for (i = 0; i < NUM_DIRECTIONS; i++)
10125 x = bad_x + xy[i][0];
10126 y = bad_y + xy[i][1];
10127 if (!IN_LEV_FIELD(x, y))
10130 element = Feld[x][y];
10131 if (IS_AMOEBOID(element) || element == EL_GAME_OF_LIFE ||
10132 element == EL_AMOEBA_GROWING || element == EL_AMOEBA_DROP)
10140 if (kill_x != bad_x || kill_y != bad_y)
10141 Bang(bad_x, bad_y);
10144 void KillPlayer(struct PlayerInfo *player)
10146 int jx = player->jx, jy = player->jy;
10148 if (!player->active)
10151 /* remove accessible field at the player's position */
10152 Feld[jx][jy] = EL_EMPTY;
10154 /* deactivate shield (else Bang()/Explode() would not work right) */
10155 player->shield_normal_time_left = 0;
10156 player->shield_deadly_time_left = 0;
10159 BuryPlayer(player);
10162 static void KillPlayerUnlessEnemyProtected(int x, int y)
10164 if (!PLAYER_ENEMY_PROTECTED(x, y))
10165 KillPlayer(PLAYERINFO(x, y));
10168 static void KillPlayerUnlessExplosionProtected(int x, int y)
10170 if (!PLAYER_EXPLOSION_PROTECTED(x, y))
10171 KillPlayer(PLAYERINFO(x, y));
10174 void BuryPlayer(struct PlayerInfo *player)
10176 int jx = player->jx, jy = player->jy;
10178 if (!player->active)
10181 PlayLevelSoundElementAction(jx, jy, player->artwork_element, ACTION_DYING);
10182 PlayLevelSound(jx, jy, SND_GAME_LOSING);
10184 player->GameOver = TRUE;
10185 RemovePlayer(player);
10188 void RemovePlayer(struct PlayerInfo *player)
10190 int jx = player->jx, jy = player->jy;
10191 int i, found = FALSE;
10193 player->present = FALSE;
10194 player->active = FALSE;
10196 if (!ExplodeField[jx][jy])
10197 StorePlayer[jx][jy] = 0;
10199 if (player->is_moving)
10200 DrawLevelField(player->last_jx, player->last_jy);
10202 for (i = 0; i < MAX_PLAYERS; i++)
10203 if (stored_player[i].active)
10207 AllPlayersGone = TRUE;
10213 #if USE_NEW_SNAP_DELAY
10214 static void setFieldForSnapping(int x, int y, int element, int direction)
10216 struct ElementInfo *ei = &element_info[element];
10217 int direction_bit = MV_DIR_BIT(direction);
10218 int graphic_snapping = ei->direction_graphic[ACTION_SNAPPING][direction_bit];
10219 int action = (graphic_snapping != IMG_EMPTY_SPACE ? ACTION_SNAPPING :
10220 IS_DIGGABLE(element) ? ACTION_DIGGING : ACTION_COLLECTING);
10222 Feld[x][y] = EL_ELEMENT_SNAPPING;
10223 MovDelay[x][y] = MOVE_DELAY_NORMAL_SPEED + 1 - 1;
10225 ResetGfxAnimation(x, y);
10227 GfxElement[x][y] = element;
10228 GfxAction[x][y] = action;
10229 GfxDir[x][y] = direction;
10230 GfxFrame[x][y] = -1;
10235 =============================================================================
10236 checkDiagonalPushing()
10237 -----------------------------------------------------------------------------
10238 check if diagonal input device direction results in pushing of object
10239 (by checking if the alternative direction is walkable, diggable, ...)
10240 =============================================================================
10243 static boolean checkDiagonalPushing(struct PlayerInfo *player,
10244 int x, int y, int real_dx, int real_dy)
10246 int jx, jy, dx, dy, xx, yy;
10248 if (real_dx == 0 || real_dy == 0) /* no diagonal direction => push */
10251 /* diagonal direction: check alternative direction */
10256 xx = jx + (dx == 0 ? real_dx : 0);
10257 yy = jy + (dy == 0 ? real_dy : 0);
10259 return (!IN_LEV_FIELD(xx, yy) || IS_SOLID_FOR_PUSHING(Feld[xx][yy]));
10263 =============================================================================
10265 -----------------------------------------------------------------------------
10266 x, y: field next to player (non-diagonal) to try to dig to
10267 real_dx, real_dy: direction as read from input device (can be diagonal)
10268 =============================================================================
10271 int DigField(struct PlayerInfo *player,
10272 int oldx, int oldy, int x, int y,
10273 int real_dx, int real_dy, int mode)
10275 boolean is_player = (IS_PLAYER(oldx, oldy) || mode != DF_DIG);
10276 boolean player_was_pushing = player->is_pushing;
10277 boolean player_can_move = (!player->cannot_move && mode != DF_SNAP);
10278 boolean player_can_move_or_snap = (!player->cannot_move || mode == DF_SNAP);
10279 int jx = oldx, jy = oldy;
10280 int dx = x - jx, dy = y - jy;
10281 int nextx = x + dx, nexty = y + dy;
10282 int move_direction = (dx == -1 ? MV_LEFT :
10283 dx == +1 ? MV_RIGHT :
10285 dy == +1 ? MV_DOWN : MV_NONE);
10286 int opposite_direction = MV_DIR_OPPOSITE(move_direction);
10287 int dig_side = MV_DIR_OPPOSITE(move_direction);
10288 int old_element = Feld[jx][jy];
10289 #if USE_FIXED_DONT_RUN_INTO
10290 int element = MovingOrBlocked2ElementIfNotLeaving(x, y);
10296 if (is_player) /* function can also be called by EL_PENGUIN */
10298 if (player->MovPos == 0)
10300 player->is_digging = FALSE;
10301 player->is_collecting = FALSE;
10304 if (player->MovPos == 0) /* last pushing move finished */
10305 player->is_pushing = FALSE;
10307 if (mode == DF_NO_PUSH) /* player just stopped pushing */
10309 player->is_switching = FALSE;
10310 player->push_delay = -1;
10312 return MF_NO_ACTION;
10316 #if !USE_FIXED_DONT_RUN_INTO
10317 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10318 return MF_NO_ACTION;
10321 if (IS_TUBE(Back[jx][jy]) && game.engine_version >= VERSION_IDENT(2,2,0,0))
10322 old_element = Back[jx][jy];
10324 /* in case of element dropped at player position, check background */
10325 else if (Back[jx][jy] != EL_EMPTY &&
10326 game.engine_version >= VERSION_IDENT(2,2,0,0))
10327 old_element = Back[jx][jy];
10329 if (IS_WALKABLE(old_element) && !ACCESS_FROM(old_element, move_direction))
10330 return MF_NO_ACTION; /* field has no opening in this direction */
10332 if (IS_PASSABLE(old_element) && !ACCESS_FROM(old_element,opposite_direction))
10333 return MF_NO_ACTION; /* field has no opening in this direction */
10335 #if USE_FIXED_DONT_RUN_INTO
10336 if (player_can_move && DONT_RUN_INTO(element))
10338 if (element == EL_ACID && dx == 0 && dy == 1)
10341 Feld[jx][jy] = EL_PLAYER_1;
10342 InitMovingField(jx, jy, MV_DOWN);
10343 Store[jx][jy] = EL_ACID;
10344 ContinueMoving(jx, jy);
10345 BuryPlayer(player);
10348 TestIfPlayerRunsIntoBadThing(jx, jy, player->MovDir);
10350 return MF_NO_ACTION;
10354 #if USE_FIXED_DONT_RUN_INTO
10355 if (IS_MOVING(x, y) || IS_PLAYER(x, y))
10356 return MF_NO_ACTION;
10359 #if !USE_FIXED_DONT_RUN_INTO
10360 element = Feld[x][y];
10363 collect_count = element_info[element].collect_count_initial;
10365 if (!is_player && !IS_COLLECTIBLE(element)) /* penguin cannot collect it */
10366 return MF_NO_ACTION;
10368 if (mode == DF_SNAP && !IS_SNAPPABLE(element) &&
10369 game.engine_version >= VERSION_IDENT(2,2,0,0))
10371 CheckElementChangeByPlayer(x, y, element, CE_SNAPPED_BY_PLAYER,
10372 player->index_bit, dig_side);
10373 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
10374 player->index_bit, dig_side);
10376 if (Feld[x][y] != element) /* field changed by snapping */
10379 return MF_NO_ACTION;
10382 if (game.gravity && is_player && !player->is_auto_moving &&
10383 canFallDown(player) && move_direction != MV_DOWN &&
10384 !canMoveToValidFieldWithGravity(jx, jy, move_direction))
10385 return MF_NO_ACTION; /* player cannot walk here due to gravity */
10387 if (player_can_move &&
10388 IS_WALKABLE(element) && ACCESS_FROM(element, opposite_direction))
10390 int sound_element = SND_ELEMENT(element);
10391 int sound_action = ACTION_WALKING;
10393 if (IS_RND_GATE(element))
10395 if (!player->key[RND_GATE_NR(element)])
10396 return MF_NO_ACTION;
10398 else if (IS_RND_GATE_GRAY(element))
10400 if (!player->key[RND_GATE_GRAY_NR(element)])
10401 return MF_NO_ACTION;
10403 else if (IS_RND_GATE_GRAY_ACTIVE(element))
10405 if (!player->key[RND_GATE_GRAY_ACTIVE_NR(element)])
10406 return MF_NO_ACTION;
10408 else if (element == EL_EXIT_OPEN ||
10409 element == EL_SP_EXIT_OPEN ||
10410 element == EL_SP_EXIT_OPENING)
10412 sound_action = ACTION_PASSING; /* player is passing exit */
10414 else if (element == EL_EMPTY)
10416 sound_action = ACTION_MOVING; /* nothing to walk on */
10419 /* play sound from background or player, whatever is available */
10420 if (element_info[sound_element].sound[sound_action] != SND_UNDEFINED)
10421 PlayLevelSoundElementAction(x, y, sound_element, sound_action);
10423 PlayLevelSoundElementAction(x, y, player->artwork_element, sound_action);
10425 else if (player_can_move &&
10426 IS_PASSABLE(element) && canPassField(x, y, move_direction))
10428 if (!ACCESS_FROM(element, opposite_direction))
10429 return MF_NO_ACTION; /* field not accessible from this direction */
10431 if (CAN_MOVE(element)) /* only fixed elements can be passed! */
10432 return MF_NO_ACTION;
10434 if (IS_EM_GATE(element))
10436 if (!player->key[EM_GATE_NR(element)])
10437 return MF_NO_ACTION;
10439 else if (IS_EM_GATE_GRAY(element))
10441 if (!player->key[EM_GATE_GRAY_NR(element)])
10442 return MF_NO_ACTION;
10444 else if (IS_EM_GATE_GRAY_ACTIVE(element))
10446 if (!player->key[EM_GATE_GRAY_ACTIVE_NR(element)])
10447 return MF_NO_ACTION;
10449 else if (IS_SP_PORT(element))
10451 if (element == EL_SP_GRAVITY_PORT_LEFT ||
10452 element == EL_SP_GRAVITY_PORT_RIGHT ||
10453 element == EL_SP_GRAVITY_PORT_UP ||
10454 element == EL_SP_GRAVITY_PORT_DOWN)
10455 game.gravity = !game.gravity;
10456 else if (element == EL_SP_GRAVITY_ON_PORT_LEFT ||
10457 element == EL_SP_GRAVITY_ON_PORT_RIGHT ||
10458 element == EL_SP_GRAVITY_ON_PORT_UP ||
10459 element == EL_SP_GRAVITY_ON_PORT_DOWN)
10460 game.gravity = TRUE;
10461 else if (element == EL_SP_GRAVITY_OFF_PORT_LEFT ||
10462 element == EL_SP_GRAVITY_OFF_PORT_RIGHT ||
10463 element == EL_SP_GRAVITY_OFF_PORT_UP ||
10464 element == EL_SP_GRAVITY_OFF_PORT_DOWN)
10465 game.gravity = FALSE;
10468 /* automatically move to the next field with double speed */
10469 player->programmed_action = move_direction;
10471 if (player->move_delay_reset_counter == 0)
10473 player->move_delay_reset_counter = 2; /* two double speed steps */
10475 DOUBLE_PLAYER_SPEED(player);
10478 PlayLevelSoundAction(x, y, ACTION_PASSING);
10480 else if (player_can_move_or_snap && IS_DIGGABLE(element))
10484 if (mode != DF_SNAP)
10486 GfxElement[x][y] = GFX_ELEMENT(element);
10487 player->is_digging = TRUE;
10490 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
10492 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_DIGS_X,
10493 player->index_bit, dig_side);
10495 if (mode == DF_SNAP)
10497 #if USE_NEW_SNAP_DELAY
10498 if (level.block_snap_field)
10499 setFieldForSnapping(x, y, element, move_direction);
10501 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10503 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10506 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
10507 player->index_bit, dig_side);
10510 else if (player_can_move_or_snap && IS_COLLECTIBLE(element))
10514 if (is_player && mode != DF_SNAP)
10516 GfxElement[x][y] = element;
10517 player->is_collecting = TRUE;
10520 if (element == EL_SPEED_PILL)
10522 player->move_delay_value = MOVE_DELAY_HIGH_SPEED;
10524 else if (element == EL_EXTRA_TIME && level.time > 0)
10526 TimeLeft += level.extra_time;
10527 DrawGameValue_Time(TimeLeft);
10529 else if (element == EL_SHIELD_NORMAL || element == EL_SHIELD_DEADLY)
10531 player->shield_normal_time_left += level.shield_normal_time;
10532 if (element == EL_SHIELD_DEADLY)
10533 player->shield_deadly_time_left += level.shield_deadly_time;
10535 else if (element == EL_DYNAMITE || element == EL_SP_DISK_RED)
10537 if (player->inventory_size < MAX_INVENTORY_SIZE)
10538 player->inventory_element[player->inventory_size++] = element;
10540 DrawGameValue_Dynamite(local_player->inventory_size);
10542 else if (element == EL_DYNABOMB_INCREASE_NUMBER)
10544 player->dynabomb_count++;
10545 player->dynabombs_left++;
10547 else if (element == EL_DYNABOMB_INCREASE_SIZE)
10549 player->dynabomb_size++;
10551 else if (element == EL_DYNABOMB_INCREASE_POWER)
10553 player->dynabomb_xl = TRUE;
10555 else if (IS_KEY(element))
10557 player->key[KEY_NR(element)] = TRUE;
10559 DrawGameValue_Keys(player->key);
10561 redraw_mask |= REDRAW_DOOR_1;
10563 else if (IS_ENVELOPE(element))
10565 player->show_envelope = element;
10567 else if (element == EL_EMC_LENSES)
10569 game.lenses_time_left = level.lenses_time * FRAMES_PER_SECOND;
10571 RedrawAllInvisibleElementsForLenses();
10573 else if (element == EL_EMC_MAGNIFIER)
10575 game.magnify_time_left = level.magnify_time * FRAMES_PER_SECOND;
10577 RedrawAllInvisibleElementsForMagnifier();
10579 else if (IS_DROPPABLE(element) ||
10580 IS_THROWABLE(element)) /* can be collected and dropped */
10584 if (collect_count == 0)
10585 player->inventory_infinite_element = element;
10587 for (i = 0; i < collect_count; i++)
10588 if (player->inventory_size < MAX_INVENTORY_SIZE)
10589 player->inventory_element[player->inventory_size++] = element;
10591 DrawGameValue_Dynamite(local_player->inventory_size);
10593 else if (collect_count > 0)
10595 local_player->gems_still_needed -= collect_count;
10596 if (local_player->gems_still_needed < 0)
10597 local_player->gems_still_needed = 0;
10599 DrawGameValue_Emeralds(local_player->gems_still_needed);
10602 RaiseScoreElement(element);
10603 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
10606 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_COLLECTS_X,
10607 player->index_bit, dig_side);
10609 if (mode == DF_SNAP)
10611 #if USE_NEW_SNAP_DELAY
10612 if (level.block_snap_field)
10613 setFieldForSnapping(x, y, element, move_direction);
10615 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10617 TestIfElementTouchesCustomElement(x, y); /* for empty space */
10620 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X,
10621 player->index_bit, dig_side);
10624 else if (player_can_move_or_snap && IS_PUSHABLE(element))
10626 if (mode == DF_SNAP && element != EL_BD_ROCK)
10627 return MF_NO_ACTION;
10629 if (CAN_FALL(element) && dy)
10630 return MF_NO_ACTION;
10632 if (CAN_FALL(element) && IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1) &&
10633 !(element == EL_SPRING && level.use_spring_bug))
10634 return MF_NO_ACTION;
10636 if (CAN_MOVE(element) && GET_MAX_MOVE_DELAY(element) == 0 &&
10637 ((move_direction & MV_VERTICAL &&
10638 ((element_info[element].move_pattern & MV_LEFT &&
10639 IN_LEV_FIELD(x - 1, y) && IS_FREE(x - 1, y)) ||
10640 (element_info[element].move_pattern & MV_RIGHT &&
10641 IN_LEV_FIELD(x + 1, y) && IS_FREE(x + 1, y)))) ||
10642 (move_direction & MV_HORIZONTAL &&
10643 ((element_info[element].move_pattern & MV_UP &&
10644 IN_LEV_FIELD(x, y - 1) && IS_FREE(x, y - 1)) ||
10645 (element_info[element].move_pattern & MV_DOWN &&
10646 IN_LEV_FIELD(x, y + 1) && IS_FREE(x, y + 1))))))
10647 return MF_NO_ACTION;
10649 /* do not push elements already moving away faster than player */
10650 if (CAN_MOVE(element) && MovDir[x][y] == move_direction &&
10651 ABS(getElementMoveStepsize(x, y)) > MOVE_STEPSIZE_NORMAL)
10652 return MF_NO_ACTION;
10654 if (game.engine_version >= VERSION_IDENT(3,1,0,0))
10656 if (player->push_delay_value == -1 || !player_was_pushing)
10657 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10659 else if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10661 if (player->push_delay_value == -1)
10662 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10664 else if (game.engine_version >= VERSION_IDENT(2,2,0,7))
10666 if (!player->is_pushing)
10667 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10670 player->is_pushing = TRUE;
10672 if (!(IN_LEV_FIELD(nextx, nexty) &&
10673 (IS_FREE(nextx, nexty) ||
10674 (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY &&
10675 IS_SB_ELEMENT(element)))))
10676 return MF_NO_ACTION;
10678 if (!checkDiagonalPushing(player, x, y, real_dx, real_dy))
10679 return MF_NO_ACTION;
10681 if (player->push_delay == -1) /* new pushing; restart delay */
10682 player->push_delay = 0;
10684 if (player->push_delay < player->push_delay_value &&
10685 !(tape.playing && tape.file_version < FILE_VERSION_2_0) &&
10686 element != EL_SPRING && element != EL_BALLOON)
10688 /* make sure that there is no move delay before next try to push */
10689 if (game.engine_version >= VERSION_IDENT(3,0,7,1))
10690 player->move_delay = 0;
10692 return MF_NO_ACTION;
10695 if (IS_SB_ELEMENT(element))
10697 if (element == EL_SOKOBAN_FIELD_FULL)
10699 Back[x][y] = EL_SOKOBAN_FIELD_EMPTY;
10700 local_player->sokobanfields_still_needed++;
10703 if (Feld[nextx][nexty] == EL_SOKOBAN_FIELD_EMPTY)
10705 Back[nextx][nexty] = EL_SOKOBAN_FIELD_EMPTY;
10706 local_player->sokobanfields_still_needed--;
10709 Feld[x][y] = EL_SOKOBAN_OBJECT;
10711 if (Back[x][y] == Back[nextx][nexty])
10712 PlayLevelSoundAction(x, y, ACTION_PUSHING);
10713 else if (Back[x][y] != 0)
10714 PlayLevelSoundElementAction(x, y, EL_SOKOBAN_FIELD_FULL,
10717 PlayLevelSoundElementAction(nextx, nexty, EL_SOKOBAN_FIELD_EMPTY,
10720 if (local_player->sokobanfields_still_needed == 0 &&
10721 game.emulation == EMU_SOKOBAN)
10723 player->LevelSolved = player->GameOver = TRUE;
10724 PlayLevelSound(x, y, SND_GAME_SOKOBAN_SOLVING);
10728 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
10730 InitMovingField(x, y, move_direction);
10731 GfxAction[x][y] = ACTION_PUSHING;
10733 if (mode == DF_SNAP)
10734 ContinueMoving(x, y);
10736 MovPos[x][y] = (dx != 0 ? dx : dy);
10738 Pushed[x][y] = TRUE;
10739 Pushed[nextx][nexty] = TRUE;
10741 if (game.engine_version < VERSION_IDENT(2,2,0,7))
10742 player->push_delay_value = GET_NEW_PUSH_DELAY(element);
10744 player->push_delay_value = -1; /* get new value later */
10746 /* check for element change _after_ element has been pushed */
10747 if (game.use_change_when_pushing_bug)
10749 CheckElementChangeByPlayer(x, y, element, CE_PUSHED_BY_PLAYER,
10750 player->index_bit, dig_side);
10751 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PUSHES_X,
10752 player->index_bit, dig_side);
10755 else if (IS_SWITCHABLE(element))
10757 if (PLAYER_SWITCHING(player, x, y))
10759 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
10760 player->index_bit, dig_side);
10765 player->is_switching = TRUE;
10766 player->switch_x = x;
10767 player->switch_y = y;
10769 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
10771 if (element == EL_ROBOT_WHEEL)
10773 Feld[x][y] = EL_ROBOT_WHEEL_ACTIVE;
10777 DrawLevelField(x, y);
10779 else if (element == EL_SP_TERMINAL)
10784 SCAN_PLAYFIELD(xx, yy)
10786 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
10789 if (Feld[xx][yy] == EL_SP_DISK_YELLOW)
10791 else if (Feld[xx][yy] == EL_SP_TERMINAL)
10792 Feld[xx][yy] = EL_SP_TERMINAL_ACTIVE;
10795 else if (IS_BELT_SWITCH(element))
10797 ToggleBeltSwitch(x, y);
10799 else if (element == EL_SWITCHGATE_SWITCH_UP ||
10800 element == EL_SWITCHGATE_SWITCH_DOWN)
10802 ToggleSwitchgateSwitch(x, y);
10804 else if (element == EL_LIGHT_SWITCH ||
10805 element == EL_LIGHT_SWITCH_ACTIVE)
10807 ToggleLightSwitch(x, y);
10809 else if (element == EL_TIMEGATE_SWITCH)
10811 ActivateTimegateSwitch(x, y);
10813 else if (element == EL_BALLOON_SWITCH_LEFT ||
10814 element == EL_BALLOON_SWITCH_RIGHT ||
10815 element == EL_BALLOON_SWITCH_UP ||
10816 element == EL_BALLOON_SWITCH_DOWN ||
10817 element == EL_BALLOON_SWITCH_NONE ||
10818 element == EL_BALLOON_SWITCH_ANY)
10820 game.wind_direction = (element == EL_BALLOON_SWITCH_LEFT ? MV_LEFT :
10821 element == EL_BALLOON_SWITCH_RIGHT ? MV_RIGHT :
10822 element == EL_BALLOON_SWITCH_UP ? MV_UP :
10823 element == EL_BALLOON_SWITCH_DOWN ? MV_DOWN :
10824 element == EL_BALLOON_SWITCH_NONE ? MV_NONE :
10827 else if (element == EL_LAMP)
10829 Feld[x][y] = EL_LAMP_ACTIVE;
10830 local_player->lights_still_needed--;
10832 ResetGfxAnimation(x, y);
10833 DrawLevelField(x, y);
10835 else if (element == EL_TIME_ORB_FULL)
10837 Feld[x][y] = EL_TIME_ORB_EMPTY;
10839 if (level.time > 0 || level.use_time_orb_bug)
10841 TimeLeft += level.time_orb_time;
10842 DrawGameValue_Time(TimeLeft);
10845 ResetGfxAnimation(x, y);
10846 DrawLevelField(x, y);
10848 else if (element == EL_EMC_MAGIC_BALL_SWITCH ||
10849 element == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
10853 game.ball_state = !game.ball_state;
10856 SCAN_PLAYFIELD(xx, yy)
10858 for (yy = 0; yy < lev_fieldy; yy++) for (xx = 0; xx < lev_fieldx; xx++)
10861 int e = Feld[xx][yy];
10863 if (game.ball_state)
10865 if (e == EL_EMC_MAGIC_BALL)
10866 CreateField(xx, yy, EL_EMC_MAGIC_BALL_ACTIVE);
10867 else if (e == EL_EMC_MAGIC_BALL_SWITCH)
10868 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH_ACTIVE);
10872 if (e == EL_EMC_MAGIC_BALL_ACTIVE)
10873 CreateField(xx, yy, EL_EMC_MAGIC_BALL);
10874 else if (e == EL_EMC_MAGIC_BALL_SWITCH_ACTIVE)
10875 CreateField(xx, yy, EL_EMC_MAGIC_BALL_SWITCH);
10880 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
10881 player->index_bit, dig_side);
10883 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
10884 player->index_bit, dig_side);
10886 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
10887 player->index_bit, dig_side);
10893 if (!PLAYER_SWITCHING(player, x, y))
10895 player->is_switching = TRUE;
10896 player->switch_x = x;
10897 player->switch_y = y;
10899 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED,
10900 player->index_bit, dig_side);
10901 CheckTriggeredElementChangeByPlayer(x, y, element, CE_SWITCH_OF_X,
10902 player->index_bit, dig_side);
10904 CheckElementChangeByPlayer(x, y, element, CE_SWITCHED_BY_PLAYER,
10905 player->index_bit, dig_side);
10906 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SWITCHES_X,
10907 player->index_bit, dig_side);
10910 CheckElementChangeByPlayer(x, y, element, CE_PRESSED_BY_PLAYER,
10911 player->index_bit, dig_side);
10912 CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_PRESSES_X,
10913 player->index_bit, dig_side);
10915 return MF_NO_ACTION;
10918 player->push_delay = -1;
10920 if (is_player) /* function can also be called by EL_PENGUIN */
10922 if (Feld[x][y] != element) /* really digged/collected something */
10923 player->is_collecting = !player->is_digging;
10929 boolean SnapField(struct PlayerInfo *player, int dx, int dy)
10931 int jx = player->jx, jy = player->jy;
10932 int x = jx + dx, y = jy + dy;
10933 int snap_direction = (dx == -1 ? MV_LEFT :
10934 dx == +1 ? MV_RIGHT :
10936 dy == +1 ? MV_DOWN : MV_NONE);
10938 if (player->MovPos != 0 && game.engine_version >= VERSION_IDENT(2,2,0,0))
10941 if (!player->active || !IN_LEV_FIELD(x, y))
10949 if (player->MovPos == 0)
10950 player->is_pushing = FALSE;
10952 player->is_snapping = FALSE;
10954 if (player->MovPos == 0)
10956 player->is_moving = FALSE;
10957 player->is_digging = FALSE;
10958 player->is_collecting = FALSE;
10964 if (player->is_snapping)
10967 player->MovDir = snap_direction;
10969 if (player->MovPos == 0)
10971 player->is_moving = FALSE;
10972 player->is_digging = FALSE;
10973 player->is_collecting = FALSE;
10976 player->is_dropping = FALSE;
10978 if (DigField(player, jx, jy, x, y, 0, 0, DF_SNAP) == MF_NO_ACTION)
10981 player->is_snapping = TRUE;
10983 if (player->MovPos == 0)
10985 player->is_moving = FALSE;
10986 player->is_digging = FALSE;
10987 player->is_collecting = FALSE;
10990 if (player->MovPos != 0) /* prevent graphic bugs in versions < 2.2.0 */
10991 DrawLevelField(player->last_jx, player->last_jy);
10993 DrawLevelField(x, y);
10998 boolean DropElement(struct PlayerInfo *player)
11000 int old_element, new_element;
11001 int dropx = player->jx, dropy = player->jy;
11002 int drop_direction = player->MovDir;
11003 int drop_side = drop_direction;
11004 int drop_element = (player->inventory_size > 0 ?
11005 player->inventory_element[player->inventory_size - 1] :
11006 player->inventory_infinite_element != EL_UNDEFINED ?
11007 player->inventory_infinite_element :
11008 player->dynabombs_left > 0 ?
11009 EL_DYNABOMB_PLAYER_1_ACTIVE + player->index_nr :
11012 /* do not drop an element on top of another element; when holding drop key
11013 pressed without moving, dropped element must move away before the next
11014 element can be dropped (this is especially important if the next element
11015 is dynamite, which can be placed on background for historical reasons) */
11016 if (PLAYER_DROPPING(player, dropx, dropy) && Feld[dropx][dropy] != EL_EMPTY)
11019 if (IS_THROWABLE(drop_element))
11021 dropx += GET_DX_FROM_DIR(drop_direction);
11022 dropy += GET_DY_FROM_DIR(drop_direction);
11024 if (!IN_LEV_FIELD(dropx, dropy))
11028 old_element = Feld[dropx][dropy]; /* old element at dropping position */
11029 new_element = drop_element; /* default: no change when dropping */
11031 /* check if player is active, not moving and ready to drop */
11032 if (!player->active || player->MovPos || player->drop_delay > 0)
11035 /* check if player has anything that can be dropped */
11036 if (new_element == EL_UNDEFINED)
11039 /* check if anything can be dropped at the current position */
11040 if (IS_ACTIVE_BOMB(old_element) || old_element == EL_EXPLOSION)
11043 /* collected custom elements can only be dropped on empty fields */
11044 if (IS_CUSTOM_ELEMENT(new_element) && old_element != EL_EMPTY)
11047 if (old_element != EL_EMPTY)
11048 Back[dropx][dropy] = old_element; /* store old element on this field */
11050 ResetGfxAnimation(dropx, dropy);
11051 ResetRandomAnimationValue(dropx, dropy);
11053 if (player->inventory_size > 0 ||
11054 player->inventory_infinite_element != EL_UNDEFINED)
11056 if (player->inventory_size > 0)
11058 player->inventory_size--;
11060 DrawGameValue_Dynamite(local_player->inventory_size);
11062 if (new_element == EL_DYNAMITE)
11063 new_element = EL_DYNAMITE_ACTIVE;
11064 else if (new_element == EL_SP_DISK_RED)
11065 new_element = EL_SP_DISK_RED_ACTIVE;
11068 Feld[dropx][dropy] = new_element;
11070 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11071 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11072 el2img(Feld[dropx][dropy]), 0);
11074 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11076 /* needed if previous element just changed to "empty" in the last frame */
11077 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11079 CheckElementChangeByPlayer(dropx, dropy, new_element, CE_DROPPED_BY_PLAYER,
11080 player->index_bit, drop_side);
11081 CheckTriggeredElementChangeByPlayer(dropx, dropy, new_element,
11083 player->index_bit, drop_side);
11085 TestIfElementTouchesCustomElement(dropx, dropy);
11087 else /* player is dropping a dyna bomb */
11089 player->dynabombs_left--;
11091 Feld[dropx][dropy] = new_element;
11093 if (IN_SCR_FIELD(SCREENX(dropx), SCREENY(dropy)))
11094 DrawGraphicThruMask(SCREENX(dropx), SCREENY(dropy),
11095 el2img(Feld[dropx][dropy]), 0);
11097 PlayLevelSoundAction(dropx, dropy, ACTION_DROPPING);
11100 if (Feld[dropx][dropy] == new_element) /* uninitialized unless CE change */
11101 InitField_WithBug1(dropx, dropy, FALSE);
11103 new_element = Feld[dropx][dropy]; /* element might have changed */
11105 if (IS_CUSTOM_ELEMENT(new_element) && CAN_MOVE(new_element) &&
11106 element_info[new_element].move_pattern == MV_WHEN_DROPPED)
11108 int move_direction, nextx, nexty;
11110 if (element_info[new_element].move_direction_initial == MV_START_AUTOMATIC)
11111 MovDir[dropx][dropy] = drop_direction;
11113 move_direction = MovDir[dropx][dropy];
11114 nextx = dropx + GET_DX_FROM_DIR(move_direction);
11115 nexty = dropy + GET_DY_FROM_DIR(move_direction);
11117 ChangeCount[dropx][dropy] = 0; /* allow at least one more change */
11118 CheckCollision[dropx][dropy] = 2;
11121 player->drop_delay = GET_NEW_DROP_DELAY(drop_element);
11122 player->is_dropping = TRUE;
11124 player->drop_x = dropx;
11125 player->drop_y = dropy;
11130 /* ------------------------------------------------------------------------- */
11131 /* game sound playing functions */
11132 /* ------------------------------------------------------------------------- */
11134 static int *loop_sound_frame = NULL;
11135 static int *loop_sound_volume = NULL;
11137 void InitPlayLevelSound()
11139 int num_sounds = getSoundListSize();
11141 checked_free(loop_sound_frame);
11142 checked_free(loop_sound_volume);
11144 loop_sound_frame = checked_calloc(num_sounds * sizeof(int));
11145 loop_sound_volume = checked_calloc(num_sounds * sizeof(int));
11148 static void PlayLevelSound(int x, int y, int nr)
11150 int sx = SCREENX(x), sy = SCREENY(y);
11151 int volume, stereo_position;
11152 int max_distance = 8;
11153 int type = (IS_LOOP_SOUND(nr) ? SND_CTRL_PLAY_LOOP : SND_CTRL_PLAY_SOUND);
11155 if ((!setup.sound_simple && !IS_LOOP_SOUND(nr)) ||
11156 (!setup.sound_loops && IS_LOOP_SOUND(nr)))
11159 if (!IN_LEV_FIELD(x, y) ||
11160 sx < -max_distance || sx >= SCR_FIELDX + max_distance ||
11161 sy < -max_distance || sy >= SCR_FIELDY + max_distance)
11164 volume = SOUND_MAX_VOLUME;
11166 if (!IN_SCR_FIELD(sx, sy))
11168 int dx = ABS(sx - SCR_FIELDX / 2) - SCR_FIELDX / 2;
11169 int dy = ABS(sy - SCR_FIELDY / 2) - SCR_FIELDY / 2;
11171 volume -= volume * (dx > dy ? dx : dy) / max_distance;
11174 stereo_position = (SOUND_MAX_LEFT +
11175 (sx + max_distance) * SOUND_MAX_LEFT2RIGHT /
11176 (SCR_FIELDX + 2 * max_distance));
11178 if (IS_LOOP_SOUND(nr))
11180 /* This assures that quieter loop sounds do not overwrite louder ones,
11181 while restarting sound volume comparison with each new game frame. */
11183 if (loop_sound_volume[nr] > volume && loop_sound_frame[nr] == FrameCounter)
11186 loop_sound_volume[nr] = volume;
11187 loop_sound_frame[nr] = FrameCounter;
11190 PlaySoundExt(nr, volume, stereo_position, type);
11193 static void PlayLevelSoundNearest(int x, int y, int sound_action)
11195 PlayLevelSound(x < LEVELX(BX1) ? LEVELX(BX1) :
11196 x > LEVELX(BX2) ? LEVELX(BX2) : x,
11197 y < LEVELY(BY1) ? LEVELY(BY1) :
11198 y > LEVELY(BY2) ? LEVELY(BY2) : y,
11202 static void PlayLevelSoundAction(int x, int y, int action)
11204 PlayLevelSoundElementAction(x, y, Feld[x][y], action);
11207 static void PlayLevelSoundElementAction(int x, int y, int element, int action)
11209 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11211 if (sound_effect != SND_UNDEFINED)
11212 PlayLevelSound(x, y, sound_effect);
11215 static void PlayLevelSoundElementActionIfLoop(int x, int y, int element,
11218 int sound_effect = element_info[SND_ELEMENT(element)].sound[action];
11220 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11221 PlayLevelSound(x, y, sound_effect);
11224 static void PlayLevelSoundActionIfLoop(int x, int y, int action)
11226 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11228 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11229 PlayLevelSound(x, y, sound_effect);
11232 static void StopLevelSoundActionIfLoop(int x, int y, int action)
11234 int sound_effect = element_info[SND_ELEMENT(Feld[x][y])].sound[action];
11236 if (sound_effect != SND_UNDEFINED && IS_LOOP_SOUND(sound_effect))
11237 StopSound(sound_effect);
11240 static void PlayLevelMusic()
11242 if (levelset.music[level_nr] != MUS_UNDEFINED)
11243 PlayMusic(levelset.music[level_nr]); /* from config file */
11245 PlayMusic(MAP_NOCONF_MUSIC(level_nr)); /* from music dir */
11248 void PlayLevelSound_EM(int x, int y, int element_em, int sample)
11250 int element = (element_em > -1 ? map_element_EM_to_RND(element_em) : 0);
11255 PlayLevelSoundElementAction(x, y, element, ACTION_WALKING);
11259 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11263 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11267 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11271 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
11275 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11279 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11282 case SAMPLE_android_clone:
11283 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
11286 case SAMPLE_android_move:
11287 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11290 case SAMPLE_spring:
11291 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11295 PlayLevelSoundElementAction(x, y, element, ACTION_SLURPED_BY_SPRING);
11299 PlayLevelSoundElementAction(x, y, element, ACTION_WAITING);
11302 case SAMPLE_eater_eat:
11303 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11307 PlayLevelSoundElementAction(x, y, element, ACTION_MOVING);
11310 case SAMPLE_collect:
11311 PlayLevelSoundElementAction(x, y, element, ACTION_COLLECTING);
11314 case SAMPLE_diamond:
11315 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11318 case SAMPLE_squash:
11319 /* !!! CHECK THIS !!! */
11321 PlayLevelSoundElementAction(x, y, element, ACTION_BREAKING);
11323 PlayLevelSoundElementAction(x, y, element, ACTION_SMASHED_BY_ROCK);
11327 case SAMPLE_wonderfall:
11328 PlayLevelSoundElementAction(x, y, element, ACTION_FILLING);
11332 PlayLevelSoundElementAction(x, y, element, ACTION_IMPACT);
11336 PlayLevelSoundElementAction(x, y, element, ACTION_PUSHING);
11340 PlayLevelSoundElementAction(x, y, element, ACTION_DIGGING);
11344 PlayLevelSoundElementAction(x, y, element, ACTION_SPLASHING);
11348 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
11352 PlayLevelSoundElementAction(x, y, element, ACTION_GROWING);
11355 case SAMPLE_wonder:
11356 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
11360 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
11363 case SAMPLE_exit_open:
11364 PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
11367 case SAMPLE_exit_leave:
11368 PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
11371 case SAMPLE_dynamite:
11372 PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
11376 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
11380 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
11384 PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
11388 PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
11392 PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
11396 PlaySoundStereo(SND_GAME_RUNNING_OUT_OF_TIME, SOUND_MIDDLE);
11400 PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
11405 void RaiseScore(int value)
11407 local_player->score += value;
11409 DrawGameValue_Score(local_player->score);
11412 void RaiseScoreElement(int element)
11417 case EL_BD_DIAMOND:
11418 case EL_EMERALD_YELLOW:
11419 case EL_EMERALD_RED:
11420 case EL_EMERALD_PURPLE:
11421 case EL_SP_INFOTRON:
11422 RaiseScore(level.score[SC_EMERALD]);
11425 RaiseScore(level.score[SC_DIAMOND]);
11428 RaiseScore(level.score[SC_CRYSTAL]);
11431 RaiseScore(level.score[SC_PEARL]);
11434 case EL_BD_BUTTERFLY:
11435 case EL_SP_ELECTRON:
11436 RaiseScore(level.score[SC_BUG]);
11439 case EL_BD_FIREFLY:
11440 case EL_SP_SNIKSNAK:
11441 RaiseScore(level.score[SC_SPACESHIP]);
11444 case EL_DARK_YAMYAM:
11445 RaiseScore(level.score[SC_YAMYAM]);
11448 RaiseScore(level.score[SC_ROBOT]);
11451 RaiseScore(level.score[SC_PACMAN]);
11454 RaiseScore(level.score[SC_NUT]);
11457 case EL_SP_DISK_RED:
11458 case EL_DYNABOMB_INCREASE_NUMBER:
11459 case EL_DYNABOMB_INCREASE_SIZE:
11460 case EL_DYNABOMB_INCREASE_POWER:
11461 RaiseScore(level.score[SC_DYNAMITE]);
11463 case EL_SHIELD_NORMAL:
11464 case EL_SHIELD_DEADLY:
11465 RaiseScore(level.score[SC_SHIELD]);
11467 case EL_EXTRA_TIME:
11468 RaiseScore(level.extra_time_score);
11482 RaiseScore(level.score[SC_KEY]);
11485 RaiseScore(element_info[element].collect_score);
11490 void RequestQuitGame(boolean ask_if_really_quit)
11492 if (AllPlayersGone ||
11493 !ask_if_really_quit ||
11494 level_editor_test_game ||
11495 Request("Do you really want to quit the game ?",
11496 REQ_ASK | REQ_STAY_CLOSED))
11498 #if defined(NETWORK_AVALIABLE)
11499 if (options.network)
11500 SendToServer_StopPlaying();
11504 game_status = GAME_MODE_MAIN;
11510 if (tape.playing && tape.deactivate_display)
11511 TapeDeactivateDisplayOff(TRUE);
11513 OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
11515 if (tape.playing && tape.deactivate_display)
11516 TapeDeactivateDisplayOn();
11521 /* ---------- new game button stuff ---------------------------------------- */
11523 /* graphic position values for game buttons */
11524 #define GAME_BUTTON_XSIZE 30
11525 #define GAME_BUTTON_YSIZE 30
11526 #define GAME_BUTTON_XPOS 5
11527 #define GAME_BUTTON_YPOS 215
11528 #define SOUND_BUTTON_XPOS 5
11529 #define SOUND_BUTTON_YPOS (GAME_BUTTON_YPOS + GAME_BUTTON_YSIZE)
11531 #define GAME_BUTTON_STOP_XPOS (GAME_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11532 #define GAME_BUTTON_PAUSE_XPOS (GAME_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11533 #define GAME_BUTTON_PLAY_XPOS (GAME_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11534 #define SOUND_BUTTON_MUSIC_XPOS (SOUND_BUTTON_XPOS + 0 * GAME_BUTTON_XSIZE)
11535 #define SOUND_BUTTON_LOOPS_XPOS (SOUND_BUTTON_XPOS + 1 * GAME_BUTTON_XSIZE)
11536 #define SOUND_BUTTON_SIMPLE_XPOS (SOUND_BUTTON_XPOS + 2 * GAME_BUTTON_XSIZE)
11543 } gamebutton_info[NUM_GAME_BUTTONS] =
11546 GAME_BUTTON_STOP_XPOS, GAME_BUTTON_YPOS,
11551 GAME_BUTTON_PAUSE_XPOS, GAME_BUTTON_YPOS,
11552 GAME_CTRL_ID_PAUSE,
11556 GAME_BUTTON_PLAY_XPOS, GAME_BUTTON_YPOS,
11561 SOUND_BUTTON_MUSIC_XPOS, SOUND_BUTTON_YPOS,
11562 SOUND_CTRL_ID_MUSIC,
11563 "background music on/off"
11566 SOUND_BUTTON_LOOPS_XPOS, SOUND_BUTTON_YPOS,
11567 SOUND_CTRL_ID_LOOPS,
11568 "sound loops on/off"
11571 SOUND_BUTTON_SIMPLE_XPOS, SOUND_BUTTON_YPOS,
11572 SOUND_CTRL_ID_SIMPLE,
11573 "normal sounds on/off"
11577 void CreateGameButtons()
11581 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11583 Bitmap *gd_bitmap = graphic_info[IMG_GLOBAL_DOOR].bitmap;
11584 struct GadgetInfo *gi;
11587 unsigned long event_mask;
11588 int gd_xoffset, gd_yoffset;
11589 int gd_x1, gd_x2, gd_y1, gd_y2;
11592 gd_xoffset = gamebutton_info[i].x;
11593 gd_yoffset = gamebutton_info[i].y;
11594 gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
11595 gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
11597 if (id == GAME_CTRL_ID_STOP ||
11598 id == GAME_CTRL_ID_PAUSE ||
11599 id == GAME_CTRL_ID_PLAY)
11601 button_type = GD_TYPE_NORMAL_BUTTON;
11603 event_mask = GD_EVENT_RELEASED;
11604 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11605 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11609 button_type = GD_TYPE_CHECK_BUTTON;
11611 ((id == SOUND_CTRL_ID_MUSIC && setup.sound_music) ||
11612 (id == SOUND_CTRL_ID_LOOPS && setup.sound_loops) ||
11613 (id == SOUND_CTRL_ID_SIMPLE && setup.sound_simple) ? TRUE : FALSE);
11614 event_mask = GD_EVENT_PRESSED;
11615 gd_y1 = DOOR_GFX_PAGEY1 + gd_yoffset;
11616 gd_y2 = DOOR_GFX_PAGEY1 + gd_yoffset - GAME_BUTTON_YSIZE;
11619 gi = CreateGadget(GDI_CUSTOM_ID, id,
11620 GDI_INFO_TEXT, gamebutton_info[i].infotext,
11621 GDI_X, DX + gd_xoffset,
11622 GDI_Y, DY + gd_yoffset,
11623 GDI_WIDTH, GAME_BUTTON_XSIZE,
11624 GDI_HEIGHT, GAME_BUTTON_YSIZE,
11625 GDI_TYPE, button_type,
11626 GDI_STATE, GD_BUTTON_UNPRESSED,
11627 GDI_CHECKED, checked,
11628 GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y1,
11629 GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y1,
11630 GDI_ALT_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y2,
11631 GDI_ALT_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y2,
11632 GDI_EVENT_MASK, event_mask,
11633 GDI_CALLBACK_ACTION, HandleGameButtons,
11637 Error(ERR_EXIT, "cannot create gadget");
11639 game_gadget[id] = gi;
11643 void FreeGameButtons()
11647 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11648 FreeGadget(game_gadget[i]);
11651 static void MapGameButtons()
11655 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11656 MapGadget(game_gadget[i]);
11659 void UnmapGameButtons()
11663 for (i = 0; i < NUM_GAME_BUTTONS; i++)
11664 UnmapGadget(game_gadget[i]);
11667 static void HandleGameButtons(struct GadgetInfo *gi)
11669 int id = gi->custom_id;
11671 if (game_status != GAME_MODE_PLAYING)
11676 case GAME_CTRL_ID_STOP:
11677 RequestQuitGame(TRUE);
11680 case GAME_CTRL_ID_PAUSE:
11681 if (options.network)
11683 #if defined(NETWORK_AVALIABLE)
11685 SendToServer_ContinuePlaying();
11687 SendToServer_PausePlaying();
11691 TapeTogglePause(TAPE_TOGGLE_MANUAL);
11694 case GAME_CTRL_ID_PLAY:
11697 #if defined(NETWORK_AVALIABLE)
11698 if (options.network)
11699 SendToServer_ContinuePlaying();
11703 tape.pausing = FALSE;
11704 DrawVideoDisplay(VIDEO_STATE_PAUSE_OFF,0);
11709 case SOUND_CTRL_ID_MUSIC:
11710 if (setup.sound_music)
11712 setup.sound_music = FALSE;
11715 else if (audio.music_available)
11717 setup.sound = setup.sound_music = TRUE;
11719 SetAudioMode(setup.sound);
11725 case SOUND_CTRL_ID_LOOPS:
11726 if (setup.sound_loops)
11727 setup.sound_loops = FALSE;
11728 else if (audio.loops_available)
11730 setup.sound = setup.sound_loops = TRUE;
11731 SetAudioMode(setup.sound);
11735 case SOUND_CTRL_ID_SIMPLE:
11736 if (setup.sound_simple)
11737 setup.sound_simple = FALSE;
11738 else if (audio.sound_available)
11740 setup.sound = setup.sound_simple = TRUE;
11741 SetAudioMode(setup.sound);