+/* this switch controls how rocks move horizontally */
+#define OLD_GAME_BEHAVIOUR FALSE
+
+/* EXPERIMENTAL STUFF */
+#define USE_NEW_AMOEBA_CODE FALSE
+
+/* for DigField() */
+#define DF_NO_PUSH 0
+#define DF_DIG 1
+#define DF_SNAP 2
+
+/* for MoveFigure() */
+#define MF_NO_ACTION 0
+#define MF_MOVING 1
+#define MF_ACTION 2
+
+/* for ScrollFigure() */
+#define SCROLL_INIT 0
+#define SCROLL_GO_ON 1
+
+/* for Explode() */
+#define EX_PHASE_START 0
+#define EX_NO_EXPLOSION 0
+#define EX_NORMAL 1
+#define EX_CENTER 2
+#define EX_BORDER 3
+
+/* special positions in the game control window (relative to control window) */
+#define XX_LEVEL 37
+#define YY_LEVEL 20
+#define XX_EMERALDS 29
+#define YY_EMERALDS 54
+#define XX_DYNAMITE 29
+#define YY_DYNAMITE 89
+#define XX_KEYS 18
+#define YY_KEYS 123
+#define XX_SCORE 15
+#define YY_SCORE 159
+#define XX_TIME 29
+#define YY_TIME 194
+
+/* special positions in the game control window (relative to main window) */
+#define DX_LEVEL (DX + XX_LEVEL)
+#define DY_LEVEL (DY + YY_LEVEL)
+#define DX_EMERALDS (DX + XX_EMERALDS)
+#define DY_EMERALDS (DY + YY_EMERALDS)
+#define DX_DYNAMITE (DX + XX_DYNAMITE)
+#define DY_DYNAMITE (DY + YY_DYNAMITE)
+#define DX_KEYS (DX + XX_KEYS)
+#define DY_KEYS (DY + YY_KEYS)
+#define DX_SCORE (DX + XX_SCORE)
+#define DY_SCORE (DY + YY_SCORE)
+#define DX_TIME (DX + XX_TIME)
+#define DY_TIME (DY + YY_TIME)
+
+/* values for initial player move delay (initial delay counter value) */
+#define INITIAL_MOVE_DELAY_OFF -1
+#define INITIAL_MOVE_DELAY_ON 0
+
+/* values for player movement speed (which is in fact a delay value) */
+#define MOVE_DELAY_NORMAL_SPEED 8
+#define MOVE_DELAY_HIGH_SPEED 4
+
+#define DOUBLE_MOVE_DELAY(x) (x = (x <= MOVE_DELAY_HIGH_SPEED ? x * 2 : x))
+#define HALVE_MOVE_DELAY(x) (x = (x >= MOVE_DELAY_HIGH_SPEED ? x / 2 : x))
+#define DOUBLE_PLAYER_SPEED(p) (HALVE_MOVE_DELAY((p)->move_delay_value))
+#define HALVE_PLAYER_SPEED(p) (DOUBLE_MOVE_DELAY((p)->move_delay_value))
+
+/* values for other actions */
+#define MOVE_STEPSIZE_NORMAL (TILEX / MOVE_DELAY_NORMAL_SPEED)
+
+#define INIT_GFX_RANDOM() (SimpleRND(1000000))
+
+#define GET_NEW_PUSH_DELAY(e) ( (element_info[e].push_delay_fixed) + \
+ RND(element_info[e].push_delay_random))
+#define GET_NEW_MOVE_DELAY(e) ( (element_info[e].move_delay_fixed) + \
+ RND(element_info[e].move_delay_random))
+
+#define ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, condition) \
+ (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
+ (condition) || \
+ (DONT_COLLIDE_WITH(e) && \
+ IS_FREE_OR_PLAYER(x, y))))
+
+#define ELEMENT_CAN_ENTER_FIELD_GENERIC_2(x, y, condition) \
+ (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
+ (condition)))
+
+#define ELEMENT_CAN_ENTER_FIELD(e, x, y) \
+ ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, 0)
+
+#define ELEMENT_CAN_ENTER_FIELD_OR_ACID(e, x, y) \
+ ELEMENT_CAN_ENTER_FIELD_GENERIC(e, x, y, (Feld[x][y] == EL_ACID))
+
+#define ELEMENT_CAN_ENTER_FIELD_OR_ACID_2(x, y) \
+ ELEMENT_CAN_ENTER_FIELD_GENERIC_2(x, y, (Feld[x][y] == EL_ACID))
+
+#define ENEMY_CAN_ENTER_FIELD(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
+
+#define YAMYAM_CAN_ENTER_FIELD(x, y) \
+ (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
+ Feld[x][y] == EL_DIAMOND))
+
+#define DARK_YAMYAM_CAN_ENTER_FIELD(x, y) \
+ (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
+ IS_FOOD_DARK_YAMYAM(Feld[x][y])))
+
+#define PACMAN_CAN_ENTER_FIELD(x, y) \
+ (IN_LEV_FIELD(x, y) && (IS_FREE_OR_PLAYER(x, y) || \
+ IS_AMOEBOID(Feld[x][y])))
+
+#define PIG_CAN_ENTER_FIELD(x, y) \
+ (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
+ IS_FOOD_PIG(Feld[x][y])))
+
+#define PENGUIN_CAN_ENTER_FIELD(x, y) \
+ (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || \
+ IS_FOOD_PENGUIN(Feld[x][y]) || \
+ Feld[x][y] == EL_EXIT_OPEN || \
+ Feld[x][y] == EL_ACID))
+
+#define MOLE_CAN_ENTER_FIELD(x, y, condition) \
+ (IN_LEV_FIELD(x, y) && (IS_FREE(x, y) || (condition)))
+
+#define IN_LEV_FIELD_AND_IS_FREE(x, y) (IN_LEV_FIELD(x, y) && IS_FREE(x, y))
+#define IN_LEV_FIELD_AND_NOT_FREE(x, y) (IN_LEV_FIELD(x, y) && !IS_FREE(x, y))
+
+/* game button identifiers */
+#define GAME_CTRL_ID_STOP 0
+#define GAME_CTRL_ID_PAUSE 1
+#define GAME_CTRL_ID_PLAY 2
+#define SOUND_CTRL_ID_MUSIC 3
+#define SOUND_CTRL_ID_LOOPS 4
+#define SOUND_CTRL_ID_SIMPLE 5
+
+#define NUM_GAME_BUTTONS 6
+
+
+/* forward declaration for internal use */
+
+static void InitBeltMovement(void);
+static void CloseAllOpenTimegates(void);
+static void CheckGravityMovement(struct PlayerInfo *);
+static void KillHeroUnlessProtected(int, int);
+
+static void TestIfPlayerTouchesCustomElement(int, int);
+static void TestIfElementTouchesCustomElement(int, int);
+
+static boolean CheckTriggeredElementChange(int, int, int, int);
+static boolean CheckElementChange(int, int, int, int);
+static void ChangeElementNow(int, int, int);
+
+static void PlaySoundLevel(int, int, int);
+static void PlaySoundLevelNearest(int, int, int);
+static void PlaySoundLevelAction(int, int, int);
+static void PlaySoundLevelElementAction(int, int, int, int);
+static void PlaySoundLevelActionIfLoop(int, int, int);
+static void StopSoundLevelActionIfLoop(int, int, int);
+
+static void MapGameButtons();
+static void HandleGameButtons(struct GadgetInfo *);
+
+static struct GadgetInfo *game_gadget[NUM_GAME_BUTTONS];
+
+
+/* ------------------------------------------------------------------------- */
+/* definition of elements that automatically change to other elements after */
+/* a specified time, eventually calling a function when changing */
+/* ------------------------------------------------------------------------- */
+
+/* forward declaration for changer functions */
+static void InitBuggyBase(int x, int y);
+static void WarnBuggyBase(int x, int y);
+
+static void InitTrap(int x, int y);
+static void ActivateTrap(int x, int y);
+static void ChangeActiveTrap(int x, int y);
+
+static void InitRobotWheel(int x, int y);
+static void RunRobotWheel(int x, int y);
+static void StopRobotWheel(int x, int y);
+
+static void InitTimegateWheel(int x, int y);
+static void RunTimegateWheel(int x, int y);
+
+struct ChangingElementInfo
+{
+ int element;
+ int target_element;
+ int change_delay;
+ void (*pre_change_function)(int x, int y);
+ void (*change_function)(int x, int y);
+ void (*post_change_function)(int x, int y);
+};
+
+static struct ChangingElementInfo changing_element_list[] =
+{
+ {
+ EL_NUT_BREAKING,
+ EL_EMERALD,
+ 6,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ EL_PEARL_BREAKING,
+ EL_EMPTY,
+ 8,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ EL_EXIT_OPENING,
+ EL_EXIT_OPEN,
+ 29,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ EL_SWITCHGATE_OPENING,
+ EL_SWITCHGATE_OPEN,
+ 29,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ EL_SWITCHGATE_CLOSING,
+ EL_SWITCHGATE_CLOSED,
+ 29,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ EL_TIMEGATE_OPENING,
+ EL_TIMEGATE_OPEN,
+ 29,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ EL_TIMEGATE_CLOSING,
+ EL_TIMEGATE_CLOSED,
+ 29,
+ NULL,
+ NULL,
+ NULL
+ },
+
+ {
+ EL_ACID_SPLASH_LEFT,
+ EL_EMPTY,
+ 8,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ EL_ACID_SPLASH_RIGHT,
+ EL_EMPTY,
+ 8,
+ NULL,
+ NULL,
+ NULL
+ },
+ {
+ EL_SP_BUGGY_BASE,
+ EL_SP_BUGGY_BASE_ACTIVATING,
+ 0,
+ InitBuggyBase,
+ NULL,
+ NULL
+ },
+ {
+ EL_SP_BUGGY_BASE_ACTIVATING,
+ EL_SP_BUGGY_BASE_ACTIVE,
+ 0,
+ InitBuggyBase,
+ NULL,
+ NULL
+ },
+ {
+ EL_SP_BUGGY_BASE_ACTIVE,
+ EL_SP_BUGGY_BASE,
+ 0,
+ InitBuggyBase,
+ WarnBuggyBase,
+ NULL
+ },
+ {
+ EL_TRAP,
+ EL_TRAP_ACTIVE,
+ 0,
+ InitTrap,
+ NULL,
+ ActivateTrap
+ },
+ {
+ EL_TRAP_ACTIVE,
+ EL_TRAP,
+ 31,
+ NULL,
+ ChangeActiveTrap,
+ NULL
+ },
+ {
+ EL_ROBOT_WHEEL_ACTIVE,
+ EL_ROBOT_WHEEL,
+ 0,
+ InitRobotWheel,
+ RunRobotWheel,
+ StopRobotWheel
+ },
+ {
+ EL_TIMEGATE_SWITCH_ACTIVE,
+ EL_TIMEGATE_SWITCH,
+ 0,
+ InitTimegateWheel,
+ RunTimegateWheel,
+ NULL
+ },
+
+ {
+ EL_UNDEFINED,
+ EL_UNDEFINED,
+ -1,
+ NULL,
+ NULL,
+ NULL
+ }
+};
+
+struct
+{
+ int element;
+ int push_delay_fixed, push_delay_random;
+}
+push_delay_list[] =
+{
+ { EL_SPRING, 0, 0 },
+ { EL_BALLOON, 0, 0 },
+
+ { EL_SOKOBAN_OBJECT, 2, 0 },
+ { EL_SOKOBAN_FIELD_FULL, 2, 0 },
+ { EL_SATELLITE, 2, 0 },
+ { EL_SP_DISK_YELLOW, 2, 0 },
+
+ { EL_UNDEFINED, 0, 0 },
+};
+
+struct
+{
+ int element;
+ int move_stepsize;
+}
+move_stepsize_list[] =
+{
+ { EL_AMOEBA_DROP, 2 },
+ { EL_AMOEBA_DROPPING, 2 },
+ { EL_QUICKSAND_FILLING, 1 },
+ { EL_QUICKSAND_EMPTYING, 1 },
+ { EL_MAGIC_WALL_FILLING, 2 },
+ { EL_BD_MAGIC_WALL_FILLING, 2 },
+ { EL_MAGIC_WALL_EMPTYING, 2 },
+ { EL_BD_MAGIC_WALL_EMPTYING, 2 },
+
+ { EL_UNDEFINED, 0 },
+};
+
+struct
+{
+ int element;
+ int gem_count;
+}
+gem_count_list[] =
+{
+ { EL_EMERALD, 1 },
+ { EL_BD_DIAMOND, 1 },
+ { EL_EMERALD_YELLOW, 1 },
+ { EL_EMERALD_RED, 1 },
+ { EL_EMERALD_PURPLE, 1 },
+ { EL_DIAMOND, 3 },
+ { EL_SP_INFOTRON, 1 },
+ { EL_PEARL, 5 },
+ { EL_CRYSTAL, 8 },
+
+ { EL_UNDEFINED, 0 },
+};
+
+static boolean changing_element[MAX_NUM_ELEMENTS];
+static unsigned long trigger_events[MAX_NUM_ELEMENTS];
+
+#define IS_AUTO_CHANGING(e) (changing_element[e])
+#define IS_JUST_CHANGING(x, y) (ChangeDelay[x][y] != 0)
+#define IS_CHANGING(x, y) (IS_AUTO_CHANGING(Feld[x][y]) || \
+ IS_JUST_CHANGING(x, y))
+
+