rnd-20021019-2-src
[rocksndiamonds.git] / src / tools.c
index 74d003cdbf7b2bdc65d71b8b43024ebc00a3824f..63324e0a698788483c450aea5d0f51e56e5d42f2 100644 (file)
@@ -690,7 +690,7 @@ static int getGraphicAnimationPhase(int frames, int delay, int mode)
 {
   int phase;
 
-  if (mode == ANIM_PINGPONG)
+  if (mode & ANIM_PINGPONG)
   {
     int max_anim_frames = 2 * frames - 2;
 
@@ -700,24 +700,35 @@ static int getGraphicAnimationPhase(int frames, int delay, int mode)
   else
     phase = (FrameCounter % (delay * frames)) / delay;
 
-  if (mode == ANIM_REVERSE)
+  if (mode & ANIM_REVERSE)
     phase = -phase;
 
   return phase;
 }
 
-static int getNewGraphicAnimationFrame(int graphic, int sync_frame)
+int getNewGraphicAnimationFrame(int graphic, int sync_frame)
 {
   int num_frames = new_graphic_info[graphic].anim_frames;
   int delay = new_graphic_info[graphic].anim_delay;
   int mode = new_graphic_info[graphic].anim_mode;
-  int frame;
+  int frame = 0;
 
   /* animation synchronized with global frame counter, not move position */
   if (new_graphic_info[graphic].anim_global_sync || sync_frame < 0)
     sync_frame = FrameCounter;
 
-  if (mode & ANIM_PINGPONG)            /* use border frames once */
+  if (mode & ANIM_LOOP)                        /* normal, looping animation */
+  {
+    frame = (sync_frame % (delay * num_frames)) / delay;
+  }
+  else if (mode & ANIM_LINEAR)         /* normal, non-looping animation */
+  {
+    frame = sync_frame / delay;
+
+    if (frame > num_frames - 1)
+      frame = num_frames - 1;
+  }
+  else if (mode & ANIM_PINGPONG)       /* use border frames once */
   {
     int max_anim_frames = 2 * num_frames - 2;
 
@@ -731,8 +742,6 @@ static int getNewGraphicAnimationFrame(int graphic, int sync_frame)
     frame = (sync_frame % (delay * max_anim_frames)) / delay;
     frame = (frame < num_frames ? frame : max_anim_frames - frame - 1);
   }
-  else /* mode == ANIM_NORMAL || mode == ANIM_REVERSE */
-    frame = (sync_frame % (delay * num_frames)) / delay;
 
   if (mode & ANIM_REVERSE)             /* use reverse animation direction */
     frame = num_frames - frame - 1;
@@ -756,9 +765,13 @@ void DrawGraphicAnimationExt(int x, int y, int graphic,
 
 void DrawNewGraphicAnimationExt(int x, int y, int graphic, int mask_mode)
 {
+#if 0
   int delay = new_graphic_info[graphic].anim_delay;
 
   if (!(FrameCounter % delay) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+#else
+  if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+#endif
   {
     int frame = getNewGraphicAnimationFrame(graphic, -1);
 
@@ -902,11 +915,11 @@ void DrawNewGraphicExt(DrawBuffer *dst_bitmap, int x, int y, int graphic,
   Bitmap *src_bitmap = new_graphic_info[graphic].bitmap;
   int src_x = new_graphic_info[graphic].src_x;
   int src_y = new_graphic_info[graphic].src_y;
+  int offset_x = new_graphic_info[graphic].offset_x;
+  int offset_y = new_graphic_info[graphic].offset_y;
 
-  if (new_graphic_info[graphic].anim_vertical)
-    src_y += frame * TILEY;
-  else
-    src_x += frame * TILEX;
+  src_x += frame * offset_x;
+  src_y += frame * offset_y;
 
   BlitBitmap(src_bitmap, dst_bitmap, src_x, src_y, TILEX, TILEY, x, y);
 }
@@ -983,11 +996,11 @@ void DrawNewGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y,
   GC drawing_gc = src_bitmap->stored_clip_gc;
   int src_x = new_graphic_info[graphic].src_x;
   int src_y = new_graphic_info[graphic].src_y;
+  int offset_x = new_graphic_info[graphic].offset_x;
+  int offset_y = new_graphic_info[graphic].offset_y;
 
-  if (new_graphic_info[graphic].anim_vertical)
-    src_y += frame * TILEY;
-  else
-    src_x += frame * TILEX;
+  src_x += frame * offset_x;
+  src_y += frame * offset_y;
 
   SetClipOrigin(src_bitmap, drawing_gc, dest_x - src_x, dest_y - src_y);
   BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y);
@@ -995,8 +1008,16 @@ void DrawNewGraphicThruMaskExt(DrawBuffer *d, int dest_x, int dest_y,
 
 void DrawMiniGraphic(int x, int y, int graphic)
 {
-  DrawMiniGraphicExt(drawto, SX + x*MINI_TILEX, SY + y*MINI_TILEY, graphic);
-  MarkTileDirty(x/2, y/2);
+  DrawMiniGraphicExt(drawto,
+                    SX + x * MINI_TILEX, SY + y * MINI_TILEY, graphic);
+  MarkTileDirty(x / 2, y / 2);
+}
+
+void DrawNewMiniGraphic(int x, int y, int graphic)
+{
+  DrawNewMiniGraphicExt(drawto,
+                       SX + x * MINI_TILEX, SY + y * MINI_TILEY, graphic);
+  MarkTileDirty(x / 2, y / 2);
 }
 
 void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
@@ -1044,6 +1065,19 @@ void getMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
   }
 }
 
+void getNewMiniGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
+{
+  Bitmap *src_bitmap = new_graphic_info[graphic].bitmap;
+  int mini_startx = 0;
+  int mini_starty = src_bitmap->height * 2 / 3;
+  int src_x = mini_startx + new_graphic_info[graphic].src_x / 2;
+  int src_y = mini_starty + new_graphic_info[graphic].src_y / 2;
+
+  *bitmap = src_bitmap;
+  *x = src_x;
+  *y = src_y;
+}
+
 void DrawMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic)
 {
   Bitmap *bitmap;
@@ -1053,6 +1087,24 @@ void DrawMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic)
   BlitBitmap(bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
 }
 
+void DrawNewMiniGraphicExt(DrawBuffer *d, int x, int y, int graphic)
+{
+#if 1
+  Bitmap *src_bitmap;
+  int src_x, src_y;
+
+  getNewMiniGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
+#else
+  Bitmap *src_bitmap = new_graphic_info[graphic].bitmap;
+  int mini_startx = src_bitmap->width  * 2 / 3;
+  int mini_starty = src_bitmap->height * 2 / 3;
+  int src_x = mini_startx + new_graphic_info[graphic].src_x / 2;
+  int src_y = mini_starty + new_graphic_info[graphic].src_y / 2;
+#endif
+
+  BlitBitmap(src_bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
+}
+
 void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic,
                        int cut_mode, int mask_mode)
 {
@@ -1187,6 +1239,8 @@ void DrawNewGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame,
   GC drawing_gc;
   int src_x;
   int src_y;
+  int offset_x;
+  int offset_y;
 
   int width = TILEX, height = TILEY;
   int cx = 0, cy = 0;
@@ -1266,11 +1320,11 @@ void DrawNewGraphicShifted(int x,int y, int dx,int dy, int graphic, int frame,
   drawing_gc = src_bitmap->stored_clip_gc;
   src_x = new_graphic_info[graphic].src_x;
   src_y = new_graphic_info[graphic].src_y;
+  offset_x = new_graphic_info[graphic].offset_x;
+  offset_y = new_graphic_info[graphic].offset_y;
 
-  if (new_graphic_info[graphic].anim_vertical)
-    src_y += frame * TILEY;
-  else
-    src_x += frame * TILEX;
+  src_x += frame * offset_x;
+  src_y += frame * offset_y;
 
   src_x += cx;
   src_y += cy;
@@ -1344,7 +1398,7 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
   }
   else if (element == EL_SP_ELECTRON)
   {
-    graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_NORMAL);
+    graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_LOOP);
   }
   else if (element == EL_MOLE || element == EL_PENGUIN ||
           element == EL_PIG || element == EL_DRAGON)
@@ -1370,11 +1424,11 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
   }
   else if (element == EL_SATELLITE)
   {
-    graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_NORMAL);
+    graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_LOOP);
   }
   else if (element == EL_ACID)
   {
-    graphic = GFX_GEBLUBBER + getGraphicAnimationPhase(4, 10, ANIM_NORMAL);
+    graphic = GFX_GEBLUBBER + getGraphicAnimationPhase(4, 10, ANIM_LOOP);
   }
   else if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
   {
@@ -1457,101 +1511,66 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
     DrawGraphic(x, y, graphic);
 }
 
+inline static int getFramePosition(int x, int y)
+{
+  int element = Feld[x][y];
+  int frame_pos = -1;
+
+  if (element == EL_QUICKSAND_FULL ||
+      element == EL_MAGIC_WALL_FULL ||
+      element == EL_BD_MAGIC_WALL_FULL)
+    frame_pos = -1;
+  else if (IS_MOVING(x, y) || CAN_MOVE(element) || CAN_FALL(element))
+    frame_pos = ABS(MovPos[x][y]) / (TILEX / 8);
+
+  return frame_pos;
+}
+
+inline static int getGfxAction(int x, int y)
+{
+  int gfx_action = GFX_ACTION_DEFAULT;
+
+  if (GfxAction[x][y] != GFX_ACTION_DEFAULT)
+    gfx_action = GfxAction[x][y];
+  else if (IS_MOVING(x, y))
+    gfx_action = GFX_ACTION_MOVING;
+
+  return gfx_action;
+}
+
 void DrawNewScreenElementExt(int x, int y, int dx, int dy, int element,
-                         int cut_mode, int mask_mode)
+                            int cut_mode, int mask_mode)
 {
   int ux = LEVELX(x), uy = LEVELY(y);
   int move_dir = MovDir[ux][uy];
-  int move_pos = ABS(MovPos[ux][uy]) / (TILEX / 8);
-  int graphic = el_dir2img(element, move_dir);
+  int move_pos = getFramePosition(ux, uy);
+  int gfx_action = getGfxAction(ux, uy);
+  int graphic = el_dir_act2img(element, move_dir, gfx_action);
   int frame = getNewGraphicAnimationFrame(graphic, move_pos);
-  int phase8 = move_pos;
-  int phase4 = phase8 / 2;
-  int phase2  = phase8 / 4;
-
-  int dir = move_dir;  /* !!! THROW AWAY LATER !!! */
 
-  if (0)
+  if (element == EL_WALL_GROWING)
   {
-    ;
-  }
-#if 0
-  else if (element == EL_PACMAN || element == EL_BUG ||
-          element == EL_SPACESHIP)
-  {
-    graphic += 1 * !phase2;
+    boolean left_stopped = FALSE, right_stopped = FALSE;
 
-    if (dir == MV_UP)
-      graphic += 1 * 2;
-    else if (dir == MV_LEFT)
-      graphic += 2 * 2;
-    else if (dir == MV_DOWN)
-      graphic += 3 * 2;
-  }
-  else if (element == EL_SP_SNIKSNAK)
-  {
-    if (dir == MV_LEFT)
-      graphic = GFX_SP_SNIKSNAK_LEFT;
-    else if (dir == MV_RIGHT)
-      graphic = GFX_SP_SNIKSNAK_RIGHT;
-    else if (dir == MV_UP)
-      graphic = GFX_SP_SNIKSNAK_UP;
-    else
-      graphic = GFX_SP_SNIKSNAK_DOWN;
+    if (!IN_LEV_FIELD(ux - 1, uy) || IS_MAUER(Feld[ux - 1][uy]))
+      left_stopped = TRUE;
+    if (!IN_LEV_FIELD(ux + 1, uy) || IS_MAUER(Feld[ux + 1][uy]))
+      right_stopped = TRUE;
 
-    graphic += (phase8 < 4 ? phase8 : 7 - phase8);
-  }
-  else if (element == EL_SP_ELECTRON)
-  {
-    graphic = GFX2_SP_ELECTRON + getGraphicAnimationPhase(8, 2, ANIM_NORMAL);
-  }
-#endif
-  else if (element == EL_MOLE || element == EL_PENGUIN ||
-          element == EL_PIG || element == EL_DRAGON)
-  {
-    if (dir == MV_LEFT)
-      graphic = (element == EL_MOLE ? GFX_MOLE_LEFT :
-                element == EL_PENGUIN ? GFX_PINGUIN_LEFT :
-                element == EL_PIG ? GFX_SCHWEIN_LEFT : GFX_DRACHE_LEFT);
-    else if (dir == MV_RIGHT)
-      graphic = (element == EL_MOLE ? GFX_MOLE_RIGHT :
-                element == EL_PENGUIN ? GFX_PINGUIN_RIGHT :
-                element == EL_PIG ? GFX_SCHWEIN_RIGHT : GFX_DRACHE_RIGHT);
-    else if (dir == MV_UP)
-      graphic = (element == EL_MOLE ? GFX_MOLE_UP :
-                element == EL_PENGUIN ? GFX_PINGUIN_UP :
-                element == EL_PIG ? GFX_SCHWEIN_UP : GFX_DRACHE_UP);
-    else
-      graphic = (element == EL_MOLE ? GFX_MOLE_DOWN :
-                element == EL_PENGUIN ? GFX_PINGUIN_DOWN :
-                element == EL_PIG ? GFX_SCHWEIN_DOWN : GFX_DRACHE_DOWN);
-
-    graphic += phase4;
-  }
-  else if (element == EL_SATELLITE)
-  {
-#if 1
-    graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_NORMAL);
-#else
-    graphic = GFX_SONDE_START + getNewGraphicAnimationFrame(graphic, move_pos);
-#endif
-  }
-  else if (element == EL_ACID)
-  {
-#if 1
-    graphic = GFX_GEBLUBBER + getGraphicAnimationPhase(4, 10, ANIM_NORMAL);
-#else
-    graphic = GFX_GEBLUBBER + getNewGraphicAnimationFrame(graphic, move_pos);
-#endif
-  }
-  else if (element == EL_BD_BUTTERFLY || element == EL_BD_FIREFLY)
-  {
-    graphic += !phase2;
-  }
-  else if (element == EL_BALLOON)
-  {
-    graphic += phase4;
+    if (left_stopped && right_stopped)
+      graphic = IMG_WALL;
+    else if (left_stopped)
+    {
+      graphic = IMG_WALL_GROWING_ACTIVE_RIGHT;
+      frame = new_graphic_info[graphic].anim_frames - 1;
+    }
+    else if (right_stopped)
+    {
+      graphic = IMG_WALL_GROWING_ACTIVE_LEFT;
+      frame = new_graphic_info[graphic].anim_frames - 1;
+    }
   }
+#if 0
   else if ((element == EL_ROCK ||
            element == EL_SP_ZONK ||
            element == EL_BD_ROCK ||
@@ -1565,9 +1584,9 @@ void DrawNewScreenElementExt(int x, int y, int dx, int dy, int element,
          element == EL_SP_ZONK ||
          element == EL_BD_ROCK)
       {
-       if (dir == MV_LEFT)
+       if (move_dir == MV_LEFT)
          graphic += (4 - phase4) % 4;
-       else if (dir == MV_RIGHT)
+       else if (move_dir == MV_RIGHT)
          graphic += phase4;
        else
          graphic += phase2 * 2;
@@ -1576,50 +1595,17 @@ void DrawNewScreenElementExt(int x, int y, int dx, int dy, int element,
        graphic += phase2;
     }
   }
-  else if (element == EL_MAGIC_WALL_ACTIVE ||
-          element == EL_MAGIC_WALL_EMPTYING ||
-          element == EL_BD_MAGIC_WALL_ACTIVE ||
-          element == EL_BD_MAGIC_WALL_EMPTYING ||
-          element == EL_MAGIC_WALL_FULL ||
-          element == EL_BD_MAGIC_WALL_FULL)
-  {
-#if 1
-    graphic += 3 + getGraphicAnimationPhase(4, 4, ANIM_REVERSE);
-#else
-    graphic += 3 + getNewGraphicAnimationFrame(graphic, move_pos);
 #endif
-  }
   else if (IS_AMOEBOID(element) || element == EL_AMOEBA_DRIPPING)
   {
-    graphic = (element == EL_AMOEBA_DEAD ? GFX_AMOEBE_TOT : GFX_AMOEBE_LEBT);
-    graphic += (x + 2 * y + 4) % 4;
-  }
-  else if (element == EL_WALL_GROWING)
-  {
-    boolean links_massiv = FALSE, rechts_massiv = FALSE;
+    graphic = (element == EL_BD_AMOEBA ? IMG_BD_AMOEBA_PART1 :
+              element == EL_AMOEBA_WET ? IMG_AMOEBA_WET_PART1 :
+              element == EL_AMOEBA_DRY ? IMG_AMOEBA_DRY_PART1 :
+              element == EL_AMOEBA_FULL ? IMG_AMOEBA_FULL_PART1 :
+              IMG_AMOEBA_DEAD_PART1);
 
-    if (!IN_LEV_FIELD(ux-1, uy) || IS_MAUER(Feld[ux-1][uy]))
-      links_massiv = TRUE;
-    if (!IN_LEV_FIELD(ux+1, uy) || IS_MAUER(Feld[ux+1][uy]))
-      rechts_massiv = TRUE;
-
-    if (links_massiv && rechts_massiv)
-      graphic = GFX_MAUERWERK;
-    else if (links_massiv)
-      graphic = GFX_MAUER_R;
-    else if (rechts_massiv)
-      graphic = GFX_MAUER_L;
-  }
-#if 0
-  else if ((element == EL_INVISIBLE_STEELWALL ||
-           element == EL_INVISIBLE_WALL ||
-           element == EL_INVISIBLE_SAND) && game.light_time_left)
-  {
-    graphic = (element == EL_INVISIBLE_STEELWALL ? GFX_INVISIBLE_STEEL_ON :
-              element == EL_INVISIBLE_WALL ? GFX_UNSICHTBAR_ON :
-              GFX_SAND_INVISIBLE_ON);
+    graphic += (x + 2 * y + 4) % 4;
   }
-#endif
 
   if (dx || dy)
     DrawNewGraphicShifted(x, y, dx, dy, graphic, frame, cut_mode, mask_mode);
@@ -2078,6 +2064,22 @@ void DrawMiniElement(int x, int y, int element)
   DrawMiniGraphic(x, y, graphic);
 }
 
+void DrawNewMiniElement(int x, int y, int element)
+{
+  int graphic;
+
+#if 0
+  if (!element)
+  {
+    DrawNewMiniGraphic(x, y, -1);
+    return;
+  }
+#endif
+
+  graphic = el2img(element);
+  DrawNewMiniGraphic(x, y, graphic);
+}
+
 void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y)
 {
   int x = sx + scroll_x, y = sy + scroll_y;
@@ -2112,6 +2114,40 @@ void DrawMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y)
   }
 }
 
+void DrawNewMiniElementOrWall(int sx, int sy, int scroll_x, int scroll_y)
+{
+  int x = sx + scroll_x, y = sy + scroll_y;
+
+  if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
+    DrawNewMiniElement(sx, sy, EL_EMPTY);
+  else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
+    DrawNewMiniElement(sx, sy, Feld[x][y]);
+  else
+  {
+    int steel_type, steel_position;
+    int border[6][2] =
+    {
+      { IMG_STEELWALL_TOPLEFT,         IMG_INVISIBLE_STEELWALL_TOPLEFT     },
+      { IMG_STEELWALL_TOPRIGHT,                IMG_INVISIBLE_STEELWALL_TOPRIGHT    },
+      { IMG_STEELWALL_BOTTOMLEFT,      IMG_INVISIBLE_STEELWALL_BOTTOMLEFT  },
+      { IMG_STEELWALL_BOTTOMRIGHT,     IMG_INVISIBLE_STEELWALL_BOTTOMRIGHT },
+      { IMG_STEELWALL_VERTICAL,                IMG_INVISIBLE_STEELWALL_VERTICAL    },
+      { IMG_STEELWALL_HORIZONTAL,      IMG_INVISIBLE_STEELWALL_HORIZONTAL  }
+    };
+
+    steel_type = (BorderElement == EL_STEELWALL ? 0 : 1);
+    steel_position = (x == -1 && y == -1                       ? 0 :
+                     x == lev_fieldx && y == -1                ? 1 :
+                     x == -1 && y == lev_fieldy                ? 2 :
+                     x == lev_fieldx && y == lev_fieldy        ? 3 :
+                     x == -1 || x == lev_fieldx                ? 4 :
+                     y == -1 || y == lev_fieldy                ? 5 : -1);
+
+    if (steel_position != -1)
+      DrawNewMiniGraphic(sx, sy, border[steel_position][steel_type]);
+  }
+}
+
 void DrawMicroElement(int xpos, int ypos, int element)
 {
   int graphic;
@@ -2160,6 +2196,35 @@ void DrawMicroElement(int xpos, int ypos, int element)
               MICRO_TILEX, MICRO_TILEY, xpos, ypos);
 }
 
+void getNewMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
+{
+  Bitmap *src_bitmap = new_graphic_info[graphic].bitmap;
+  int mini_startx = src_bitmap->width * 3 / 4;
+  int mini_starty = src_bitmap->height * 2 / 3;
+  int src_x = mini_startx + new_graphic_info[graphic].src_x / 8;
+  int src_y = mini_starty + new_graphic_info[graphic].src_y / 8;
+
+  *bitmap = src_bitmap;
+  *x = src_x;
+  *y = src_y;
+}
+
+void DrawNewMicroElement(int xpos, int ypos, int element)
+{
+  Bitmap *src_bitmap;
+  int src_x, src_y;
+  int graphic;
+
+  if (element == EL_EMPTY)
+    return;
+
+  graphic = el2img(element);
+
+  getNewMicroGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
+  BlitBitmap(src_bitmap, drawto, src_x, src_y, MICRO_TILEX, MICRO_TILEY,
+            xpos, ypos);
+}
+
 void DrawLevel()
 {
   int x,y;
@@ -2168,7 +2233,7 @@ void DrawLevel()
 
   for(x=BX1; x<=BX2; x++)
     for(y=BY1; y<=BY2; y++)
-      DrawScreenField(x, y);
+      DrawNewScreenField(x, y);
 
   redraw_mask |= REDRAW_FIELD;
 }
@@ -2184,6 +2249,17 @@ void DrawMiniLevel(int size_x, int size_y, int scroll_x, int scroll_y)
   redraw_mask |= REDRAW_FIELD;
 }
 
+void DrawNewMiniLevel(int size_x, int size_y, int scroll_x, int scroll_y)
+{
+  int x,y;
+
+  for(x=0; x<size_x; x++)
+    for(y=0; y<size_y; y++)
+      DrawNewMiniElementOrWall(x, y, scroll_x, scroll_y);
+
+  redraw_mask |= REDRAW_FIELD;
+}
+
 static void DrawMicroLevelExt(int xpos, int ypos, int from_x, int from_y)
 {
   int x, y;
@@ -2216,6 +2292,38 @@ static void DrawMicroLevelExt(int xpos, int ypos, int from_x, int from_y)
   redraw_mask |= REDRAW_MICROLEVEL;
 }
 
+static void DrawNewMicroLevelExt(int xpos, int ypos, int from_x, int from_y)
+{
+  int x, y;
+
+  ClearRectangle(drawto, xpos, ypos, MICROLEV_XSIZE, MICROLEV_YSIZE);
+
+  if (lev_fieldx < STD_LEV_FIELDX)
+    xpos += (STD_LEV_FIELDX - lev_fieldx) / 2 * MICRO_TILEX;
+  if (lev_fieldy < STD_LEV_FIELDY)
+    ypos += (STD_LEV_FIELDY - lev_fieldy) / 2 * MICRO_TILEY;
+
+  xpos += MICRO_TILEX;
+  ypos += MICRO_TILEY;
+
+  for(x=-1; x<=STD_LEV_FIELDX; x++)
+  {
+    for(y=-1; y<=STD_LEV_FIELDY; y++)
+    {
+      int lx = from_x + x, ly = from_y + y;
+
+      if (lx >= 0 && lx < lev_fieldx && ly >= 0 && ly < lev_fieldy)
+       DrawNewMicroElement(xpos + x * MICRO_TILEX, ypos + y * MICRO_TILEY,
+                           Ur[lx][ly]);
+      else if (lx >= -1 && lx < lev_fieldx+1 && ly >= -1 && ly < lev_fieldy+1)
+       DrawNewMicroElement(xpos + x * MICRO_TILEX, ypos + y * MICRO_TILEY,
+                           BorderElement);
+    }
+  }
+
+  redraw_mask |= REDRAW_MICROLEVEL;
+}
+
 #define MICROLABEL_EMPTY               0
 #define MICROLABEL_LEVEL_NAME          1
 #define MICROLABEL_CREATED_BY          2
@@ -2265,7 +2373,7 @@ void DrawMicroLevel(int xpos, int ypos, boolean restart)
     label_state = 1;
     label_counter = 0;
 
-    DrawMicroLevelExt(xpos, ypos, from_x, from_y);
+    DrawNewMicroLevelExt(xpos, ypos, from_x, from_y);
     DrawMicroLevelLabelExt(label_state);
 
     /* initialize delay counters */
@@ -3346,6 +3454,12 @@ int el2img(int element)
 #if 1
   int graphic_NEW = element_info[element].graphic[GFX_ACTION_DEFAULT];
 
+#if DEBUG
+  if (graphic_NEW < 0)
+    Error(ERR_WARN, "element %d -> graphic %d -- probably crashing now...",
+         element, graphic_NEW);
+#endif
+
   return graphic_NEW;
 #else
 
@@ -3359,32 +3473,19 @@ int el2img(int element)
       break;
   }
 
-  return IMG_EMPTY_SPACE;
+  return IMG_EMPTY;
 #endif
 }
 
 int el_dir2img(int element, int direction)
 {
-  int action = GFX_ACTION_DEFAULT;
-
-  if (element_info[element].has_direction_graphic[action])
-  {
-    int direction = MV_DIR_BIT(direction);
-
-    return element_info[element].direction_graphic[action][direction];
-  }
-  else
-    return el2img(element);
+  return el_dir_act2img(element, direction, GFX_ACTION_DEFAULT);
 }
 
 int el_dir_act2img(int element, int direction, int action)
 {
-  if (element_info[element].has_direction_graphic[action])
-  {
-    int direction = MV_DIR_BIT(direction);
+  action = graphics_action_mapping[action];
+  direction = MV_DIR_BIT(direction);
 
-    return element_info[element].direction_graphic[action][direction];
-  }
-  else
-    return el_dir2img(element, direction);
+  return element_info[element].direction_graphic[action][direction];
 }