+ DrawTextS(x, y + font_height / 2, font_nr, buffer);
+ }
+}
+
+static void DrawPropertiesWindow(void)
+{
+ struct GraphicInfo *gd = &graphic_info[IMG_EDITOR_INPUT_TEXT];
+ int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
+ int border_size = gd->border_size;
+ int font_nr = FONT_TEXT_1;
+ int font_height = getFontHeight(font_nr);
+ int xoffset = TILEX + element_border + 3 * border_size;
+ int yoffset = (TILEY - font_height) / 2;
+ int x1 = editor.settings.element_graphic.x + element_border;
+ int y1 = editor.settings.element_graphic.y + element_border;
+ int x2 = (editor.settings.element_name.x == -1 ? x1 + xoffset :
+ editor.settings.element_name.x);
+ int y2 = (editor.settings.element_name.y == -1 ? y1 + yoffset :
+ editor.settings.element_name.y);
+ char *text = "Element Settings";
+ int font2_nr = FONT_TITLE_1;
+ struct MenuPosInfo *pos = &editor.settings.headline;
+ int sx = SX + ALIGNED_XPOS(pos->x, getTextWidth(text, font2_nr), pos->align);
+ int sy = SY + pos->y;
+
+ stick_element_properties_window = FALSE;
+
+ // make sure that previous properties edit mode exists for this element
+ if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG_2 &&
+ !IS_CUSTOM_ELEMENT(properties_element))
+ edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_2;
+
+ if (edit_mode_properties > ED_MODE_PROPERTIES_CONFIG &&
+ !IS_PLAYER_ELEMENT(properties_element) &&
+ !IS_CUSTOM_ELEMENT(properties_element))
+ edit_mode_properties = ED_MODE_PROPERTIES_CONFIG;
+
+ if (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG &&
+ (IS_PLAYER_ELEMENT(properties_element) ||
+ IS_CUSTOM_ELEMENT(properties_element)))
+ edit_mode_properties = ED_MODE_PROPERTIES_CONFIG_1;
+
+ CopyElementPropertiesToEditor(properties_element);
+
+ UnmapLevelEditorFieldGadgets();
+ UnmapLevelEditorToolboxDrawingGadgets();
+ UnmapLevelEditorToolboxCustomGadgets();
+
+ MapLevelEditorToolboxCustomGadgetsIfNeeded();
+
+ SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
+ ClearField();
+
+ DrawText(sx, sy, text, font2_nr);
+
+ FrameCounter = 0; // restart animation frame counter
+
+ DrawElementBorder(SX + x1, SY + y1, TILEX, TILEY, FALSE);
+ DrawEditorElementAnimation(SX + x1, SY + y1);
+ DrawEditorElementName(x2, y2, font_nr);
+
+ DrawPropertiesTabulatorGadgets();
+
+ if (edit_mode_properties == ED_MODE_PROPERTIES_INFO)
+ DrawPropertiesInfo();
+ else if (edit_mode_properties == ED_MODE_PROPERTIES_CHANGE)
+ DrawPropertiesChange();
+ else // (edit_mode_properties == ED_MODE_PROPERTIES_CONFIG[_1|_2])
+ DrawPropertiesConfig();
+}
+
+static void DrawPaletteWindow(void)
+{
+ int i;
+
+ UnmapLevelEditorFieldGadgets();
+
+ SetMainBackgroundImage(IMG_BACKGROUND_EDITOR);
+ ClearField();
+
+ // map buttons to select elements
+ for (i = 0; i < ED_NUM_ELEMENTLIST_BUTTONS; i++)
+ MapGadget(level_editor_gadget[GADGET_ID_ELEMENTLIST_FIRST + i]);
+ MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_VERTICAL]);
+ MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_UP]);
+ MapGadget(level_editor_gadget[GADGET_ID_SCROLL_LIST_DOWN]);
+}
+
+static void UpdateCustomElementGraphicGadgets(void)
+{
+ int i;
+
+ InitElementPropertiesGfxElement();
+
+ ModifyEditorElementList();
+ RedrawDrawingElements();
+
+ // force redraw of all mapped drawing area gadgets
+ for (i = 0; i < ED_NUM_DRAWING_AREAS; i++)
+ {
+ struct GadgetInfo *gi = level_editor_gadget[drawingarea_info[i].gadget_id];
+
+ if (gi->mapped)
+ MapDrawingArea(i);
+ }
+}
+
+static int getOpenDirectionFromTube(int element)
+{
+ switch (element)
+ {
+ case EL_TUBE_LEFT_UP: return (MV_LEFT | MV_UP);
+ case EL_TUBE_LEFT_DOWN: return (MV_LEFT | MV_DOWN);
+ case EL_TUBE_RIGHT_UP: return (MV_RIGHT | MV_UP);
+ case EL_TUBE_RIGHT_DOWN: return (MV_RIGHT | MV_DOWN);
+ case EL_TUBE_HORIZONTAL: return (MV_HORIZONTAL);
+ case EL_TUBE_HORIZONTAL_UP: return (MV_HORIZONTAL | MV_UP);
+ case EL_TUBE_HORIZONTAL_DOWN: return (MV_HORIZONTAL | MV_DOWN);
+ case EL_TUBE_VERTICAL: return (MV_VERTICAL);
+ case EL_TUBE_VERTICAL_LEFT: return (MV_VERTICAL | MV_LEFT);
+ case EL_TUBE_VERTICAL_RIGHT: return (MV_VERTICAL | MV_RIGHT);
+ case EL_TUBE_ANY: return (MV_ANY_DIRECTION);
+ }
+
+ return MV_NONE;
+}
+
+static int getTubeFromOpenDirection(int direction)
+{
+ switch (direction)
+ {
+ case (MV_LEFT | MV_UP): return EL_TUBE_LEFT_UP;
+ case (MV_LEFT | MV_DOWN): return EL_TUBE_LEFT_DOWN;
+ case (MV_RIGHT | MV_UP): return EL_TUBE_RIGHT_UP;
+ case (MV_RIGHT | MV_DOWN): return EL_TUBE_RIGHT_DOWN;
+ case (MV_HORIZONTAL): return EL_TUBE_HORIZONTAL;
+ case (MV_HORIZONTAL | MV_UP): return EL_TUBE_HORIZONTAL_UP;
+ case (MV_HORIZONTAL | MV_DOWN): return EL_TUBE_HORIZONTAL_DOWN;
+ case (MV_VERTICAL): return EL_TUBE_VERTICAL;
+ case (MV_VERTICAL | MV_LEFT): return EL_TUBE_VERTICAL_LEFT;
+ case (MV_VERTICAL | MV_RIGHT): return EL_TUBE_VERTICAL_RIGHT;
+ case (MV_ANY_DIRECTION): return EL_TUBE_ANY;
+
+ // if only one direction, fall back to simple tube with that direction
+ case (MV_LEFT): return EL_TUBE_HORIZONTAL;
+ case (MV_RIGHT): return EL_TUBE_HORIZONTAL;
+ case (MV_UP): return EL_TUBE_VERTICAL;
+ case (MV_DOWN): return EL_TUBE_VERTICAL;
+ }
+
+ return EL_EMPTY;
+}
+
+static int getTubeFromOpenDirectionNotEmpty(int direction, int element_old)
+{
+ int element_new = getTubeFromOpenDirection(direction);
+
+ return (element_new != EL_EMPTY ? element_new : element_old);
+}
+
+static int getOpenDirectionFromBelt(int element)
+{
+ int belt_dir = getBeltDirFromBeltElement(element);
+
+ return (belt_dir == MV_LEFT ? MV_RIGHT :
+ belt_dir == MV_RIGHT ? MV_LEFT :
+ belt_dir == MV_NONE ? MV_HORIZONTAL : belt_dir);
+}
+
+static int getBeltFromNrAndOpenDirection(int nr, int direction)
+{
+ int belt_dir = (direction == MV_LEFT ? MV_RIGHT :
+ direction == MV_RIGHT ? MV_LEFT :
+ direction == MV_HORIZONTAL ? MV_NONE : direction);
+
+ if (direction == MV_NONE)
+ return EL_EMPTY;
+
+ return getBeltElementFromBeltNrAndBeltDir(nr, belt_dir);
+}
+
+static int getBeltFromNrAndOpenDirectionNotEmpty(int nr, int direction,
+ int element_old)
+{
+ int element_new = getBeltFromNrAndOpenDirection(nr, direction);
+
+ return (element_new != EL_EMPTY ? element_new : element_old);
+}
+
+static int getOpenDirectionFromPool(int element)
+{
+ switch (element)
+ {
+ case EL_ACID_POOL_TOPLEFT: return (MV_DOWN | MV_RIGHT);
+ case EL_ACID_POOL_TOPRIGHT: return (MV_DOWN | MV_LEFT);
+ case EL_ACID_POOL_BOTTOMLEFT: return (MV_UP | MV_RIGHT);
+ case EL_ACID_POOL_BOTTOMRIGHT: return (MV_UP | MV_LEFT);
+ case EL_ACID_POOL_BOTTOM: return (MV_HORIZONTAL | MV_UP);
+ case EL_ACID: return (MV_HORIZONTAL | MV_DOWN);
+ }
+
+ return MV_NONE;
+}
+
+static int getPoolFromOpenDirection(int direction)
+{
+ switch (direction)
+ {
+ case (MV_DOWN | MV_RIGHT): return EL_ACID_POOL_TOPLEFT;
+ case (MV_DOWN | MV_LEFT): return EL_ACID_POOL_TOPRIGHT;
+ case (MV_UP | MV_RIGHT): return EL_ACID_POOL_BOTTOMLEFT;
+ case (MV_UP | MV_LEFT): return EL_ACID_POOL_BOTTOMRIGHT;
+ case (MV_HORIZONTAL | MV_UP): return EL_ACID_POOL_BOTTOM;
+ case (MV_HORIZONTAL | MV_DOWN): return EL_ACID;
+ }
+
+ return EL_EMPTY;
+}
+
+static int getPoolFromOpenDirectionExt(int direction, int help_element)
+{
+ int element = getPoolFromOpenDirection(direction);
+ int help_direction = getOpenDirectionFromPool(help_element);
+
+ if (element == EL_EMPTY)
+ {
+ int help_direction_vertical = help_direction & MV_VERTICAL;
+
+ element = getPoolFromOpenDirection(direction | help_direction_vertical);
+ }
+
+ if (element == EL_EMPTY)
+ {
+ int help_direction_horizontal = help_direction & MV_HORIZONTAL;
+
+ element = getPoolFromOpenDirection(direction | help_direction_horizontal);
+ }
+
+ return element;
+}
+
+static int getPoolFromOpenDirectionNotEmpty(int direction, int element_old)
+{
+ int element_new = getPoolFromOpenDirectionExt(direction, element_old);
+
+ return (element_new != EL_EMPTY ? element_new : element_old);
+}
+
+static int getOpenDirectionFromPillar(int element)
+{
+ switch (element)
+ {
+ case EL_EMC_WALL_1: return (MV_DOWN);
+ case EL_EMC_WALL_2: return (MV_VERTICAL);
+ case EL_EMC_WALL_3: return (MV_UP);
+ }
+
+ return MV_NONE;
+}
+
+static int getPillarFromOpenDirection(int direction)
+{
+ switch (direction)
+ {
+ case (MV_DOWN): return EL_EMC_WALL_1;
+ case (MV_VERTICAL): return EL_EMC_WALL_2;
+ case (MV_UP): return EL_EMC_WALL_3;
+ }
+
+ return EL_EMPTY;
+}
+
+static int getPillarFromOpenDirectionNotEmpty(int direction, int element_old)
+{
+ int element_new = getPillarFromOpenDirection(direction);
+
+ return (element_new != EL_EMPTY ? element_new : element_old);
+}
+
+static int getOpenDirectionFromSteel2(int element)
+{
+ switch (element)
+ {
+ case EL_DC_STEELWALL_2_LEFT: return (MV_RIGHT);
+ case EL_DC_STEELWALL_2_RIGHT: return (MV_LEFT);
+ case EL_DC_STEELWALL_2_TOP: return (MV_DOWN);
+ case EL_DC_STEELWALL_2_BOTTOM: return (MV_UP);
+ case EL_DC_STEELWALL_2_HORIZONTAL: return (MV_HORIZONTAL);
+ case EL_DC_STEELWALL_2_VERTICAL: return (MV_VERTICAL);
+ case EL_DC_STEELWALL_2_MIDDLE: return (MV_ANY_DIRECTION);
+ case EL_DC_STEELWALL_2_SINGLE: return (MV_NONE);
+ }
+
+ return MV_NONE;
+}
+
+static int getSteel2FromOpenDirection(int direction)
+{
+ switch (direction)
+ {
+ case (MV_RIGHT): return EL_DC_STEELWALL_2_LEFT;
+ case (MV_LEFT): return EL_DC_STEELWALL_2_RIGHT;
+ case (MV_DOWN): return EL_DC_STEELWALL_2_TOP;
+ case (MV_UP): return EL_DC_STEELWALL_2_BOTTOM;
+ case (MV_HORIZONTAL): return EL_DC_STEELWALL_2_HORIZONTAL;
+ case (MV_VERTICAL): return EL_DC_STEELWALL_2_VERTICAL;
+ case (MV_ANY_DIRECTION): return EL_DC_STEELWALL_2_MIDDLE;
+ case (MV_NONE): return EL_DC_STEELWALL_2_SINGLE;
+ }
+
+ return EL_EMPTY;
+}
+
+static int getSteel2FromOpenDirectionNotEmpty(int direction, int element_old)
+{
+ int element_new = getSteel2FromOpenDirection(direction);
+
+ return (element_new != EL_EMPTY ? element_new : element_old);
+}
+
+static int getOpenDirectionFromChip(int element)
+{
+ switch (element)
+ {
+ case EL_SP_CHIP_SINGLE: return (MV_NONE);
+ case EL_SP_CHIP_LEFT: return (MV_RIGHT);
+ case EL_SP_CHIP_RIGHT: return (MV_LEFT);
+ case EL_SP_CHIP_TOP: return (MV_DOWN);
+ case EL_SP_CHIP_BOTTOM: return (MV_UP);
+ }
+
+ return MV_NONE;
+}
+
+static int getChipFromOpenDirection(int direction)
+{
+ switch (direction)
+ {
+ case (MV_NONE): return EL_SP_CHIP_SINGLE;
+ case (MV_LEFT): return EL_SP_CHIP_RIGHT;
+ case (MV_RIGHT): return EL_SP_CHIP_LEFT;
+ case (MV_UP): return EL_SP_CHIP_BOTTOM;
+ case (MV_DOWN): return EL_SP_CHIP_TOP;
+ }
+
+ return EL_EMPTY;
+}
+
+static int getChipFromOpenDirectionNotEmpty(int direction, int element_old)
+{
+ int element_new = getChipFromOpenDirection(direction);
+
+ return (element_new != EL_EMPTY ? element_new : element_old);
+}
+
+static int getClosedTube(int x, int y)
+{
+ struct XY *xy = xy_directions;
+ int element_old = IntelliDrawBuffer[x][y];
+ int direction_old = getOpenDirectionFromTube(element_old);
+ int direction_new = MV_NONE;
+ int i;
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+
+ if (IN_LEV_FIELD(xx, yy) && IS_TUBE(IntelliDrawBuffer[xx][yy]) &&
+ (direction_old & dir) &&
+ (getOpenDirectionFromTube(IntelliDrawBuffer[xx][yy]) & dir_opposite))
+ direction_new |= dir;
+ }
+
+ return getTubeFromOpenDirectionNotEmpty(direction_new, element_old);
+}
+
+static int getClosedBelt(int x, int y)
+{
+ struct XY *xy = xy_directions;
+ int element_old = IntelliDrawBuffer[x][y];
+ int nr = getBeltNrFromBeltElement(element_old);
+ int direction_old = getOpenDirectionFromBelt(element_old);
+ int direction_new = MV_NONE;
+ int i;
+
+ for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+
+ if (IN_LEV_FIELD(xx, yy) && IS_BELT(IntelliDrawBuffer[xx][yy]) &&
+ (direction_old & dir) &&
+ (getOpenDirectionFromBelt(IntelliDrawBuffer[xx][yy]) & dir_opposite))
+ direction_new |= dir;
+ }
+
+ return getBeltFromNrAndOpenDirection(nr, direction_new);
+}
+
+static int getClosedPool(int x, int y)
+{
+ struct XY *xy = xy_directions;
+ int element_old = IntelliDrawBuffer[x][y];
+ int direction_old = getOpenDirectionFromPool(element_old);
+ int direction_new = MV_NONE;
+ int i;
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+
+ if (IN_LEV_FIELD(xx, yy) &&
+ IS_ACID_POOL_OR_ACID(IntelliDrawBuffer[xx][yy]) &&
+ (direction_old & dir) &&
+ (getOpenDirectionFromPool(IntelliDrawBuffer[xx][yy]) & dir_opposite))
+ direction_new |= dir;
+ }
+
+ return getPoolFromOpenDirectionNotEmpty(direction_new, element_old);
+}
+
+static int getClosedPillar(int x, int y)
+{
+ struct XY *xy = xy_directions;
+ int element_old = IntelliDrawBuffer[x][y];
+ int direction_old = getOpenDirectionFromPillar(element_old);
+ int direction_new = MV_NONE;
+ int i;
+
+ for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+
+ if (IN_LEV_FIELD(xx, yy) && IS_EMC_PILLAR(IntelliDrawBuffer[xx][yy]) &&
+ (direction_old & dir) &&
+ (getOpenDirectionFromPillar(IntelliDrawBuffer[xx][yy]) & dir_opposite))
+ direction_new |= dir;
+ }
+
+ return getPillarFromOpenDirectionNotEmpty(direction_new, element_old);
+}
+
+static int getClosedSteel2(int x, int y)
+{
+ struct XY *xy = xy_directions;
+ int element_old = IntelliDrawBuffer[x][y];
+ int direction_old = getOpenDirectionFromSteel2(element_old);
+ int direction_new = MV_NONE;
+ int i;
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+
+ if (IN_LEV_FIELD(xx, yy) && IS_DC_STEELWALL_2(IntelliDrawBuffer[xx][yy]) &&
+ (direction_old & dir) &&
+ (getOpenDirectionFromSteel2(IntelliDrawBuffer[xx][yy]) & dir_opposite))
+ direction_new |= dir;
+ }
+
+ return getSteel2FromOpenDirectionNotEmpty(direction_new, element_old);
+}
+
+static int getClosedChip(int x, int y)
+{
+ struct XY *xy = xy_directions;
+ int element_old = IntelliDrawBuffer[x][y];
+ int direction_old = getOpenDirectionFromChip(element_old);
+ int direction_new = MV_NONE;
+ int i;
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+
+ if (IN_LEV_FIELD(xx, yy) && IS_SP_CHIP(IntelliDrawBuffer[xx][yy]) &&
+ (direction_old & dir) &&
+ (getOpenDirectionFromChip(IntelliDrawBuffer[xx][yy]) & dir_opposite))
+ direction_new |= dir;
+ }
+
+ return getChipFromOpenDirectionNotEmpty(direction_new, element_old);
+}
+
+static void SetElementSimpleExt(int x, int y, int dx, int dy, int element,
+ boolean change_level)
+{
+ int sx = x - level_xpos;
+ int sy = y - level_ypos;
+ int old_element = Tile[x][y];
+ int new_element = element;
+ unsigned int new_bitmask = (getDrawModeHiRes() ? (dx + 1) << (dy * 2) : 0x0f);
+ boolean draw_masked = FALSE;
+
+ if (IS_MM_WALL_EDITOR(element))
+ {
+ element = map_mm_wall_element_editor(element) | new_bitmask;
+
+ if (IS_MM_WALL(old_element))
+ element |= MM_WALL_BITS(old_element);
+
+ if (!change_level)
+ draw_masked = TRUE;
+ }
+ else if (IS_MM_WALL(old_element) && element == EL_EMPTY)
+ {
+ int element_changed = old_element & ~new_bitmask;
+
+ if (MM_WALL_BITS(element_changed) != 0)
+ element = element_changed;
+ }
+
+ IntelliDrawBuffer[x][y] = element;
+
+ if (change_level)
+ Tile[x][y] = element;
+
+ if (IN_ED_FIELD(sx, sy))
+ {
+ if (IS_MM_WALL(old_element) && new_element == EL_EMPTY)
+ DrawSizedWallParts_MM(sx, sy, EL_EMPTY, ed_tilesize, FALSE, new_bitmask);
+ else if (draw_masked)
+ DrawEditorElementThruMask(sx, sy, element);
+ else
+ DrawEditorElement(sx, sy, element);
+ }
+}
+
+static void SetElementSimple(int x, int y, int element, boolean change_level)
+{
+ SetElementSimpleExt(x, y, 0, 0, element, change_level);
+}
+
+static void MergeAndCloseNeighbourElements(int x1, int y1, int *element1,
+ int x2, int y2, int *element2,
+ int (*close_function)(int, int),
+ boolean change_level)
+{
+ // set neighbour elements to newly determined connections
+ SetElementSimple(x1, y1, *element1, change_level);
+ SetElementSimple(x2, y2, *element2, change_level);
+
+ // remove all open connections of neighbour elements
+ *element1 = close_function(x1, y1);
+ *element2 = close_function(x2, y2);
+
+ // set neighbour elements to new, minimized connections
+ SetElementSimple(x1, y1, *element1, change_level);
+ SetElementSimple(x2, y2, *element2, change_level);
+}
+
+static void SetElementIntelliDraw(int x, int y, int dx, int dy, int new_element,
+ boolean change_level, int button)
+{
+ struct XY *xy = xy_directions;
+ static int last_x = -1;
+ static int last_y = -1;
+
+ if (new_element == EL_UNDEFINED)
+ {
+ last_x = -1;
+ last_y = -1;
+
+ return;
+ }
+
+ int old_element = IntelliDrawBuffer[x][y];
+
+ if (IS_TUBE(new_element))
+ {
+ int last_element_new = EL_UNDEFINED;
+ int direction = MV_NONE;
+ int i;
+
+ // if old element is of same kind, keep all existing directions
+ if (IS_TUBE(old_element))
+ direction |= getOpenDirectionFromTube(old_element);
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+
+ if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
+ IS_TUBE(IntelliDrawBuffer[last_x][last_y]))
+ {
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+ int last_element_old = IntelliDrawBuffer[last_x][last_y];
+ int last_direction_old = getOpenDirectionFromTube(last_element_old);
+ int last_direction_new = last_direction_old | dir_opposite;
+
+ last_element_new = getTubeFromOpenDirection(last_direction_new);
+
+ direction |= dir;
+ }
+ }
+
+ new_element = getTubeFromOpenDirectionNotEmpty(direction, new_element);
+
+ if (last_element_new != EL_UNDEFINED)
+ MergeAndCloseNeighbourElements(x, y, &new_element,
+ last_x, last_y, &last_element_new,
+ getClosedTube, change_level);
+ }
+ else if (IS_BELT(new_element))
+ {
+ int belt_nr = getBeltNrFromBeltElement(new_element);
+ int last_element_new = EL_UNDEFINED;
+ int direction = MV_NONE;
+ int i;
+
+ // if old element is of same kind, keep all existing directions
+ if (IS_BELT(old_element))
+ direction |= getOpenDirectionFromBelt(old_element);
+
+ for (i = MV_BIT_LEFT; i <= MV_BIT_RIGHT; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+
+ if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
+ IS_BELT(IntelliDrawBuffer[last_x][last_y]))
+ {
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+ int last_element_old = IntelliDrawBuffer[last_x][last_y];
+ int last_belt_nr = getBeltNrFromBeltElement(last_element_old);
+ int last_direction_old = getOpenDirectionFromBelt(last_element_old);
+ int last_direction_new = last_direction_old | dir_opposite;
+
+ last_element_new = getBeltFromNrAndOpenDirection(last_belt_nr,
+ last_direction_new);
+ direction |= dir;
+ }
+ }
+
+ new_element = getBeltFromNrAndOpenDirectionNotEmpty(belt_nr, direction,
+ new_element);
+ if (last_element_new != EL_UNDEFINED)
+ MergeAndCloseNeighbourElements(x, y, &new_element,
+ last_x, last_y, &last_element_new,
+ getClosedBelt, change_level);
+ }
+ else if (IS_ACID_POOL_OR_ACID(new_element))
+ {
+ int last_element_new = EL_UNDEFINED;
+ int direction = MV_NONE;
+ int i;
+
+ // if old element is of same kind, keep all existing directions
+ if (IS_ACID_POOL_OR_ACID(old_element))
+ direction |= getOpenDirectionFromPool(old_element);
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+
+ if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
+ IS_ACID_POOL_OR_ACID(IntelliDrawBuffer[last_x][last_y]))
+ {
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+ int last_element_old = IntelliDrawBuffer[last_x][last_y];
+ int last_direction_old = getOpenDirectionFromPool(last_element_old);
+ int last_direction_new = last_direction_old | dir_opposite;
+
+ last_element_new = getPoolFromOpenDirection(last_direction_new);
+
+ direction |= dir;
+ }
+ }
+
+ // special corrections needed for intuitively correct acid pool drawing
+ if (last_element_new == EL_EMPTY)
+ last_element_new = new_element;
+ else if (last_element_new != EL_UNDEFINED)
+ new_element = last_element_new;
+
+ new_element = getPoolFromOpenDirectionNotEmpty(direction, new_element);
+
+ if (last_element_new != EL_UNDEFINED)
+ MergeAndCloseNeighbourElements(x, y, &new_element,
+ last_x, last_y, &last_element_new,
+ getClosedPool, change_level);
+ }
+ else if (IS_EMC_PILLAR(new_element))
+ {
+ int last_element_new = EL_UNDEFINED;
+ int direction = MV_NONE;
+ int i;
+
+ // if old element is of same kind, keep all existing directions
+ if (IS_EMC_PILLAR(old_element))
+ direction |= getOpenDirectionFromPillar(old_element);
+
+ for (i = MV_BIT_UP; i <= MV_BIT_DOWN; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+
+ if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
+ IS_EMC_PILLAR(IntelliDrawBuffer[last_x][last_y]))
+ {
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+ int last_element_old = IntelliDrawBuffer[last_x][last_y];
+ int last_direction_old = getOpenDirectionFromPillar(last_element_old);
+ int last_direction_new = last_direction_old | dir_opposite;
+
+ last_element_new = getPillarFromOpenDirection(last_direction_new);
+
+ direction |= dir;
+ }
+ }
+
+ new_element = getPillarFromOpenDirectionNotEmpty(direction, new_element);
+
+ if (last_element_new != EL_UNDEFINED)
+ MergeAndCloseNeighbourElements(x, y, &new_element,
+ last_x, last_y, &last_element_new,
+ getClosedPillar, change_level);
+ }
+ else if (IS_DC_STEELWALL_2(new_element))
+ {
+ int last_element_new = EL_UNDEFINED;
+ int direction = MV_NONE;
+ int i;
+
+ // if old element is of same kind, keep all existing directions
+ if (IS_DC_STEELWALL_2(old_element))
+ direction |= getOpenDirectionFromSteel2(old_element);
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+
+ if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
+ IS_DC_STEELWALL_2(IntelliDrawBuffer[last_x][last_y]))
+ {
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+ int last_element_old = IntelliDrawBuffer[last_x][last_y];
+ int last_direction_old = getOpenDirectionFromSteel2(last_element_old);
+ int last_direction_new = last_direction_old | dir_opposite;
+
+ last_element_new = getSteel2FromOpenDirection(last_direction_new);
+
+ direction |= dir;
+ }
+ }
+
+ new_element = getSteel2FromOpenDirectionNotEmpty(direction, new_element);
+
+ if (last_element_new != EL_UNDEFINED)
+ MergeAndCloseNeighbourElements(x, y, &new_element,
+ last_x, last_y, &last_element_new,
+ getClosedSteel2, change_level);
+ }
+ else if (IS_SP_CHIP(new_element))
+ {
+ int last_element_new = EL_UNDEFINED;
+ int direction = MV_NONE;
+ int i;
+
+ // (do not keep existing directions, regardless of kind of old element)
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+
+ if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
+ IS_SP_CHIP(IntelliDrawBuffer[last_x][last_y]))
+ {
+ int dir = MV_DIR_FROM_BIT(i);
+ int dir_opposite = MV_DIR_OPPOSITE(dir);
+ int last_element_old = IntelliDrawBuffer[last_x][last_y];
+ int last_direction_old = getOpenDirectionFromChip(last_element_old);
+ int last_direction_new = last_direction_old | dir_opposite;
+
+ if (last_direction_old == MV_NONE)
+ {
+ last_element_new = getChipFromOpenDirection(last_direction_new);
+ direction |= dir;
+ }
+ else if (last_direction_old & (dir | dir_opposite))
+ {
+ direction |= MV_DIR_OPPOSITE(last_direction_old);
+ }
+ else
+ {
+ direction |= MV_DIR_OPPOSITE(dir);
+ }
+ }
+ }
+
+ new_element = getChipFromOpenDirectionNotEmpty(direction, new_element);
+
+ if (last_element_new != EL_UNDEFINED)
+ MergeAndCloseNeighbourElements(x, y, &new_element,
+ last_x, last_y, &last_element_new,
+ getClosedChip, change_level);
+ }
+ else if (IS_SP_HARDWARE_BASE(new_element))
+ {
+ int nr = GetSimpleRandom(6);
+
+ new_element = (nr == 0 ? EL_SP_HARDWARE_BASE_1 :
+ nr == 1 ? EL_SP_HARDWARE_BASE_2 :
+ nr == 2 ? EL_SP_HARDWARE_BASE_3 :
+ nr == 3 ? EL_SP_HARDWARE_BASE_4 :
+ nr == 4 ? EL_SP_HARDWARE_BASE_5 : EL_SP_HARDWARE_BASE_6);
+ }
+ else if (new_element == EL_SP_HARDWARE_GREEN ||
+ new_element == EL_SP_HARDWARE_BLUE ||
+ new_element == EL_SP_HARDWARE_RED)
+ {
+ int nr = GetSimpleRandom(3);
+
+ new_element = (nr == 0 ? EL_SP_HARDWARE_GREEN :
+ nr == 1 ? EL_SP_HARDWARE_BLUE : EL_SP_HARDWARE_RED);
+ }
+ else if (IS_GROUP_ELEMENT(new_element))
+ {
+ boolean connected_drawing = FALSE;
+ int i;
+
+ for (i = 0; i < NUM_DIRECTIONS; i++)
+ {
+ int xx = x + xy[i].x;
+ int yy = y + xy[i].y;
+
+ if (last_x == xx && last_y == yy && IN_LEV_FIELD(last_x, last_y) &&
+ IS_IN_GROUP_EL(IntelliDrawBuffer[last_x][last_y], new_element))
+ connected_drawing = TRUE;
+ }
+
+ if (!connected_drawing)
+ ResolveGroupElement(new_element);
+
+ new_element = GetElementFromGroupElement(new_element);
+ }
+ else if (IS_BELT_SWITCH(old_element))
+ {
+ int belt_nr = getBeltNrFromBeltSwitchElement(old_element);
+ int belt_dir = getBeltDirFromBeltSwitchElement(old_element);
+
+ belt_dir = (belt_dir == MV_LEFT ? MV_NONE :
+ belt_dir == MV_NONE ? MV_RIGHT : MV_LEFT);
+
+ new_element = getBeltSwitchElementFromBeltNrAndBeltDir(belt_nr, belt_dir);
+ }
+ else
+ {
+ static int swappable_elements[][2] =
+ {
+ { EL_EXIT_CLOSED, EL_EXIT_OPEN },
+ { EL_DYNAMITE, EL_DYNAMITE_ACTIVE },
+ { EL_EM_DYNAMITE, EL_EM_DYNAMITE_ACTIVE },
+ { EL_QUICKSAND_EMPTY, EL_QUICKSAND_FULL },
+ { EL_EMERALD, EL_WALL_EMERALD },
+ { EL_EMERALD_YELLOW, EL_WALL_EMERALD_YELLOW },
+ { EL_EMERALD_RED, EL_WALL_EMERALD_RED },
+ { EL_EMERALD_PURPLE, EL_WALL_EMERALD_PURPLE },
+ { EL_DIAMOND, EL_WALL_DIAMOND },
+ { EL_BD_DIAMOND, EL_WALL_BD_DIAMOND },
+ { EL_GATE_1, EL_GATE_1_GRAY },
+ { EL_GATE_2, EL_GATE_2_GRAY },
+ { EL_GATE_3, EL_GATE_3_GRAY },
+ { EL_GATE_4, EL_GATE_4_GRAY },
+ { EL_EM_GATE_1, EL_EM_GATE_1_GRAY },
+ { EL_EM_GATE_2, EL_EM_GATE_2_GRAY },
+ { EL_EM_GATE_3, EL_EM_GATE_3_GRAY },
+ { EL_EM_GATE_4, EL_EM_GATE_4_GRAY },
+ { EL_EMC_GATE_5, EL_EMC_GATE_5_GRAY },
+ { EL_EMC_GATE_6, EL_EMC_GATE_6_GRAY },
+ { EL_EMC_GATE_7, EL_EMC_GATE_7_GRAY },
+ { EL_EMC_GATE_8, EL_EMC_GATE_8_GRAY },
+ { EL_DC_GATE_WHITE, EL_DC_GATE_WHITE_GRAY },
+ { EL_TIME_ORB_EMPTY, EL_TIME_ORB_FULL },
+ { EL_LAMP, EL_LAMP_ACTIVE },
+ { EL_SOKOBAN_FIELD_EMPTY, EL_SOKOBAN_FIELD_FULL },
+ { EL_SP_BASE, EL_SP_BUGGY_BASE },
+ { EL_PEARL, EL_WALL_PEARL },
+ { EL_CRYSTAL, EL_WALL_CRYSTAL },
+ { EL_TIMEGATE_CLOSED, EL_TIMEGATE_OPEN },
+ { EL_SWITCHGATE_CLOSED, EL_SWITCHGATE_OPEN },
+ { EL_SWITCHGATE_SWITCH_UP, EL_SWITCHGATE_SWITCH_DOWN },
+ { EL_DC_SWITCHGATE_SWITCH_UP, EL_DC_SWITCHGATE_SWITCH_DOWN },
+ { EL_LIGHT_SWITCH, EL_LIGHT_SWITCH_ACTIVE },
+ { EL_LANDMINE, EL_DC_LANDMINE },
+ { EL_SHIELD_NORMAL, EL_SHIELD_DEADLY },
+ { EL_STEEL_EXIT_CLOSED, EL_STEEL_EXIT_OPEN },
+ { EL_EM_EXIT_CLOSED, EL_EM_EXIT_OPEN },
+ { EL_EM_STEEL_EXIT_CLOSED, EL_EM_STEEL_EXIT_OPEN },
+ { EL_QUICKSAND_FAST_EMPTY, EL_QUICKSAND_FAST_FULL },
+ { EL_MM_EXIT_CLOSED, EL_MM_EXIT_OPEN },
+ { EL_MM_FUSE, EL_MM_FUSE_ACTIVE },
+ { EL_MM_LIGHTBULB, EL_MM_LIGHTBULB_ACTIVE },
+ { EL_MM_FUEL_EMPTY, EL_MM_FUEL_FULL },
+
+ { -1, -1 },
+ };
+ static int rotatable_elements_4[][4] =
+ {
+ {
+ EL_BUG_UP,
+ EL_BUG_RIGHT,
+ EL_BUG_DOWN,
+ EL_BUG_LEFT
+ },
+ {
+ EL_SPACESHIP_UP,
+ EL_SPACESHIP_RIGHT,
+ EL_SPACESHIP_DOWN,
+ EL_SPACESHIP_LEFT
+ },
+ {
+ EL_BD_BUTTERFLY_UP,
+ EL_BD_BUTTERFLY_RIGHT,
+ EL_BD_BUTTERFLY_DOWN,
+ EL_BD_BUTTERFLY_LEFT
+ },
+ {
+ EL_BD_FIREFLY_UP,
+ EL_BD_FIREFLY_RIGHT,
+ EL_BD_FIREFLY_DOWN,
+ EL_BD_FIREFLY_LEFT
+ },
+ {
+ EL_PACMAN_UP,
+ EL_PACMAN_RIGHT,
+ EL_PACMAN_DOWN,
+ EL_PACMAN_LEFT
+ },
+ {
+ EL_YAMYAM_UP,
+ EL_YAMYAM_RIGHT,
+ EL_YAMYAM_DOWN,
+ EL_YAMYAM_LEFT
+ },
+ {
+ EL_ARROW_UP,
+ EL_ARROW_RIGHT,
+ EL_ARROW_DOWN,
+ EL_ARROW_LEFT
+ },
+ {
+ EL_SP_PORT_UP,
+ EL_SP_PORT_RIGHT,
+ EL_SP_PORT_DOWN,
+ EL_SP_PORT_LEFT
+ },
+ {
+ EL_SP_GRAVITY_PORT_UP,
+ EL_SP_GRAVITY_PORT_RIGHT,
+ EL_SP_GRAVITY_PORT_DOWN,
+ EL_SP_GRAVITY_PORT_LEFT
+ },
+ {
+ EL_SP_GRAVITY_ON_PORT_UP,
+ EL_SP_GRAVITY_ON_PORT_RIGHT,
+ EL_SP_GRAVITY_ON_PORT_DOWN,
+ EL_SP_GRAVITY_ON_PORT_LEFT
+ },
+ {
+ EL_SP_GRAVITY_OFF_PORT_UP,
+ EL_SP_GRAVITY_OFF_PORT_RIGHT,
+ EL_SP_GRAVITY_OFF_PORT_DOWN,
+ EL_SP_GRAVITY_OFF_PORT_LEFT
+ },
+ {
+ EL_MOLE_UP,
+ EL_MOLE_RIGHT,
+ EL_MOLE_DOWN,
+ EL_MOLE_LEFT
+ },
+ {
+ EL_BALLOON_SWITCH_UP,
+ EL_BALLOON_SWITCH_RIGHT,
+ EL_BALLOON_SWITCH_DOWN,
+ EL_BALLOON_SWITCH_LEFT
+ },
+ {
+ EL_MM_MCDUFFIN_UP,
+ EL_MM_MCDUFFIN_RIGHT,
+ EL_MM_MCDUFFIN_DOWN,
+ EL_MM_MCDUFFIN_LEFT
+ },
+ {
+ EL_MM_MIRROR_FIXED_1,
+ EL_MM_MIRROR_FIXED_4,
+ EL_MM_MIRROR_FIXED_3,
+ EL_MM_MIRROR_FIXED_2
+ },
+ {
+ EL_MM_STEEL_GRID_FIXED_1,
+ EL_MM_STEEL_GRID_FIXED_4,
+ EL_MM_STEEL_GRID_FIXED_2,
+ EL_MM_STEEL_GRID_FIXED_3
+ },
+ {
+ EL_MM_WOODEN_GRID_FIXED_1,
+ EL_MM_WOODEN_GRID_FIXED_4,
+ EL_MM_WOODEN_GRID_FIXED_2,
+ EL_MM_WOODEN_GRID_FIXED_3
+ },
+ {
+ EL_MM_POLARIZER_CROSS_1,
+ EL_MM_POLARIZER_CROSS_4,
+ EL_MM_POLARIZER_CROSS_3,
+ EL_MM_POLARIZER_CROSS_2
+ },
+ {
+ EL_MM_PACMAN_UP,
+ EL_MM_PACMAN_RIGHT,
+ EL_MM_PACMAN_DOWN,
+ EL_MM_PACMAN_LEFT
+ },
+ {
+ EL_DF_LASER_UP,
+ EL_DF_LASER_RIGHT,
+ EL_DF_LASER_DOWN,
+ EL_DF_LASER_LEFT
+ },
+ {
+ EL_DF_RECEIVER_UP,
+ EL_DF_RECEIVER_RIGHT,
+ EL_DF_RECEIVER_DOWN,
+ EL_DF_RECEIVER_LEFT
+ },
+ {
+ EL_DF_SLOPE_1,
+ EL_DF_SLOPE_4,
+ EL_DF_SLOPE_3,
+ EL_DF_SLOPE_2
+ },
+
+ {
+ -1,
+ },
+ };
+ static int rotatable_elements_8[][8] =
+ {
+ {
+ EL_DF_STEEL_GRID_FIXED_1,
+ EL_DF_STEEL_GRID_FIXED_8,
+ EL_DF_STEEL_GRID_FIXED_7,
+ EL_DF_STEEL_GRID_FIXED_6,
+ EL_DF_STEEL_GRID_FIXED_5,
+ EL_DF_STEEL_GRID_FIXED_4,
+ EL_DF_STEEL_GRID_FIXED_3,
+ EL_DF_STEEL_GRID_FIXED_2
+ },
+ {
+ EL_DF_WOODEN_GRID_FIXED_1,
+ EL_DF_WOODEN_GRID_FIXED_8,
+ EL_DF_WOODEN_GRID_FIXED_7,
+ EL_DF_WOODEN_GRID_FIXED_6,
+ EL_DF_WOODEN_GRID_FIXED_5,
+ EL_DF_WOODEN_GRID_FIXED_4,
+ EL_DF_WOODEN_GRID_FIXED_3,
+ EL_DF_WOODEN_GRID_FIXED_2
+ },
+ {
+ EL_DF_STEEL_GRID_ROTATING_1,
+ EL_DF_STEEL_GRID_ROTATING_8,
+ EL_DF_STEEL_GRID_ROTATING_7,
+ EL_DF_STEEL_GRID_ROTATING_6,
+ EL_DF_STEEL_GRID_ROTATING_5,
+ EL_DF_STEEL_GRID_ROTATING_4,
+ EL_DF_STEEL_GRID_ROTATING_3,
+ EL_DF_STEEL_GRID_ROTATING_2
+ },
+ {
+ EL_DF_WOODEN_GRID_ROTATING_1,
+ EL_DF_WOODEN_GRID_ROTATING_8,
+ EL_DF_WOODEN_GRID_ROTATING_7,
+ EL_DF_WOODEN_GRID_ROTATING_6,
+ EL_DF_WOODEN_GRID_ROTATING_5,
+ EL_DF_WOODEN_GRID_ROTATING_4,
+ EL_DF_WOODEN_GRID_ROTATING_3,
+ EL_DF_WOODEN_GRID_ROTATING_2
+ },
+
+ {
+ -1,
+ },
+ };
+ static int rotatable_elements_16[][16] =
+ {
+ {
+ EL_MM_MIRROR_1,
+ EL_MM_MIRROR_16,
+ EL_MM_MIRROR_15,
+ EL_MM_MIRROR_14,
+ EL_MM_MIRROR_13,
+ EL_MM_MIRROR_12,
+ EL_MM_MIRROR_11,
+ EL_MM_MIRROR_10,
+ EL_MM_MIRROR_9,
+ EL_MM_MIRROR_8,
+ EL_MM_MIRROR_7,
+ EL_MM_MIRROR_6,
+ EL_MM_MIRROR_5,
+ EL_MM_MIRROR_4,
+ EL_MM_MIRROR_3,
+ EL_MM_MIRROR_2
+ },
+ {
+ EL_MM_TELEPORTER_5,
+ EL_MM_TELEPORTER_4,
+ EL_MM_TELEPORTER_3,
+ EL_MM_TELEPORTER_2,
+ EL_MM_TELEPORTER_1,
+ EL_MM_TELEPORTER_16,
+ EL_MM_TELEPORTER_15,
+ EL_MM_TELEPORTER_14,
+ EL_MM_TELEPORTER_13,
+ EL_MM_TELEPORTER_12,
+ EL_MM_TELEPORTER_11,
+ EL_MM_TELEPORTER_10,
+ EL_MM_TELEPORTER_9,
+ EL_MM_TELEPORTER_8,
+ EL_MM_TELEPORTER_7,
+ EL_MM_TELEPORTER_6
+ },
+ {
+ EL_MM_TELEPORTER_RED_5,
+ EL_MM_TELEPORTER_RED_4,
+ EL_MM_TELEPORTER_RED_3,
+ EL_MM_TELEPORTER_RED_2,
+ EL_MM_TELEPORTER_RED_1,
+ EL_MM_TELEPORTER_RED_16,
+ EL_MM_TELEPORTER_RED_15,
+ EL_MM_TELEPORTER_RED_14,
+ EL_MM_TELEPORTER_RED_13,
+ EL_MM_TELEPORTER_RED_12,
+ EL_MM_TELEPORTER_RED_11,
+ EL_MM_TELEPORTER_RED_10,
+ EL_MM_TELEPORTER_RED_9,
+ EL_MM_TELEPORTER_RED_8,
+ EL_MM_TELEPORTER_RED_7,
+ EL_MM_TELEPORTER_RED_6
+ },
+ {
+ EL_MM_TELEPORTER_YELLOW_5,
+ EL_MM_TELEPORTER_YELLOW_4,
+ EL_MM_TELEPORTER_YELLOW_3,
+ EL_MM_TELEPORTER_YELLOW_2,
+ EL_MM_TELEPORTER_YELLOW_1,
+ EL_MM_TELEPORTER_YELLOW_16,
+ EL_MM_TELEPORTER_YELLOW_15,
+ EL_MM_TELEPORTER_YELLOW_14,
+ EL_MM_TELEPORTER_YELLOW_13,
+ EL_MM_TELEPORTER_YELLOW_12,
+ EL_MM_TELEPORTER_YELLOW_11,
+ EL_MM_TELEPORTER_YELLOW_10,
+ EL_MM_TELEPORTER_YELLOW_9,
+ EL_MM_TELEPORTER_YELLOW_8,
+ EL_MM_TELEPORTER_YELLOW_7,
+ EL_MM_TELEPORTER_YELLOW_6
+ },
+ {
+ EL_MM_TELEPORTER_GREEN_5,
+ EL_MM_TELEPORTER_GREEN_4,
+ EL_MM_TELEPORTER_GREEN_3,
+ EL_MM_TELEPORTER_GREEN_2,
+ EL_MM_TELEPORTER_GREEN_1,
+ EL_MM_TELEPORTER_GREEN_16,
+ EL_MM_TELEPORTER_GREEN_15,
+ EL_MM_TELEPORTER_GREEN_14,
+ EL_MM_TELEPORTER_GREEN_13,
+ EL_MM_TELEPORTER_GREEN_12,
+ EL_MM_TELEPORTER_GREEN_11,
+ EL_MM_TELEPORTER_GREEN_10,
+ EL_MM_TELEPORTER_GREEN_9,
+ EL_MM_TELEPORTER_GREEN_8,
+ EL_MM_TELEPORTER_GREEN_7,
+ EL_MM_TELEPORTER_GREEN_6
+ },
+ {
+ EL_MM_TELEPORTER_BLUE_5,
+ EL_MM_TELEPORTER_BLUE_4,
+ EL_MM_TELEPORTER_BLUE_3,
+ EL_MM_TELEPORTER_BLUE_2,
+ EL_MM_TELEPORTER_BLUE_1,
+ EL_MM_TELEPORTER_BLUE_16,
+ EL_MM_TELEPORTER_BLUE_15,
+ EL_MM_TELEPORTER_BLUE_14,
+ EL_MM_TELEPORTER_BLUE_13,
+ EL_MM_TELEPORTER_BLUE_12,
+ EL_MM_TELEPORTER_BLUE_11,
+ EL_MM_TELEPORTER_BLUE_10,
+ EL_MM_TELEPORTER_BLUE_9,
+ EL_MM_TELEPORTER_BLUE_8,
+ EL_MM_TELEPORTER_BLUE_7,
+ EL_MM_TELEPORTER_BLUE_6
+ },
+ {
+ EL_MM_POLARIZER_1,
+ EL_MM_POLARIZER_16,
+ EL_MM_POLARIZER_15,
+ EL_MM_POLARIZER_14,
+ EL_MM_POLARIZER_13,
+ EL_MM_POLARIZER_12,
+ EL_MM_POLARIZER_11,
+ EL_MM_POLARIZER_10,
+ EL_MM_POLARIZER_9,
+ EL_MM_POLARIZER_8,
+ EL_MM_POLARIZER_7,
+ EL_MM_POLARIZER_6,
+ EL_MM_POLARIZER_5,
+ EL_MM_POLARIZER_4,
+ EL_MM_POLARIZER_3,
+ EL_MM_POLARIZER_2
+ },
+ {
+ EL_DF_MIRROR_1,
+ EL_DF_MIRROR_16,
+ EL_DF_MIRROR_15,
+ EL_DF_MIRROR_14,
+ EL_DF_MIRROR_13,
+ EL_DF_MIRROR_12,
+ EL_DF_MIRROR_11,
+ EL_DF_MIRROR_10,
+ EL_DF_MIRROR_9,
+ EL_DF_MIRROR_8,
+ EL_DF_MIRROR_7,
+ EL_DF_MIRROR_6,
+ EL_DF_MIRROR_5,
+ EL_DF_MIRROR_4,
+ EL_DF_MIRROR_3,
+ EL_DF_MIRROR_2
+ },
+ {
+ EL_DF_MIRROR_ROTATING_1,
+ EL_DF_MIRROR_ROTATING_16,
+ EL_DF_MIRROR_ROTATING_15,
+ EL_DF_MIRROR_ROTATING_14,
+ EL_DF_MIRROR_ROTATING_13,
+ EL_DF_MIRROR_ROTATING_12,
+ EL_DF_MIRROR_ROTATING_11,
+ EL_DF_MIRROR_ROTATING_10,
+ EL_DF_MIRROR_ROTATING_9,
+ EL_DF_MIRROR_ROTATING_8,
+ EL_DF_MIRROR_ROTATING_7,
+ EL_DF_MIRROR_ROTATING_6,
+ EL_DF_MIRROR_ROTATING_5,
+ EL_DF_MIRROR_ROTATING_4,
+ EL_DF_MIRROR_ROTATING_3,
+ EL_DF_MIRROR_ROTATING_2
+ },
+ {
+ EL_DF_MIRROR_FIXED_1,
+ EL_DF_MIRROR_FIXED_16,
+ EL_DF_MIRROR_FIXED_15,
+ EL_DF_MIRROR_FIXED_14,
+ EL_DF_MIRROR_FIXED_13,
+ EL_DF_MIRROR_FIXED_12,
+ EL_DF_MIRROR_FIXED_11,
+ EL_DF_MIRROR_FIXED_10,
+ EL_DF_MIRROR_FIXED_9,
+ EL_DF_MIRROR_FIXED_8,
+ EL_DF_MIRROR_FIXED_7,
+ EL_DF_MIRROR_FIXED_6,
+ EL_DF_MIRROR_FIXED_5,
+ EL_DF_MIRROR_FIXED_4,
+ EL_DF_MIRROR_FIXED_3,
+ EL_DF_MIRROR_FIXED_2
+ },
+
+ {
+ -1,
+ },
+ };
+ int i, j;
+
+ for (i = 0; swappable_elements[i][0] != -1; i++)
+ {
+ int element1 = swappable_elements[i][0];
+ int element2 = swappable_elements[i][1];
+
+ if (old_element == element1 || old_element == element2)
+ new_element = (old_element == element1 ? element2 : element1);
+ }
+
+ for (i = 0; rotatable_elements_4[i][0] != -1; i++)
+ {
+ for (j = 0; j < 4; j++)
+ {
+ int element = rotatable_elements_4[i][j];
+
+ if (old_element == element)
+ new_element = (button == 1 ? rotatable_elements_4[i][(j + 3) % 4] :
+ button == 2 ? rotatable_elements_4[i][0] :
+ button == 3 ? rotatable_elements_4[i][(j + 1) % 4] :
+ old_element);
+ }
+ }
+
+ for (i = 0; rotatable_elements_8[i][0] != -1; i++)
+ {
+ for (j = 0; j < 8; j++)
+ {
+ int element = rotatable_elements_8[i][j];
+
+ if (old_element == element)
+ new_element = (button == 1 ? rotatable_elements_8[i][(j + 7) % 8] :
+ button == 2 ? rotatable_elements_8[i][0] :
+ button == 3 ? rotatable_elements_8[i][(j + 1) % 8] :
+ old_element);
+ }
+ }
+
+ for (i = 0; rotatable_elements_16[i][0] != -1; i++)
+ {
+ for (j = 0; j < 16; j++)
+ {
+ int element = rotatable_elements_16[i][j];
+
+ if (old_element == element)
+ new_element = (button == 1 ? rotatable_elements_16[i][(j + 15) % 16] :
+ button == 2 ? rotatable_elements_16[i][0] :
+ button == 3 ? rotatable_elements_16[i][(j + 1) % 16] :
+ old_element);
+ }
+ }
+
+ if (old_element != new_element)
+ {
+ int max_infotext_len = getMaxInfoTextLength();
+ char infotext[MAX_OUTPUT_LINESIZE + 1];
+
+ strncpy(infotext, getElementInfoText(new_element), max_infotext_len);
+ infotext[max_infotext_len] = '\0';
+
+ ClearEditorGadgetInfoText();
+
+ DrawTextS(INFOTEXT_XPOS - SX, INFOTEXT_YPOS - SY, INFOTEXT_FONT,
+ infotext);
+ }
+ }
+
+ if (IS_MM_WALL_EDITOR(new_element))
+ SetElementSimpleExt(x, y, dx, dy, new_element, change_level);
+ else
+ SetElementSimple(x, y, new_element, change_level);
+
+ last_x = x;
+ last_y = y;
+}
+
+static void ResetIntelliDraw(void)
+{
+ int x, y;
+
+ for (x = 0; x < lev_fieldx; x++)
+ for (y = 0; y < lev_fieldy; y++)
+ IntelliDrawBuffer[x][y] = Tile[x][y];
+
+ SetElementIntelliDraw(-1, -1, -1, -1, EL_UNDEFINED, FALSE, -1);