rnd-19981017-1
[rocksndiamonds.git] / src / game.c
index 05af36f92b6a846193002ae345d09d1120cd68ff..4851f4aa7745267c5226d1012c325fba70dcac4f 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                                                  *
 ***********************************************************/
 #include "files.h"
 #include "tape.h"
 #include "joystick.h"
+#include "network.h"
 
 void GetPlayerConfig()
 {
-  int old_joystick_nr = joystick_nr;
+  int old_joystick_nr = setup.joystick_nr;
 
   if (sound_status==SOUND_OFF)
     local_player->setup &= ~SETUP_SOUND;
@@ -35,20 +35,20 @@ void GetPlayerConfig()
     local_player->setup &= ~SETUP_SOUND_MUSIC;
   }
 
-  sound_on = sound_simple_on = SETUP_SOUND_ON(local_player->setup);
-  sound_loops_on = SETUP_SOUND_LOOPS_ON(local_player->setup);
-  sound_music_on = SETUP_SOUND_MUSIC_ON(local_player->setup);
-  toons_on = SETUP_TOONS_ON(local_player->setup);
-  direct_draw_on = SETUP_DIRECT_DRAW_ON(local_player->setup);
-  fading_on = SETUP_FADING_ON(local_player->setup);
-  autorecord_on = SETUP_AUTO_RECORD_ON(local_player->setup);
-  joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
-  quick_doors = SETUP_QUICK_DOORS_ON(local_player->setup);
-  scroll_delay_on = SETUP_SCROLL_DELAY_ON(local_player->setup);
-  soft_scrolling_on = SETUP_SOFT_SCROLL_ON(local_player->setup);
+  setup.sound_on = setup.sound_simple_on = SETUP_SOUND_ON(local_player->setup);
+  setup.sound_loops_on = SETUP_SOUND_LOOPS_ON(local_player->setup);
+  setup.sound_music_on = SETUP_SOUND_MUSIC_ON(local_player->setup);
+  setup.toons_on = SETUP_TOONS_ON(local_player->setup);
+  setup.direct_draw_on = SETUP_DIRECT_DRAW_ON(local_player->setup);
+  setup.fading_on = SETUP_FADING_ON(local_player->setup);
+  setup.autorecord_on = SETUP_AUTO_RECORD_ON(local_player->setup);
+  setup.joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
+  setup.quick_doors = SETUP_QUICK_DOORS_ON(local_player->setup);
+  setup.scroll_delay_on = SETUP_SCROLL_DELAY_ON(local_player->setup);
+  setup.soft_scrolling_on = SETUP_SOFT_SCROLL_ON(local_player->setup);
 
 #ifndef MSDOS
-  if (joystick_nr != old_joystick_nr)
+  if (setup.joystick_nr != old_joystick_nr)
   {
     if (joystick_device)
       close(joystick_device);
@@ -60,16 +60,25 @@ void GetPlayerConfig()
 void InitGame()
 {
   int i,j, x,y;
-  BOOL emulate_bd = TRUE;      /* unless non-BOULDERDASH elements found */
-  BOOL emulate_sb = TRUE;      /* unless non-SOKOBAN     elements found */
+  boolean emulate_bd = TRUE;   /* unless non-BOULDERDASH elements found */
+  boolean emulate_sb = TRUE;   /* unless non-SOKOBAN     elements found */
+
+  /* don't play tapes over network */
+  network_playing = (options.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->present = FALSE;
     player->active = FALSE;
+
+    /*
     player->local = FALSE;
+    */
 
     player->score = 0;
     player->gems_still_needed = level.edelsteine;
@@ -114,15 +123,27 @@ void InitGame()
 
 
     /* TEST TEST TEST */
+
+    /*
     stored_player[i].active = TRUE;
+    */
+
     /* TEST TEST TEST */
 
     player->LevelSolved = FALSE;
     player->GameOver = FALSE;
   }
 
+  /*
   local_player->active = TRUE;
   local_player->local = TRUE;
+  */
+
+  network_player_action_received = FALSE;
+
+  /* initial null action */
+  if (network_playing)
+    SendToServer_MovePlayer(MV_NO_MOVING);
 
   ZX = ZY = -1;
 
@@ -130,7 +151,10 @@ void InitGame()
   FrameCounter = 0;
   TimeFrames = 0;
   TimeLeft = level.time;
+
+  ScreenMovDir = MV_NO_MOVING;
   ScreenMovPos = 0;
+  ScreenGfxPos = 0;
 
   AllPlayersGone = SiebAktiv = FALSE;
 
@@ -164,7 +188,22 @@ void InitGame()
        struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_SPIELER1];
        int jx = player->jx, jy = player->jy;
 
-       /* remove duplicate players */
+       /*
+       player->active = TRUE;
+       */
+
+       player->present = TRUE;
+       if (player->connected)
+       {
+         player->active = TRUE;
+
+         printf("Player %d activated.\n", player->element_nr);
+         printf("[Local player is %d and currently %s.]\n",
+                local_player->element_nr,
+                local_player->active ? "active" : "not active");
+       }
+
+       /* remove potentially duplicate players */
        if (StorePlayer[jx][jy] == Feld[x][y])
          StorePlayer[jx][jy] = 0;
 
@@ -172,6 +211,7 @@ void InitGame()
        Feld[x][y] = EL_LEERRAUM;
        player->jx = player->last_jx = x;
        player->jy = player->last_jy = y;
+
        break;
       }
       case EL_BADEWANNE:
@@ -249,6 +289,52 @@ void InitGame()
     }
   }
 
+  /* check if any connected player was not found in playfield */
+  for(i=0; i<MAX_PLAYERS; i++)
+  {
+    struct PlayerInfo *player = &stored_player[i];
+
+    if (player->connected && !player->present)
+    {
+      printf("Oops!\n");
+
+
+      for(j=0; j<MAX_PLAYERS; j++)
+      {
+       struct PlayerInfo *some_player = &stored_player[j];
+       int jx = some_player->jx, jy = some_player->jy;
+
+       /* assign first free player found that is present in the playfield */
+       if (some_player->present && !some_player->connected)
+       {
+         player->present = TRUE;
+         player->active = TRUE;
+         some_player->present = FALSE;
+
+         StorePlayer[jx][jy] = player->element_nr;
+         player->jx = player->last_jx = jx;
+         player->jy = player->last_jy = jy;
+
+         break;
+       }
+      }
+    }
+  }
+
+  for(i=0; i<MAX_PLAYERS; i++)
+  {
+    struct PlayerInfo *player = &stored_player[i];
+
+    printf("Player %d: present == %d, connected == %d, active == %d.\n",
+          i+1,
+          player->present,
+          player->connected,
+          player->active);
+    if (local_player == player)
+      printf("Player %d is local player.\n", i+1);
+  }
+
+
   game_emulation = (emulate_bd ? EMU_BOULDERDASH :
                    emulate_sb ? EMU_SOKOBAN : EMU_NONE);
 
@@ -290,9 +376,9 @@ void InitGame()
   DrawGameButton(BUTTON_GAME_STOP);
   DrawGameButton(BUTTON_GAME_PAUSE);
   DrawGameButton(BUTTON_GAME_PLAY);
-  DrawSoundDisplay(BUTTON_SOUND_MUSIC  | (BUTTON_ON * sound_music_on));
-  DrawSoundDisplay(BUTTON_SOUND_LOOPS  | (BUTTON_ON * sound_loops_on));
-  DrawSoundDisplay(BUTTON_SOUND_SIMPLE | (BUTTON_ON * sound_simple_on));
+  DrawSoundDisplay(BUTTON_SOUND_MUSIC  | (BUTTON_ON * setup.sound_music_on));
+  DrawSoundDisplay(BUTTON_SOUND_LOOPS  | (BUTTON_ON * setup.sound_loops_on));
+  DrawSoundDisplay(BUTTON_SOUND_SIMPLE | (BUTTON_ON * setup.sound_simple_on));
   XCopyArea(display,drawto,pix[PIX_DB_DOOR],gc,
            DX+GAME_CONTROL_XPOS,DY+GAME_CONTROL_YPOS,
            GAME_CONTROL_XSIZE,2*GAME_CONTROL_YSIZE,
@@ -301,10 +387,16 @@ void InitGame()
 
   OpenDoor(DOOR_OPEN_1);
 
-  if (sound_music_on)
+  if (setup.sound_music_on)
     PlaySoundLoop(background_loop[level_nr % num_bg_loops]);
 
   XAutoRepeatOff(display);
+
+
+  for (i=0;i<4;i++)
+    printf("Spieler %d %saktiv.\n",
+          i+1, (stored_player[i].active ? "" : "nicht "));
+
 }
 
 void InitMovDir(int x, int y)
@@ -424,12 +516,12 @@ void GameWon()
 
   if (TimeLeft)
   {
-    if (sound_loops_on)
+    if (setup.sound_loops_on)
       PlaySoundExt(SND_SIRR, PSND_MAX_VOLUME, PSND_MAX_RIGHT, PSND_LOOP);
 
     while(TimeLeft > 0)
     {
-      if (!sound_loops_on)
+      if (!setup.sound_loops_on)
        PlaySoundStereo(SND_SIRR, PSND_MAX_RIGHT);
       if (TimeLeft && !(TimeLeft % 10))
        RaiseScore(level.score[SC_ZEITBONUS]);
@@ -442,7 +534,7 @@ void GameWon()
       Delay(10);
     }
 
-    if (sound_loops_on)
+    if (setup.sound_loops_on)
       StopSound(SND_SIRR);
   }
 
@@ -489,7 +581,7 @@ void GameWon()
   BackToFront();
 }
 
-BOOL NewHiScore()
+boolean NewHiScore()
 {
   int k,l;
   int position = -1;
@@ -601,6 +693,14 @@ int MovingOrBlocked2Element(int x, int y)
     return(element);
 }
 
+static void RemoveField(int x, int y)
+{
+  Feld[x][y] = EL_LEERRAUM;
+  MovPos[x][y] = 0;
+  MovDir[x][y] = 0;
+  MovDelay[x][y] = 0;
+}
+
 void RemoveMovingField(int x, int y)
 {
   int oldx = x,oldy = y, newx = x,newy = y;
@@ -643,7 +743,7 @@ void RemoveMovingField(int x, int y)
 
 void DrawDynamite(int x, int y)
 {
-  int sx = SCROLLX(x), sy = SCROLLY(y);
+  int sx = SCREENX(x), sy = SCREENY(y);
   int graphic = el2gfx(Feld[x][y]);
   int phase;
 
@@ -836,12 +936,12 @@ void Explode(int ex, int ey, int phase, int mode)
       InitMovDir(x,y);
     DrawLevelField(x,y);
   }
-  else if (!(phase%delay) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
+  else if (!(phase%delay) && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
   {
     if (phase==delay)
-      ErdreichAnbroeckeln(SCROLLX(x),SCROLLY(y));
+      ErdreichAnbroeckeln(SCREENX(x),SCREENY(y));
 
-    DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_EXPLOSION+(phase/delay-1));
+    DrawGraphic(SCREENX(x),SCREENY(y),GFX_EXPLOSION+(phase/delay-1));
   }
 }
 
@@ -951,8 +1051,8 @@ void Blurb(int x, int y)
     if (MovDelay[x][y])                /* neue Phase / in Wartezustand */
     {
       MovDelay[x][y]--;
-      if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
-       DrawGraphic(SCROLLX(x),SCROLLY(y),graphic+4-MovDelay[x][y]/2);
+      if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
+       DrawGraphic(SCREENX(x),SCREENY(y),graphic+4-MovDelay[x][y]/2);
 
       if (!MovDelay[x][y])
       {
@@ -965,14 +1065,17 @@ void Blurb(int x, int y)
 
 void Impact(int x, int y)
 {
-  BOOL lastline = (y==lev_fieldy-1);
-  BOOL object_hit = FALSE;
+  boolean lastline = (y==lev_fieldy-1);
+  boolean object_hit = FALSE;
   int element = Feld[x][y];
   int smashed = 0;
 
   /* 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));
@@ -1193,7 +1296,7 @@ void TurnRound(int x, int y)
   }
   else if (element==EL_MAMPFER)
   {
-    BOOL can_turn_left = FALSE, can_turn_right = FALSE;
+    boolean can_turn_left = FALSE, can_turn_right = FALSE;
 
     if (IN_LEV_FIELD(left_x,left_y) &&
        (IS_FREE_OR_PLAYER(left_x,left_y) ||
@@ -1217,7 +1320,7 @@ void TurnRound(int x, int y)
   }
   else if (element==EL_MAMPFER2)
   {
-    BOOL can_turn_left = FALSE, can_turn_right = FALSE;
+    boolean can_turn_left = FALSE, can_turn_right = FALSE;
 
     if (IN_LEV_FIELD(left_x,left_y) &&
        (IS_FREE_OR_PLAYER(left_x,left_y) ||
@@ -1241,7 +1344,7 @@ void TurnRound(int x, int y)
   }
   else if (element==EL_PACMAN)
   {
-    BOOL can_turn_left = FALSE, can_turn_right = FALSE;
+    boolean can_turn_left = FALSE, can_turn_right = FALSE;
 
     if (IN_LEV_FIELD(left_x,left_y) &&
        (IS_FREE_OR_PLAYER(left_x,left_y) ||
@@ -1265,9 +1368,9 @@ void TurnRound(int x, int y)
   }
   else if (element==EL_SCHWEIN)
   {
-    BOOL can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE;
-    BOOL should_turn_left = FALSE, should_turn_right = FALSE;
-    BOOL should_move_on = FALSE;
+    boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE;
+    boolean should_turn_left = FALSE, should_turn_right = FALSE;
+    boolean should_move_on = FALSE;
     int rnd_value = 24;
     int rnd = RND(rnd_value);
 
@@ -1337,7 +1440,7 @@ void TurnRound(int x, int y)
   }
   else if (element==EL_DRACHE)
   {
-    BOOL can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE;
+    boolean can_turn_left = FALSE, can_turn_right = FALSE, can_move_on = FALSE;
     int rnd_value = 24;
     int rnd = RND(rnd_value);
 
@@ -1456,7 +1559,7 @@ void TurnRound(int x, int y)
 
       if ((MovDir[x][y]&(MV_LEFT|MV_RIGHT)) && (MovDir[x][y]&(MV_UP|MV_DOWN)))
       {
-       BOOL first_horiz = RND(2);
+       boolean first_horiz = RND(2);
        int new_move_dir = MovDir[x][y];
 
        MovDir[x][y] =
@@ -1490,6 +1593,28 @@ void TurnRound(int x, int y)
   }
 }
 
+static boolean JustBeingPushed(int x, int y)
+{
+  int i;
+
+  for(i=0; i<MAX_PLAYERS; i++)
+  {
+    struct PlayerInfo *player = &stored_player[i];
+
+    if (player->active && !player->gone &&
+       player->Pushing && player->MovPos)
+    {
+      int next_jx = player->jx + (player->jx - player->last_jx);
+      int next_jy = player->jy + (player->jy - player->last_jy);
+
+      if (x == next_jx && y == next_jy)
+       return(TRUE);
+    }
+  }
+
+  return(FALSE);
+}
+
 void StartMoving(int x, int y)
 {
   int element = Feld[x][y];
@@ -1499,26 +1624,9 @@ void StartMoving(int x, int y)
 
   if (CAN_FALL(element) && y<lev_fieldy-1)
   {
-    /* check if this element is just being pushed */
     if ((x>0 && IS_PLAYER(x-1,y)) || (x<lev_fieldx-1 && IS_PLAYER(x+1,y)))
-    {
-      int i;
-
-      for(i=0; i<MAX_PLAYERS; i++)
-      {
-       struct PlayerInfo *player = &stored_player[i];
-
-       if (player->active && !player->gone &&
-           player->Pushing && player->MovPos)
-       {
-         int next_jx = player->jx + (player->jx - player->last_jx);
-         int next_jy = player->jy + (player->jy - player->last_jy);
-
-         if (x == next_jx && y == next_jy)
-           return;
-       }
-      }
-    }
+      if (JustBeingPushed(x,y))
+       return;
 
     if (element==EL_MORAST_VOLL)
     {
@@ -1630,10 +1738,10 @@ void StartMoving(int x, int y)
     }
     else if (IS_SLIPPERY(Feld[x][y+1]) && !Store[x][y+1])
     {
-      BOOL left  = (x>0 && IS_FREE(x-1,y) &&
-                   (IS_FREE(x-1,y+1) || Feld[x-1][y+1]==EL_SALZSAEURE));
-      BOOL right = (x<lev_fieldx-1 && IS_FREE(x+1,y) &&
-                   (IS_FREE(x+1,y+1) || Feld[x+1][y+1]==EL_SALZSAEURE));
+      boolean left  = (x>0 && IS_FREE(x-1,y) &&
+                      (IS_FREE(x-1,y+1) || Feld[x-1][y+1]==EL_SALZSAEURE));
+      boolean right = (x<lev_fieldx-1 && IS_FREE(x+1,y) &&
+                      (IS_FREE(x+1,y+1) || Feld[x+1][y+1]==EL_SALZSAEURE));
 
       if (left || right)
       {
@@ -1648,6 +1756,9 @@ void StartMoving(int x, int y)
   {
     int newx,newy;
 
+    if (element == EL_SONDE && JustBeingPushed(x,y))
+      return;
+
     if (!MovDelay[x][y])       /* neuer Schritt / noch nicht gewartet */
     {
       /* Alle Figuren, die nach jeden Schritt die Richtung wechseln können.
@@ -1673,8 +1784,8 @@ void StartMoving(int x, int y)
        if (phase>3)
          phase = 7-phase;
 
-       if (IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
-         DrawGraphic(SCROLLX(x),SCROLLY(y), el2gfx(element)+phase);
+       if (IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
+         DrawGraphic(SCREENX(x),SCREENY(y), el2gfx(element)+phase);
 
        if ((element==EL_MAMPFER || element==EL_MAMPFER2)
            && MovDelay[x][y]%4==3)
@@ -1695,7 +1806,7 @@ void StartMoving(int x, int y)
        for(i=1;i<=3;i++)
        {
          int xx = x + i*dx, yy = y + i*dy;
-         int sx = SCROLLX(xx), sy = SCROLLY(yy);
+         int sx = SCREENX(xx), sy = SCREENY(yy);
 
          if (!IN_LEV_FIELD(xx,yy) ||
              IS_SOLID(Feld[xx][yy]) || Feld[xx][yy]==EL_EXPLODING)
@@ -1764,8 +1875,8 @@ void StartMoving(int x, int y)
        DrawLevelField(x,y);
 
        PlaySoundLevel(newx,newy,SND_BUING);
-       if (IN_SCR_FIELD(SCROLLX(newx),SCROLLY(newy)))
-         DrawGraphicThruMask(SCROLLX(newx),SCROLLY(newy),el2gfx(element));
+       if (IN_SCR_FIELD(SCREENX(newx),SCREENY(newy)))
+         DrawGraphicThruMask(SCREENX(newx),SCREENY(newy),el2gfx(element));
 
        local_player->friends_still_needed--;
        if (!local_player->friends_still_needed &&
@@ -1823,7 +1934,7 @@ void StartMoving(int x, int y)
       }
       else
       {
-       BOOL wanna_flame = !RND(10);
+       boolean wanna_flame = !RND(10);
        int dx = newx - x, dy = newy - y;
        int newx1 = newx+1*dx, newy1 = newy+1*dy;
        int newx2 = newx+2*dx, newy2 = newy+2*dy;
@@ -1902,27 +2013,7 @@ void StartMoving(int x, int y)
       else if (element == EL_BUTTERFLY || element == EL_FIREFLY)
        DrawGraphicAnimation(x,y, el2gfx(element), 2, 4, ANIM_NORMAL);
       else if (element==EL_SONDE)
-      {
-       int i;
-
-       /* check if this element is just being pushed */
-       for(i=0; i<MAX_PLAYERS; i++)
-       {
-         struct PlayerInfo *player = &stored_player[i];
-
-         if (player->active && !player->gone &&
-             player->Pushing && player->GfxPos)
-         {
-           int next_jx = player->jx + (player->jx - player->last_jx);
-           int next_jy = player->jy + (player->jy - player->last_jy);
-
-           if (x == next_jx && y == next_jy)
-             return;
-         }
-       }
-
        DrawGraphicAnimation(x,y, GFX_SONDE_START, 8, 2, ANIM_NORMAL);
-      }
 
       return;
     }
@@ -2147,7 +2238,7 @@ void AmoebeUmwandeln2(int ax, int ay, int new_element)
 {
   int x,y;
   int group_nr = AmoebaNr[ax][ay];
-  BOOL done = FALSE;
+  boolean done = FALSE;
 
   for(y=0;y<lev_fieldy;y++) for(x=0;x<lev_fieldx;x++)
   {
@@ -2186,8 +2277,8 @@ void AmoebeWaechst(int x, int y)
   if (MovDelay[x][y])          /* neue Phase / in Wartezustand */
   {
     MovDelay[x][y]--;
-    if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
-      DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_AMOEBING+3-MovDelay[x][y]/2);
+    if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
+      DrawGraphic(SCREENX(x),SCREENY(y),GFX_AMOEBING+3-MovDelay[x][y]/2);
 
     if (!MovDelay[x][y])
     {
@@ -2250,7 +2341,7 @@ void AmoebeAbleger(int ax, int ay)
   else                         /* normale oder "gefüllte" Amöbe */
   {
     int start = RND(4);
-    BOOL waiting_for_player = FALSE;
+    boolean waiting_for_player = FALSE;
 
     for(i=0;i<4;i++)
     {
@@ -2402,8 +2493,8 @@ void Ablenk(int x, int y)
     MovDelay[x][y]--;
     if (MovDelay[x][y])
     {
-      if (IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
-       DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_ABLENK+MovDelay[x][y]%4);
+      if (IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
+       DrawGraphic(SCREENX(x),SCREENY(y),GFX_ABLENK+MovDelay[x][y]%4);
       if (!(MovDelay[x][y]%4))
        PlaySoundLevel(x,y,SND_MIEP);
       return;
@@ -2461,8 +2552,8 @@ void NussKnacken(int x, int y)
   if (MovDelay[x][y])          /* neue Phase / in Wartezustand */
   {
     MovDelay[x][y]--;
-    if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
-      DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_CRACKINGNUT+3-MovDelay[x][y]/2);
+    if (MovDelay[x][y]/2 && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
+      DrawGraphic(SCREENX(x),SCREENY(y),GFX_CRACKINGNUT+3-MovDelay[x][y]/2);
 
     if (!MovDelay[x][y])
     {
@@ -2474,8 +2565,8 @@ void NussKnacken(int x, int y)
 
 void SiebAktivieren(int x, int y, int typ)
 {
-  if (!(SiebAktiv % 4) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
-    DrawGraphic(SCROLLX(x),SCROLLY(y),
+  if (!(SiebAktiv % 4) && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
+    DrawGraphic(SCREENX(x),SCREENY(y),
                (typ==1 ? GFX_SIEB_VOLL : GFX_SIEB2_VOLL)+3-(SiebAktiv%16)/4);
 }
 
@@ -2487,10 +2578,10 @@ void AusgangstuerPruefen(int x, int y)
   {
     Feld[x][y] = EL_AUSGANG_ACT;
 
-    PlaySoundLevel(x < UNSCROLLX(BX1) ? UNSCROLLX(BX1) :
-                  (x > UNSCROLLX(BX2) ? UNSCROLLX(BX2) : x),
-                  y < UNSCROLLY(BY1) ? UNSCROLLY(BY1) :
-                  (y > UNSCROLLY(BY2) ? UNSCROLLY(BY2) : y),
+    PlaySoundLevel(x < LEVELX(BX1) ? LEVELX(BX1) :
+                  (x > LEVELX(BX2) ? LEVELX(BX2) : x),
+                  y < LEVELY(BY1) ? LEVELY(BY1) :
+                  (y > LEVELY(BY2) ? LEVELY(BY2) : y),
                   SND_OEFFNEN);
   }
 }
@@ -2508,8 +2599,8 @@ void AusgangstuerOeffnen(int x, int y)
 
     MovDelay[x][y]--;
     tuer = MovDelay[x][y]/delay;
-    if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
-      DrawGraphic(SCROLLX(x),SCROLLY(y),GFX_AUSGANG_AUF-tuer);
+    if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
+      DrawGraphic(SCREENX(x),SCREENY(y),GFX_AUSGANG_AUF-tuer);
 
     if (!MovDelay[x][y])
     {
@@ -2526,7 +2617,7 @@ void AusgangstuerBlinken(int x, int y)
 
 void EdelsteinFunkeln(int x, int y)
 {
-  if (!IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)) || IS_MOVING(x,y))
+  if (!IN_SCR_FIELD(SCREENX(x),SCREENY(y)) || IS_MOVING(x,y))
     return;
 
   if (Feld[x][y] == EL_EDELSTEIN_BD)
@@ -2540,10 +2631,10 @@ void EdelsteinFunkeln(int x, int y)
     {
       MovDelay[x][y]--;
 
-      if (direct_draw_on && MovDelay[x][y])
+      if (setup.direct_draw_on && MovDelay[x][y])
        SetDrawtoField(DRAW_BUFFERED);
 
-      DrawGraphic(SCROLLX(x),SCROLLY(y), el2gfx(Feld[x][y]));
+      DrawGraphic(SCREENX(x),SCREENY(y), el2gfx(Feld[x][y]));
 
       if (MovDelay[x][y])
       {
@@ -2552,14 +2643,14 @@ void EdelsteinFunkeln(int x, int y)
        if (phase > 2)
          phase = 4-phase;
 
-       DrawGraphicThruMask(SCROLLX(x),SCROLLY(y), GFX_FUNKELN_WEISS + phase);
+       DrawGraphicThruMask(SCREENX(x),SCREENY(y), GFX_FUNKELN_WEISS + phase);
 
-       if (direct_draw_on)
+       if (setup.direct_draw_on)
        {
          int dest_x,dest_y;
 
-         dest_x = FX + SCROLLX(x)*TILEX;
-         dest_y = FY + SCROLLY(y)*TILEY;
+         dest_x = FX + SCREENX(x)*TILEX;
+         dest_y = FY + SCREENY(y)*TILEY;
 
          XCopyArea(display,drawto_field,window,gc,
                    dest_x,dest_y, TILEX,TILEY, dest_x,dest_y);
@@ -2583,25 +2674,39 @@ void MauerWaechst(int x, int y)
 
     MovDelay[x][y]--;
     phase = 2-MovDelay[x][y]/delay;
-    if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
-      DrawGraphic(SCROLLX(x),SCROLLY(y),
-                 (Store[x][y]==MV_LEFT ? GFX_MAUER_L1 : GFX_MAUER_R1)+phase);
+    if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCREENX(x),SCREENY(y)))
+      DrawGraphic(SCREENX(x),SCREENY(y),
+                 (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);
     }
   }
@@ -2609,8 +2714,11 @@ void MauerWaechst(int x, int y)
 
 void MauerAbleger(int ax, int ay)
 {
-  BOOL links_frei = FALSE, rechts_frei = FALSE;
-  BOOL links_massiv = FALSE, rechts_massiv = FALSE;
+  int element = Feld[ax][ay];
+  boolean oben_frei = FALSE, unten_frei = FALSE;
+  boolean links_frei = FALSE, rechts_frei = FALSE;
+  boolean oben_massiv = FALSE, unten_massiv = FALSE;
+  boolean links_massiv = FALSE, rechts_massiv = FALSE;
 
   if (!MovDelay[ax][ay])       /* neue Mauer / noch nicht gewartet */
     MovDelay[ax][ay] = 6;
@@ -2622,42 +2730,79 @@ 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(SCROLLX(ax-1),SCROLLY(ay)))
-      DrawGraphic(SCROLLX(ax-1),SCROLLY(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(SCROLLX(ax+1),SCROLLY(ay)))
-      DrawGraphic(SCROLLX(ax+1),SCROLLY(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;
 }
 
 void CheckForDragon(int x, int y)
 {
   int i,j;
-  BOOL dragon_found = FALSE;
+  boolean dragon_found = FALSE;
   static int xy[4][2] =
   {
     { 0,-1 },
@@ -2703,9 +2848,11 @@ void CheckForDragon(int x, int y)
   }
 }
 
-void PlayerActions(struct PlayerInfo *player, int player_action)
+void PlayerActions(struct PlayerInfo *player, byte player_action)
 {
-  BOOL moved = FALSE, snapped = FALSE, bombed = FALSE;
+  static byte stored_player_action[MAX_PLAYERS];
+  static int num_stored_actions = 0;
+  boolean moved = FALSE, snapped = FALSE, bombed = FALSE;
   int jx = player->jx, jy = player->jy;
   int left     = player_action & JOY_LEFT;
   int right    = player_action & JOY_RIGHT;
@@ -2716,6 +2863,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;
 
@@ -2736,7 +2886,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 */
@@ -2752,7 +2910,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)
     {
@@ -2774,12 +2933,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;
@@ -2795,20 +2955,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 =
+      (options.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 (!options.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;
@@ -2874,14 +3119,17 @@ 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);
 
     if (SiebAktiv)
     {
-      BOOL sieb = FALSE;
+      boolean sieb = FALSE;
       int jx = local_player->jx, jy = local_player->jy;
 
       if (element==EL_SIEB_LEER || element==EL_SIEB_VOLL ||
@@ -2951,12 +3199,54 @@ void GameActions(int player_action)
   DrawAllPlayers();
 }
 
+static boolean 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 boolean 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 softscroll_offset = (setup.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,
@@ -2982,8 +3272,8 @@ void ScrollLevel(int dx, int dy)
   redraw_mask |= REDRAW_FIELD;
 }
 
-BOOL MoveFigureOneStep(struct PlayerInfo *player,
-                      int dx, int dy, int real_dx, int real_dy)
+boolean MoveFigureOneStep(struct PlayerInfo *player,
+                         int dx, int dy, int real_dx, int real_dy)
 {
   int jx = player->jx, jy = player->jy;
   int new_jx = jx+dx, new_jy = jy+dy;
@@ -3001,6 +3291,9 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player,
   if (!IN_LEV_FIELD(new_jx,new_jy))
     return(MF_NO_ACTION);
 
+  if (!options.network && !AllPlayersInSight(player, new_jx,new_jy))
+    return(MF_NO_ACTION);
+
   element = MovingOrBlocked2Element(new_jx,new_jy);
 
   if (DONT_GO_TO(element))
@@ -3024,21 +3317,21 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player,
   if (can_move != MF_MOVING)
     return(can_move);
 
-  StorePlayer[jx][jy] = EL_LEERRAUM;
+  StorePlayer[jx][jy] = 0;
   player->last_jx = jx;
   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);
 }
 
-BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy)
+boolean MoveFigure(struct PlayerInfo *player, int dx, int dy)
 {
   int jx = player->jx, jy = player->jy;
   int old_jx = jx, old_jy = jy;
@@ -3064,20 +3357,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 || !options.network))
   {
     int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
-    int offset = (scroll_delay_on ? 3 : 0);
+    int offset = (setup.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 (!options.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)
@@ -3115,7 +3482,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);
@@ -3132,12 +3499,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;
 
@@ -3147,7 +3508,40 @@ void ScrollFigure(struct PlayerInfo *player, int mode)
   {
     player->last_jx = jx;
     player->last_jy = jy;
+
+    if (Feld[jx][jy] == EL_AUSGANG_AUF)
+    {
+      RemoveHero(player);
+
+      if (!local_player->friends_still_needed)
+       player->LevelSolved = player->GameOver = TRUE;
+    }
+  }
+}
+
+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)
@@ -3394,23 +3788,12 @@ int DigField(struct PlayerInfo *player,
     case EL_EDELSTEIN_GELB:
     case EL_EDELSTEIN_ROT:
     case EL_EDELSTEIN_LILA:
-      Feld[x][y] = EL_LEERRAUM;
-      MovDelay[x][y] = 0;      /* wegen EDELSTEIN_BD-Funkeln! */
-      if (local_player->gems_still_needed > 0)
-       local_player->gems_still_needed--;
-      RaiseScoreElement(EL_EDELSTEIN);
-      DrawText(DX_EMERALDS, DY_EMERALDS,
-              int2str(local_player->gems_still_needed, 3),
-              FS_SMALL, FC_YELLOW);
-      PlaySoundLevel(x, y, SND_PONG);
-      break;
-
     case EL_DIAMANT:
-      Feld[x][y] = EL_LEERRAUM;
-      local_player->gems_still_needed -= 3;
+      RemoveField(x,y);
+      local_player->gems_still_needed -= (element == EL_DIAMANT ? 3 : 1);
       if (local_player->gems_still_needed < 0)
        local_player->gems_still_needed = 0;
-      RaiseScoreElement(EL_DIAMANT);
+      RaiseScoreElement(element);
       DrawText(DX_EMERALDS, DY_EMERALDS,
               int2str(local_player->gems_still_needed, 3),
               FS_SMALL, FC_YELLOW);
@@ -3418,7 +3801,7 @@ int DigField(struct PlayerInfo *player,
       break;
 
     case EL_DYNAMIT_AUS:
-      Feld[x][y] = EL_LEERRAUM;
+      RemoveField(x,y);
       player->dynamite++;
       RaiseScoreElement(EL_DYNAMIT);
       DrawText(DX_DYNAMITE, DY_DYNAMITE,
@@ -3428,22 +3811,22 @@ int DigField(struct PlayerInfo *player,
       break;
 
     case EL_DYNABOMB_NR:
-      Feld[x][y] = EL_LEERRAUM;
+      RemoveField(x,y);
       player->dynabomb_count++;
       player->dynabombs_left++;
       RaiseScoreElement(EL_DYNAMIT);
       PlaySoundLevel(x,y,SND_PONG);
       break;
-    case EL_DYNABOMB_SZ:
 
-      Feld[x][y] = EL_LEERRAUM;
+    case EL_DYNABOMB_SZ:
+      RemoveField(x,y);
       player->dynabomb_size++;
       RaiseScoreElement(EL_DYNAMIT);
       PlaySoundLevel(x,y,SND_PONG);
       break;
 
     case EL_DYNABOMB_XL:
-      Feld[x][y] = EL_LEERRAUM;
+      RemoveField(x,y);
       player->dynabomb_xl = TRUE;
       RaiseScoreElement(EL_DYNAMIT);
       PlaySoundLevel(x,y,SND_PONG);
@@ -3456,7 +3839,7 @@ int DigField(struct PlayerInfo *player,
     {
       int key_nr = element-EL_SCHLUESSEL1;
 
-      Feld[x][y] = EL_LEERRAUM;
+      RemoveField(x,y);
       player->key[key_nr] = TRUE;
       RaiseScoreElement(EL_SCHLUESSEL);
       DrawMiniGraphicExt(drawto,gc,
@@ -3501,7 +3884,7 @@ int DigField(struct PlayerInfo *player,
          !tape.playing)
        return(MF_NO_ACTION);
 
-      Feld[x][y] = EL_LEERRAUM;
+      RemoveField(x,y);
       Feld[x+dx][y+dy] = element;
 
       player->push_delay_value = 2+RND(8);
@@ -3541,11 +3924,15 @@ int DigField(struct PlayerInfo *player,
       if (mode==DF_SNAP)
        return(MF_NO_ACTION);
 
+      PlaySoundLevel(x,y,SND_BUING);
+
+      /*
       player->gone = TRUE;
       PlaySoundLevel(x,y,SND_BUING);
 
       if (!local_player->friends_still_needed)
        player->LevelSolved = player->GameOver = TRUE;
+      */
 
       break;
 
@@ -3608,7 +3995,7 @@ int DigField(struct PlayerInfo *player,
          local_player->sokobanfields_still_needed++;
        }
        else
-         Feld[x][y] = EL_LEERRAUM;
+         RemoveField(x,y);
 
        if (Feld[x+dx][y+dy] == EL_SOKOBAN_FELD_LEER)
        {
@@ -3622,7 +4009,7 @@ int DigField(struct PlayerInfo *player,
       }
       else
       {
-       Feld[x][y] = EL_LEERRAUM;
+       RemoveField(x,y);
        Feld[x+dx][y+dy] = element;
       }
 
@@ -3658,7 +4045,7 @@ int DigField(struct PlayerInfo *player,
   return(MF_MOVING);
 }
 
-BOOL SnapField(struct PlayerInfo *player, int dx, int dy)
+boolean SnapField(struct PlayerInfo *player, int dx, int dy)
 {
   int jx = player->jx, jy = player->jy;
   int x = jx + dx, y = jy + dy;
@@ -3693,7 +4080,7 @@ BOOL SnapField(struct PlayerInfo *player, int dx, int dy)
   return(TRUE);
 }
 
-BOOL PlaceBomb(struct PlayerInfo *player)
+boolean PlaceBomb(struct PlayerInfo *player)
 {
   int jx = player->jx, jy = player->jy;
   int element;
@@ -3717,15 +4104,17 @@ BOOL PlaceBomb(struct PlayerInfo *player)
     player->dynamite--;
     DrawText(DX_DYNAMITE, DY_DYNAMITE, int2str(local_player->dynamite, 3),
             FS_SMALL, FC_YELLOW);
-    DrawGraphicThruMask(SCROLLX(jx),SCROLLY(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(SCROLLX(jx),SCROLLY(jy),GFX_DYNABOMB);
+    if (IN_SCR_FIELD(SCREENX(jx),SCREENY(jy)))
+      DrawGraphicThruMask(SCREENX(jx),SCREENY(jy),GFX_DYNABOMB);
   }
 
   return(TRUE);
@@ -3733,12 +4122,12 @@ BOOL PlaceBomb(struct PlayerInfo *player)
 
 void PlaySoundLevel(int x, int y, int sound_nr)
 {
-  int sx = SCROLLX(x), sy = SCROLLY(y);
+  int sx = SCREENX(x), sy = SCREENY(y);
   int volume, stereo;
   int silence_distance = 8;
 
-  if ((!sound_simple_on && !IS_LOOP_SOUND(sound_nr)) ||
-      (!sound_loops_on && IS_LOOP_SOUND(sound_nr)))
+  if ((!setup.sound_simple_on && !IS_LOOP_SOUND(sound_nr)) ||
+      (!setup.sound_loops_on && IS_LOOP_SOUND(sound_nr)))
     return;
 
   if (!IN_LEV_FIELD(x,y) ||
@@ -3778,6 +4167,10 @@ void RaiseScoreElement(int element)
   switch(element)
   {
     case EL_EDELSTEIN:
+    case EL_EDELSTEIN_BD:
+    case EL_EDELSTEIN_GELB:
+    case EL_EDELSTEIN_ROT:
+    case EL_EDELSTEIN_LILA:
       RaiseScore(level.score[SC_EDELSTEIN]);
       break;
     case EL_DIAMANT: