rnd-19981013-3
[rocksndiamonds.git] / src / game.c
index a261b15f428dd2c7ee665fbbdbaf5ff3fd842104..9c152d05f7e91c9d9a370ebcf46bdbc769537397 100644 (file)
@@ -1,13 +1,12 @@
 /***********************************************************
 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
 *----------------------------------------------------------*
-*  ©1995 Artsoft Development                               *
-*        Holger Schemel                                    *
-*        33659 Bielefeld-Senne                             *
-*        Telefon: (0521) 493245                            *
-*        eMail: aeglos@valinor.owl.de                      *
-*               aeglos@uni-paderborn.de                    *
-*               q99492@pbhrzx.uni-paderborn.de             *
+*  (c) 1995-98 Artsoft Entertainment                       *
+*              Holger Schemel                              *
+*              Oststrasse 11a                              *
+*              33604 Bielefeld                             *
+*              phone: ++49 +521 290471                     *
+*              email: aeglos@valinor.owl.de                *
 *----------------------------------------------------------*
 *  game.c                                                  *
 ***********************************************************/
@@ -22,6 +21,7 @@
 #include "files.h"
 #include "tape.h"
 #include "joystick.h"
+#include "network.h"
 
 void GetPlayerConfig()
 {
@@ -63,11 +63,15 @@ void InitGame()
   BOOL emulate_bd = TRUE;      /* unless non-BOULDERDASH elements found */
   BOOL emulate_sb = TRUE;      /* unless non-SOKOBAN     elements found */
 
+  /* don't play tapes over network */
+  network_playing = (network && !tape.playing);
+
   for(i=0; i<MAX_PLAYERS; i++)
   {
     struct PlayerInfo *player = &stored_player[i];
 
-    player->nr = i;
+    player->index_nr = i;
+    player->element_nr = EL_SPIELER1 + i;
     player->active = FALSE;
     player->local = FALSE;
 
@@ -114,7 +118,11 @@ void InitGame()
 
 
     /* TEST TEST TEST */
+
+    /*
     stored_player[i].active = TRUE;
+    */
+
     /* TEST TEST TEST */
 
     player->LevelSolved = FALSE;
@@ -124,13 +132,32 @@ void InitGame()
   local_player->active = TRUE;
   local_player->local = TRUE;
 
+  network_player_action_received = FALSE;
+
+
+
+  /* initial null action */
+  if (network_playing)
+    SendToServer_MovePlayer(MV_NO_MOVING);
+
+
+
+  /*
+  printf("BLURB\n");
+  */
+
+
+
   ZX = ZY = -1;
 
   MampferNr = 0;
   FrameCounter = 0;
   TimeFrames = 0;
   TimeLeft = level.time;
+
+  ScreenMovDir = MV_NO_MOVING;
   ScreenMovPos = 0;
+  ScreenGfxPos = 0;
 
   AllPlayersGone = SiebAktiv = FALSE;
 
@@ -168,6 +195,8 @@ void InitGame()
        if (StorePlayer[jx][jy] == Feld[x][y])
          StorePlayer[jx][jy] = 0;
 
+       player->active = TRUE;
+
        StorePlayer[x][y] = Feld[x][y];
        Feld[x][y] = EL_LEERRAUM;
        player->jx = player->last_jx = x;
@@ -981,6 +1010,9 @@ void Impact(int x, int y)
   /* Element darunter berührt? */
   if (!lastline)
   {
+    if (Feld[x][y+1] == EL_PLAYER_IS_LEAVING)
+      return;
+
     object_hit = (!IS_FREE(x,y+1) && (!IS_MOVING(x,y+1) ||
                                      MovDir[x][y+1]!=MV_DOWN ||
                                      MovPos[x][y+1]<=TILEY/2));
@@ -2581,23 +2613,37 @@ void MauerWaechst(int x, int y)
     phase = 2-MovDelay[x][y]/delay;
     if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
       DrawGraphic(SCREENX(x),SCREENY(y),
-                 (Store[x][y]==MV_LEFT ? GFX_MAUER_L1 : GFX_MAUER_R1)+phase);
+                 (MovDir[x][y] == MV_LEFT  ? GFX_MAUER_LEFT  :
+                  MovDir[x][y] == MV_RIGHT ? GFX_MAUER_RIGHT :
+                  MovDir[x][y] == MV_UP    ? GFX_MAUER_UP    :
+                                             GFX_MAUER_DOWN  ) + phase);
 
     if (!MovDelay[x][y])
     {
-      if (Store[x][y]==MV_LEFT)
+      if (MovDir[x][y] == MV_LEFT)
       {
        if (IN_LEV_FIELD(x-1,y) && IS_MAUER(Feld[x-1][y]))
          DrawLevelField(x-1,y);
       }
-      else
+      else if (MovDir[x][y] == MV_RIGHT)
       {
        if (IN_LEV_FIELD(x+1,y) && IS_MAUER(Feld[x+1][y]))
          DrawLevelField(x+1,y);
       }
+      else if (MovDir[x][y] == MV_UP)
+      {
+       if (IN_LEV_FIELD(x,y-1) && IS_MAUER(Feld[x][y-1]))
+         DrawLevelField(x,y-1);
+      }
+      else
+      {
+       if (IN_LEV_FIELD(x,y+1) && IS_MAUER(Feld[x][y+1]))
+         DrawLevelField(x,y+1);
+      }
 
-      Feld[x][y] = EL_MAUER_LEBT;
+      Feld[x][y] = Store[x][y];
       Store[x][y] = 0;
+      MovDir[x][y] = MV_NO_MOVING;
       DrawLevelField(x,y);
     }
   }
@@ -2605,7 +2651,10 @@ void MauerWaechst(int x, int y)
 
 void MauerAbleger(int ax, int ay)
 {
+  int element = Feld[ax][ay];
+  BOOL oben_frei = FALSE, unten_frei = FALSE;
   BOOL links_frei = FALSE, rechts_frei = FALSE;
+  BOOL oben_massiv = FALSE, unten_massiv = FALSE;
   BOOL links_massiv = FALSE, rechts_massiv = FALSE;
 
   if (!MovDelay[ax][ay])       /* neue Mauer / noch nicht gewartet */
@@ -2618,35 +2667,72 @@ void MauerAbleger(int ax, int ay)
       return;
   }
 
+  if (IN_LEV_FIELD(ax,ay-1) && IS_FREE(ax,ay-1))
+    oben_frei = TRUE;
+  if (IN_LEV_FIELD(ax,ay+1) && IS_FREE(ax,ay+1))
+    unten_frei = TRUE;
   if (IN_LEV_FIELD(ax-1,ay) && IS_FREE(ax-1,ay))
     links_frei = TRUE;
   if (IN_LEV_FIELD(ax+1,ay) && IS_FREE(ax+1,ay))
     rechts_frei = TRUE;
 
-  if (links_frei)
+  if (element == EL_MAUER_Y || element == EL_MAUER_XY)
   {
-    Feld[ax-1][ay] = EL_MAUERND;
-    Store[ax-1][ay] = MV_LEFT;
-    if (IN_SCR_FIELD(SCREENX(ax-1),SCREENY(ay)))
-      DrawGraphic(SCREENX(ax-1),SCREENY(ay),GFX_MAUER_L1);
+    if (oben_frei)
+    {
+      Feld[ax][ay-1] = EL_MAUERND;
+      Store[ax][ay-1] = element;
+      MovDir[ax][ay-1] = MV_UP;
+      if (IN_SCR_FIELD(SCREENX(ax),SCREENY(ay-1)))
+       DrawGraphic(SCREENX(ax),SCREENY(ay-1),GFX_MAUER_UP);
+    }
+    if (unten_frei)
+    {
+      Feld[ax][ay+1] = EL_MAUERND;
+      Store[ax][ay+1] = element;
+      MovDir[ax][ay+1] = MV_DOWN;
+      if (IN_SCR_FIELD(SCREENX(ax),SCREENY(ay+1)))
+       DrawGraphic(SCREENX(ax),SCREENY(ay+1),GFX_MAUER_DOWN);
+    }
   }
-  if (rechts_frei)
+
+  if (element == EL_MAUER_X || element == EL_MAUER_XY ||
+      element == EL_MAUER_LEBT)
   {
-    Feld[ax+1][ay] = EL_MAUERND;
-    Store[ax+1][ay] = MV_RIGHT;
-    if (IN_SCR_FIELD(SCREENX(ax+1),SCREENY(ay)))
-      DrawGraphic(SCREENX(ax+1),SCREENY(ay),GFX_MAUER_R1);
+    if (links_frei)
+    {
+      Feld[ax-1][ay] = EL_MAUERND;
+      Store[ax-1][ay] = element;
+      MovDir[ax-1][ay] = MV_LEFT;
+      if (IN_SCR_FIELD(SCREENX(ax-1),SCREENY(ay)))
+       DrawGraphic(SCREENX(ax-1),SCREENY(ay),GFX_MAUER_LEFT);
+    }
+    if (rechts_frei)
+    {
+      Feld[ax+1][ay] = EL_MAUERND;
+      Store[ax+1][ay] = element;
+      MovDir[ax+1][ay] = MV_RIGHT;
+      if (IN_SCR_FIELD(SCREENX(ax+1),SCREENY(ay)))
+       DrawGraphic(SCREENX(ax+1),SCREENY(ay),GFX_MAUER_RIGHT);
+    }
   }
 
-  if (links_frei || rechts_frei)
+  if (element == EL_MAUER_LEBT && (links_frei || rechts_frei))
     DrawLevelField(ax,ay);
 
+  if (!IN_LEV_FIELD(ax,ay-1) || IS_MAUER(Feld[ax][ay-1]))
+    oben_massiv = TRUE;
+  if (!IN_LEV_FIELD(ax,ay+1) || IS_MAUER(Feld[ax][ay+1]))
+    unten_massiv = TRUE;
   if (!IN_LEV_FIELD(ax-1,ay) || IS_MAUER(Feld[ax-1][ay]))
     links_massiv = TRUE;
   if (!IN_LEV_FIELD(ax+1,ay) || IS_MAUER(Feld[ax+1][ay]))
     rechts_massiv = TRUE;
 
-  if (links_massiv && rechts_massiv)
+  if (((oben_massiv && unten_massiv) ||
+       element == EL_MAUER_X || element == EL_MAUER_LEBT) &&
+      ((links_massiv && rechts_massiv) ||
+       element == EL_MAUER_Y))
     Feld[ax][ay] = EL_MAUERWERK;
 }
 
@@ -2699,8 +2785,10 @@ void CheckForDragon(int x, int y)
   }
 }
 
-void PlayerActions(struct PlayerInfo *player, int player_action)
+void PlayerActions(struct PlayerInfo *player, byte player_action)
 {
+  static byte stored_player_action[MAX_PLAYERS];
+  static int num_stored_actions = 0;
   BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
   int jx = player->jx, jy = player->jy;
   int left     = player_action & JOY_LEFT;
@@ -2712,6 +2800,9 @@ void PlayerActions(struct PlayerInfo *player, int player_action)
   int dx       = (left ? -1    : right ? 1     : 0);
   int dy       = (up   ? -1    : down  ? 1     : 0);
 
+  stored_player_action[player->index_nr] = 0;
+  num_stored_actions++;
+
   if (!player->active || player->gone)
     return;
 
@@ -2732,7 +2823,15 @@ void PlayerActions(struct PlayerInfo *player, int player_action)
     {
       if (bombed && !moved)
        player_action &= JOY_BUTTON;
-      TapeRecordAction(player_action);
+
+      stored_player_action[player->index_nr] = player_action;
+
+      /* this allows cycled sequences of PlayerActions() */
+      if (num_stored_actions >= MAX_PLAYERS)
+      {
+       TapeRecordAction(stored_player_action);
+       num_stored_actions = 0;
+      }
     }
     else if (tape.playing && snapped)
       SnapField(player, 0,0);                  /* stop snapping */
@@ -2748,7 +2847,8 @@ void PlayerActions(struct PlayerInfo *player, int player_action)
   if (tape.playing && !tape.pausing && !player_action &&
       tape.counter < tape.length)
   {
-    int next_joy = tape.pos[tape.counter].joystickdata & (JOY_LEFT|JOY_RIGHT);
+    int next_joy =
+      tape.pos[tape.counter].action[player->index_nr] & (JOY_LEFT|JOY_RIGHT);
 
     if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT)
     {
@@ -2770,12 +2870,13 @@ void PlayerActions(struct PlayerInfo *player, int player_action)
   }
 }
 
-void GameActions(int player_action)
+void GameActions(byte player_action)
 {
   static long action_delay = 0;
   long action_delay_value;
   int sieb_x = 0, sieb_y = 0;
   int i, x,y, element;
+  int *recorded_player_action;
 
   if (game_status != PLAYING)
     return;
@@ -2791,20 +2892,105 @@ void GameActions(int player_action)
   /* main game synchronization point */
   WaitUntilDelayReached(&action_delay, action_delay_value);
 
+  if (network_playing && !network_player_action_received)
+  {
+    /*
+#ifdef DEBUG
+    printf("DEBUG: try to get network player actions in time\n");
+#endif
+    */
+
+    /* last chance to get network player actions without main loop delay */
+    HandleNetworking();
+
+    if (game_status != PLAYING)
+      return;
+
+    if (!network_player_action_received)
+    {
+      /*
+#ifdef DEBUG
+      printf("DEBUG: failed to get network player actions in time\n");
+#endif
+      */
+      return;
+    }
+  }
+
+
+  if (tape.pausing || (tape.playing && !TapePlayDelay()))
+    return;
+  else if (tape.recording)
+    TapeRecordDelay();
+
+
+  if (tape.playing)
+    recorded_player_action = TapePlayAction();
+  else
+    recorded_player_action = NULL;
+
+  if (network_playing)
+    SendToServer_MovePlayer(player_action);
+
   for(i=0; i<MAX_PLAYERS; i++)
   {
-    PlayerActions(&stored_player[i], player_action);
-    ScrollFigure(&stored_player[i], SCROLL_FIGURE_GO_ON);
+    /*
+    int actual_player_action =
+      (network ? network_player_action[i] : player_action);
+      */
+
+    int actual_player_action =
+      (network_playing ? network_player_action[i] : player_action);
+
+    /*
+    int actual_player_action = network_player_action[i];
+    */
+
+    /*
+    int actual_player_action = player_action;
+    */
+
+    /* TEST TEST TEST */
+
+    /*
+    if (i != TestPlayer && !stored_player[i].MovPos)
+      actual_player_action = 0;
+    */
+
+    if (!network && i != TestPlayer)
+      actual_player_action = 0;
+
+    /* TEST TEST TEST */
+
+    if (recorded_player_action)
+      actual_player_action = recorded_player_action[i];
+
+    PlayerActions(&stored_player[i], actual_player_action);
+    ScrollFigure(&stored_player[i], SCROLL_GO_ON);
+
+    network_player_action[i] = 0;
   }
 
+  network_player_action_received = FALSE;
+
+  ScrollScreen(NULL, SCROLL_GO_ON);
+
+  /*
   if (tape.pausing || (tape.playing && !TapePlayDelay()))
     return;
   else if (tape.recording)
     TapeRecordDelay();
+  */
 
   FrameCounter++;
   TimeFrames++;
 
+
+  /*
+  printf("FrameCounter == %d, RND(100) == %d\n", FrameCounter, RND(100));
+  */
+
+
   for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
   {
     Stop[x][y] = FALSE;
@@ -2870,7 +3056,10 @@ void GameActions(int player_action)
       AusgangstuerBlinken(x,y);
     else if (element==EL_MAUERND)
       MauerWaechst(x,y);
-    else if (element==EL_MAUER_LEBT)
+    else if (element==EL_MAUER_LEBT ||
+            element==EL_MAUER_X ||
+            element==EL_MAUER_Y ||
+            element==EL_MAUER_XY)
       MauerAbleger(x,y);
     else if (element==EL_BURNING)
       CheckForDragon(x,y);
@@ -2947,12 +3136,54 @@ void GameActions(int player_action)
   DrawAllPlayers();
 }
 
+static BOOL AllPlayersInSight(struct PlayerInfo *player, int x, int y)
+{
+  int min_x = x, min_y = y, max_x = x, max_y = y;
+  int i;
+
+  for(i=0; i<MAX_PLAYERS; i++)
+  {
+    int jx = stored_player[i].jx, jy = stored_player[i].jy;
+
+    if (!stored_player[i].active || stored_player[i].gone ||
+       &stored_player[i] == player)
+      continue;
+
+    min_x = MIN(min_x, jx);
+    min_y = MIN(min_y, jy);
+    max_x = MAX(max_x, jx);
+    max_y = MAX(max_y, jy);
+  }
+
+  return(max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
+}
+
+static BOOL AllPlayersInVisibleScreen()
+{
+  int i;
+
+  for(i=0; i<MAX_PLAYERS; i++)
+  {
+    int jx = stored_player[i].jx, jy = stored_player[i].jy;
+
+    if (!stored_player[i].active || stored_player[i].gone)
+      continue;
+
+    if (!IN_VIS_FIELD(SCREENX(jx), SCREENY(jy)))
+      return(FALSE);
+  }
+
+  return(TRUE);
+}
+
 void ScrollLevel(int dx, int dy)
 {
   int softscroll_offset = (soft_scrolling_on ? TILEX : 0);
   int x,y;
 
-  ScreenMovPos = local_player->GfxPos;
+  /*
+  ScreenGfxPos = local_player->GfxPos;
+  */
 
   XCopyArea(display,drawto_field,drawto_field,gc,
            FX + TILEX*(dx==-1) - softscroll_offset,
@@ -2997,6 +3228,9 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player,
   if (!IN_LEV_FIELD(new_jx,new_jy))
     return(MF_NO_ACTION);
 
+  if (!network && !AllPlayersInSight(player, new_jx,new_jy))
+    return(MF_NO_ACTION);
+
   element = MovingOrBlocked2Element(new_jx,new_jy);
 
   if (DONT_GO_TO(element))
@@ -3025,11 +3259,11 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player,
   player->last_jy = jy;
   jx = player->jx = new_jx;
   jy = player->jy = new_jy;
-  StorePlayer[jx][jy] = EL_SPIELER1 + player->nr;
+  StorePlayer[jx][jy] = player->element_nr;
 
   player->MovPos = (dx > 0 || dy > 0 ? -1 : 1) * 7*TILEX/8;
 
-  ScrollFigure(player, SCROLL_FIGURE_INIT);
+  ScrollFigure(player, SCROLL_INIT);
 
   return(MF_MOVING);
 }
@@ -3060,20 +3294,94 @@ BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy)
   jx = player->jx;
   jy = player->jy;
 
+
+
+  /*
   if (moved & MF_MOVING && player == local_player)
+  */
+
+  if (moved & MF_MOVING && !ScreenMovPos &&
+      (player == local_player || !network))
   {
     int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
     int offset = (scroll_delay_on ? 3 : 0);
 
-    if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) &&
-       jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset))
-      scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset);
-    if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) &&
-       jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset))
-      scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset);
+    /*
+    if (player == local_player)
+    {
+      printf("MOVING LOCAL PLAYER && SCROLLING\n");
+    }
+    */
+
+    if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy)))
+    {
+      /* actual player has left the screen -- scroll in that direction */
+      if (jx != old_jx)                /* player has moved horizontally */
+       scroll_x += (jx - old_jx);
+      else                     /* player has moved vertically */
+       scroll_y += (jy - old_jy);
+    }
+    else
+    {
+      if (jx != old_jx)                /* player has moved horizontally */
+      {
+       if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) &&
+           jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset))
+         scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset);
+
+       /* don't scroll more than one field at a time */
+       scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
+
+       /* don't scroll against the player's moving direction */
+       if ((player->MovDir == MV_LEFT && scroll_x > old_scroll_x) ||
+           (player->MovDir == MV_RIGHT && scroll_x < old_scroll_x))
+         scroll_x = old_scroll_x;
+      }
+      else                     /* player has moved vertically */
+      {
+       if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) &&
+           jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset))
+         scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset);
+
+       /* don't scroll more than one field at a time */
+       scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
+
+       /* don't scroll against the player's moving direction */
+       if ((player->MovDir == MV_UP && scroll_y > old_scroll_y) ||
+           (player->MovDir == MV_DOWN && scroll_y < old_scroll_y))
+         scroll_y = old_scroll_y;
+      }
+    }
+
+#if 0
+    if (player == local_player)
+    {
+      if ((scroll_x < jx-MIDPOSX-offset || scroll_x > jx-MIDPOSX+offset) &&
+         jx >= MIDPOSX-1-offset && jx <= lev_fieldx-(MIDPOSX-offset))
+       scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : offset);
+      if ((scroll_y < jy-MIDPOSY-offset || scroll_y > jy-MIDPOSY+offset) &&
+         jy >= MIDPOSY-1-offset && jy <= lev_fieldy-(MIDPOSY-offset))
+       scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : offset);
+
+      /* don't scroll more than one field at a time */
+      scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
+      scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
+    }
+#endif
 
     if (scroll_x != old_scroll_x || scroll_y != old_scroll_y)
-      ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
+    {
+      if (!network && !AllPlayersInVisibleScreen())
+      {
+       scroll_x = old_scroll_x;
+       scroll_y = old_scroll_y;
+      }
+      else
+      {
+       ScrollScreen(player, SCROLL_INIT);
+       ScrollLevel(old_scroll_x - scroll_x, old_scroll_y - scroll_y);
+      }
+    }
   }
 
   if (!(moved & MF_MOVING) && !player->Pushing)
@@ -3111,7 +3419,7 @@ void ScrollFigure(struct PlayerInfo *player, int mode)
   if (!player->active || player->gone || !player->MovPos)
     return;
 
-  if (mode == SCROLL_FIGURE_INIT)
+  if (mode == SCROLL_INIT)
   {
     player->actual_frame_counter = FrameCounter;
     player->GfxPos = ScrollStepSize * (player->MovPos / ScrollStepSize);
@@ -3128,12 +3436,6 @@ void ScrollFigure(struct PlayerInfo *player, int mode)
   player->MovPos += (player->MovPos > 0 ? -1 : 1) * TILEX/8;
   player->GfxPos = ScrollStepSize * (player->MovPos / ScrollStepSize);
 
-  if (ScreenMovPos && ScreenMovPos != local_player->GfxPos)
-  {
-    ScreenMovPos = local_player->GfxPos;
-    redraw_mask |= REDRAW_FIELD;
-  }
-
   if (Feld[last_jx][last_jy] == EL_PLAYER_IS_LEAVING)
     Feld[last_jx][last_jy] = EL_LEERRAUM;
 
@@ -3154,6 +3456,31 @@ void ScrollFigure(struct PlayerInfo *player, int mode)
   }
 }
 
+void ScrollScreen(struct PlayerInfo *player, int mode)
+{
+  static long screen_frame_counter = 0;
+
+  if (mode == SCROLL_INIT)
+  {
+    screen_frame_counter = FrameCounter;
+    ScreenMovDir = player->MovDir;
+    ScreenMovPos = player->MovPos;
+    ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
+    return;
+  }
+  else if (!FrameReached(&screen_frame_counter,1))
+    return;
+
+  if (ScreenMovPos)
+  {
+    ScreenMovPos += (ScreenMovPos > 0 ? -1 : 1) * TILEX/8;
+    ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
+    redraw_mask |= REDRAW_FIELD;
+  }
+  else
+    ScreenMovDir = MV_NO_MOVING;
+}
+
 void TestIfGoodThingHitsBadThing(int goodx, int goody)
 {
   int i, killx = goodx, killy = goody;
@@ -3714,15 +4041,17 @@ BOOL PlaceBomb(struct PlayerInfo *player)
     player->dynamite--;
     DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(local_player->dynamite, 3),
             FS_SMALL, FC_YELLOW);
-    DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNAMIT);
+    if (IN_SCR_FIELD(SCREENX(jx),SCREENY(jy)))
+      DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNAMIT);
   }
   else
   {
     Feld[jx][jy] = EL_DYNABOMB;
-    Store2[jx][jy] = EL_SPIELER1 + player->nr; /* for DynaExplode() */
+    Store2[jx][jy] = player->element_nr;       /* for DynaExplode() */
     MovDelay[jx][jy] = 96;
     player->dynabombs_left--;
-    DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNABOMB);
+    if (IN_SCR_FIELD(SCREENX(jx),SCREENY(jy)))
+      DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNABOMB);
   }
 
   return(TRUE);