rnd-19981108-2
[rocksndiamonds.git] / src / game.c
index 622a1857a553a41e70a89b7a00a9c5ff0cc152d4..017adc470abf7a353bd45c16c5738af65bff89cc 100644 (file)
 
 void GetPlayerConfig()
 {
-  int old_joystick_nr = joystick_nr;
+  if (sound_status == SOUND_OFF)
+    setup.sound = FALSE;
 
-  if (sound_status==SOUND_OFF)
-    local_player->setup &= ~SETUP_SOUND;
   if (!sound_loops_allowed)
   {
-    local_player->setup &= ~SETUP_SOUND_LOOPS;
-    local_player->setup &= ~SETUP_SOUND_MUSIC;
+    setup.sound_loops = FALSE;
+    setup.sound_music = FALSE;
   }
 
-  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_simple = setup.sound;
 
-#ifndef MSDOS
-  if (joystick_nr != old_joystick_nr)
-  {
-    if (joystick_device)
-      close(joystick_device);
-    InitJoystick();
-  }
-#endif
+  InitJoysticks();
 }
 
 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 = (network && !tape.playing);
+  network_playing = (options.network && !tape.playing);
 
   for(i=0; i<MAX_PLAYERS; i++)
   {
@@ -72,8 +54,12 @@ void InitGame()
 
     player->index_nr = i;
     player->element_nr = EL_SPIELER1 + i;
+
+    player->present = FALSE;
     player->active = FALSE;
-    player->local = FALSE;
+
+    player->action = 0;
+    player->effective_action = 0;
 
     player->score = 0;
     player->gems_still_needed = level.edelsteine;
@@ -116,22 +102,10 @@ void InitGame()
     DigField(player, 0,0,0,0,DF_NO_PUSH);
     SnapField(player, 0,0);
 
-
-    /* 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 */
@@ -181,16 +155,32 @@ void InitGame()
        struct PlayerInfo *player = &stored_player[Feld[x][y] - EL_SPIELER1];
        int jx = player->jx, jy = player->jy;
 
-       /* remove duplicate players */
-       if (StorePlayer[jx][jy] == Feld[x][y])
-         StorePlayer[jx][jy] = 0;
+       player->present = TRUE;
+
+       /*
+       if (!network_playing || player->connected)
+       */
+
+       if (!options.network || player->connected)
+       {
+         player->active = TRUE;
+
+         /* remove potentially duplicate players */
+         if (StorePlayer[jx][jy] == Feld[x][y])
+           StorePlayer[jx][jy] = 0;
 
-       player->active = TRUE;
+         StorePlayer[x][y] = Feld[x][y];
+
+         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");
+       }
 
-       StorePlayer[x][y] = Feld[x][y];
        Feld[x][y] = EL_LEERRAUM;
        player->jx = player->last_jx = x;
        player->jy = player->last_jy = y;
+
        break;
       }
       case EL_BADEWANNE:
@@ -268,6 +258,72 @@ 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)
+    {
+      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;
+       }
+      }
+    }
+  }
+
+  /* when in single player mode, eliminate all but the first active player */
+  if (!options.network && !setup.team_mode)
+  {
+    for(i=0; i<MAX_PLAYERS; i++)
+    {
+      if (stored_player[i].active)
+      {
+       for(j=i+1; j<MAX_PLAYERS; j++)
+       {
+         struct PlayerInfo *player = &stored_player[j];
+         int jx = player->jx, jy = player->jy;
+
+         if (player->active)
+         {
+           player->active = FALSE;
+           StorePlayer[jx][jy] = 0;
+           Feld[jx][jy] = EL_LEERRAUM;
+         }
+       }
+      }
+    }
+  }
+
+  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);
 
@@ -309,9 +365,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));
+  DrawSoundDisplay(BUTTON_SOUND_LOOPS  | (BUTTON_ON * setup.sound_loops));
+  DrawSoundDisplay(BUTTON_SOUND_SIMPLE | (BUTTON_ON * setup.sound_simple));
   XCopyArea(display,drawto,pix[PIX_DB_DOOR],gc,
            DX+GAME_CONTROL_XPOS,DY+GAME_CONTROL_YPOS,
            GAME_CONTROL_XSIZE,2*GAME_CONTROL_YSIZE,
@@ -320,10 +376,16 @@ void InitGame()
 
   OpenDoor(DOOR_OPEN_1);
 
-  if (sound_music_on)
+  if (setup.sound_music)
     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)
@@ -439,16 +501,19 @@ void GameWon()
   int hi_pos;
   int bumplevel = FALSE;
 
+  if (local_player->MovPos)
+    return;
+
   local_player->LevelSolved = FALSE;
 
   if (TimeLeft)
   {
-    if (sound_loops_on)
+    if (setup.sound_loops)
       PlaySoundExt(SND_SIRR, PSND_MAX_VOLUME, PSND_MAX_RIGHT, PSND_LOOP);
 
     while(TimeLeft > 0)
     {
-      if (!sound_loops_on)
+      if (!setup.sound_loops)
        PlaySoundStereo(SND_SIRR, PSND_MAX_RIGHT);
       if (TimeLeft && !(TimeLeft % 10))
        RaiseScore(level.score[SC_ZEITBONUS]);
@@ -461,7 +526,7 @@ void GameWon()
       Delay(10);
     }
 
-    if (sound_loops_on)
+    if (setup.sound_loops)
       StopSound(SND_SIRR);
   }
 
@@ -479,15 +544,7 @@ void GameWon()
   if (tape.recording)
   {
     TapeStop();
-    SaveLevelTape(tape.level_nr);      /* Ask to save tape */
-  }
-
-  if (level_nr == local_player->handicap &&
-      level_nr < leveldir[leveldir_nr].levels-1)
-  { 
-    local_player->handicap++; 
-    bumplevel = TRUE;
-    SavePlayerInfo(PLAYER_LEVEL);
+    SaveTape(tape.level_nr);           /* Ask to save tape */
   }
 
   if ((hi_pos=NewHiScore()) >= 0) 
@@ -508,14 +565,14 @@ void GameWon()
   BackToFront();
 }
 
-BOOL NewHiScore()
+boolean NewHiScore()
 {
   int k,l;
   int position = -1;
 
   LoadScore(level_nr);
 
-  if (!strcmp(local_player->alias_name,EMPTY_ALIAS) ||
+  if (!strcmp(setup.alias_name,EMPTY_ALIAS) ||
       local_player->score < highscore[MAX_SCORE_ENTRIES-1].Score) 
     return(-1);
 
@@ -531,7 +588,7 @@ BOOL NewHiScore()
 
 #ifdef ONE_PER_NAME
        for(l=k;l<MAX_SCORE_ENTRIES;l++)
-         if (!strcmp(local_player->alias_name,highscore[l].Name))
+         if (!strcmp(setup.alias_name,highscore[l].Name))
            m = l;
        if (m==k)       /* Spieler überschreibt seine alte Position */
          goto put_into_list;
@@ -547,14 +604,14 @@ BOOL NewHiScore()
 #ifdef ONE_PER_NAME
       put_into_list:
 #endif
-      sprintf(highscore[k].Name,local_player->alias_name);
+      sprintf(highscore[k].Name,setup.alias_name);
       highscore[k].Score = local_player->score; 
       position = k;
       break;
     }
 
 #ifdef ONE_PER_NAME
-    else if (!strcmp(local_player->alias_name,highscore[k].Name))
+    else if (!strcmp(setup.alias_name,highscore[k].Name))
       break;   /* Spieler schon mit besserer Punktzahl in der Liste */
 #endif
 
@@ -992,8 +1049,8 @@ 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;
 
@@ -1223,7 +1280,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) ||
@@ -1247,7 +1304,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) ||
@@ -1271,7 +1328,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) ||
@@ -1295,9 +1352,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);
 
@@ -1367,7 +1424,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);
 
@@ -1486,7 +1543,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] =
@@ -1520,7 +1577,7 @@ void TurnRound(int x, int y)
   }
 }
 
-static BOOL JustBeingPushed(int x, int y)
+static boolean JustBeingPushed(int x, int y)
 {
   int i;
 
@@ -1665,10 +1722,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)
       {
@@ -1861,7 +1918,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;
@@ -2165,7 +2222,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++)
   {
@@ -2268,7 +2325,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++)
     {
@@ -2558,7 +2615,7 @@ void EdelsteinFunkeln(int x, int y)
     {
       MovDelay[x][y]--;
 
-      if (direct_draw_on && MovDelay[x][y])
+      if (setup.direct_draw && MovDelay[x][y])
        SetDrawtoField(DRAW_BUFFERED);
 
       DrawGraphic(SCREENX(x),SCREENY(y), el2gfx(Feld[x][y]));
@@ -2572,7 +2629,7 @@ void EdelsteinFunkeln(int x, int y)
 
        DrawGraphicThruMask(SCREENX(x),SCREENY(y), GFX_FUNKELN_WEISS + phase);
 
-       if (direct_draw_on)
+       if (setup.direct_draw)
        {
          int dest_x,dest_y;
 
@@ -2642,10 +2699,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;
+  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;
@@ -2729,7 +2786,7 @@ void MauerAbleger(int ax, int ay)
 void CheckForDragon(int x, int y)
 {
   int i,j;
-  BOOL dragon_found = FALSE;
+  boolean dragon_found = FALSE;
   static int xy[4][2] =
   {
     { 0,-1 },
@@ -2775,11 +2832,12 @@ void CheckForDragon(int x, int y)
   }
 }
 
-void PlayerActions(struct PlayerInfo *player, byte player_action)
+static 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;
+  static boolean save_tape_entry = FALSE;
+  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;
@@ -2793,11 +2851,12 @@ void PlayerActions(struct PlayerInfo *player, byte player_action)
   stored_player_action[player->index_nr] = 0;
   num_stored_actions++;
 
-  if (!player->active || player->gone)
+  if (!player->active || player->gone || tape.pausing)
     return;
 
   if (player_action)
   {
+    save_tape_entry = TRUE;
     player->frame_reset_delay = 0;
 
     if (button1)
@@ -2816,12 +2875,15 @@ void PlayerActions(struct PlayerInfo *player, byte player_action)
 
       stored_player_action[player->index_nr] = player_action;
 
+#if 0
       /* this allows cycled sequences of PlayerActions() */
       if (num_stored_actions >= MAX_PLAYERS)
       {
        TapeRecordAction(stored_player_action);
        num_stored_actions = 0;
       }
+#endif
+
     }
     else if (tape.playing && snapped)
       SnapField(player, 0,0);                  /* stop snapping */
@@ -2834,13 +2896,21 @@ void PlayerActions(struct PlayerInfo *player, byte player_action)
       player->Frame = 0;
   }
 
+  if (tape.recording && num_stored_actions >= MAX_PLAYERS && save_tape_entry)
+  {
+    TapeRecordAction(stored_player_action);
+    num_stored_actions = 0;
+    save_tape_entry = FALSE;
+  }
+
   if (tape.playing && !tape.pausing && !player_action &&
       tape.counter < tape.length)
   {
     int next_joy =
       tape.pos[tape.counter].action[player->index_nr] & (JOY_LEFT|JOY_RIGHT);
 
-    if (next_joy == JOY_LEFT || next_joy == JOY_RIGHT)
+    if ((next_joy == JOY_LEFT || next_joy == JOY_RIGHT) &&
+       (player->MovDir != JOY_UP && player->MovDir != JOY_DOWN))
     {
       int dx = (next_joy == JOY_LEFT ? -1 : +1);
 
@@ -2860,24 +2930,20 @@ void PlayerActions(struct PlayerInfo *player, byte player_action)
   }
 }
 
-void GameActions(byte player_action)
+void GameActions()
 {
   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;
+  byte *recorded_player_action;
+  byte summarized_player_action = 0;
 
   if (game_status != PLAYING)
     return;
 
-#ifdef DEBUG
-  action_delay_value =
-    (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GameFrameDelay);
-#else
   action_delay_value =
-    (tape.playing && tape.fast_forward ? FFWD_FRAME_DELAY : GAME_FRAME_DELAY);
-#endif
+    (tape.playing && tape.fast_forward ? FfwdFrameDelay : GameFrameDelay);
 
   /* main game synchronization point */
   WaitUntilDelayReached(&action_delay, action_delay_value);
@@ -2908,63 +2974,53 @@ void GameActions(byte player_action)
   }
 
 
+  /*
   if (tape.pausing || (tape.playing && !TapePlayDelay()))
     return;
   else if (tape.recording)
     TapeRecordDelay();
+  */
 
+  if (tape.pausing)
+    return;
 
   if (tape.playing)
-    recorded_player_action = TapePlayAction();
-  else
-    recorded_player_action = NULL;
+    TapePlayDelay();
+  else if (tape.recording)
+    TapeRecordDelay();
 
-  if (network_playing)
-    SendToServer_MovePlayer(player_action);
+  recorded_player_action = (tape.playing ? TapePlayAction() : NULL);
 
   for(i=0; i<MAX_PLAYERS; i++)
   {
-    /*
-    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];
-    */
+    summarized_player_action |= stored_player[i].action;
 
-    /*
-    int actual_player_action = player_action;
-    */
-
-    /* TEST TEST TEST */
+    if (!network_playing)
+      stored_player[i].effective_action = stored_player[i].action;
+  }
 
-    /*
-    if (i != TestPlayer && !stored_player[i].MovPos)
-      actual_player_action = 0;
-    */
+  if (network_playing)
+    SendToServer_MovePlayer(summarized_player_action);
 
-    if (!network && i != TestPlayer)
-      actual_player_action = 0;
+  if (!options.network && !setup.team_mode)
+    local_player->effective_action = summarized_player_action;
 
-    /* TEST TEST TEST */
+  for(i=0; i<MAX_PLAYERS; i++)
+  {
+    int actual_player_action = stored_player[i].effective_action;
 
     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;
@@ -2972,15 +3028,10 @@ void GameActions(byte player_action)
     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;
@@ -3056,7 +3107,7 @@ void GameActions(byte player_action)
 
     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 ||
@@ -3126,7 +3177,7 @@ void GameActions(byte player_action)
   DrawAllPlayers();
 }
 
-static BOOL AllPlayersInSight(struct PlayerInfo *player, int x, int y)
+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;
@@ -3148,7 +3199,7 @@ static BOOL AllPlayersInSight(struct PlayerInfo *player, int x, int y)
   return(max_x - min_x < SCR_FIELDX && max_y - min_y < SCR_FIELDY);
 }
 
-static BOOL AllPlayersInVisibleScreen()
+static boolean AllPlayersInVisibleScreen()
 {
   int i;
 
@@ -3168,13 +3219,9 @@ static BOOL AllPlayersInVisibleScreen()
 
 void ScrollLevel(int dx, int dy)
 {
-  int softscroll_offset = (soft_scrolling_on ? TILEX : 0);
+  int softscroll_offset = (setup.soft_scrolling ? TILEX : 0);
   int x,y;
 
-  /*
-  ScreenGfxPos = local_player->GfxPos;
-  */
-
   XCopyArea(display,drawto_field,drawto_field,gc,
            FX + TILEX*(dx==-1) - softscroll_offset,
            FY + TILEY*(dy==-1) - softscroll_offset,
@@ -3199,8 +3246,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;
@@ -3218,7 +3265,7 @@ 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))
+  if (!options.network && !AllPlayersInSight(player, new_jx,new_jy))
     return(MF_NO_ACTION);
 
   element = MovingOrBlocked2Element(new_jx,new_jy);
@@ -3258,7 +3305,7 @@ BOOL MoveFigureOneStep(struct PlayerInfo *player,
   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;
@@ -3270,6 +3317,25 @@ BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy)
   if (!FrameReached(&player->move_delay,MoveSpeed) && !tape.playing)
     return(FALSE);
 
+  if (player->MovPos)
+  {
+    /* should only happen if pre-1.0 tape recordings are played */
+    /* this is only for backward compatibility */
+
+#if DEBUG
+    printf("THIS SHOULD ONLY HAPPEN WITH PRE-1.0 LEVEL TAPES.\n");
+#endif
+
+    while (player->MovPos)
+    {
+      ScrollFigure(player, SCROLL_GO_ON);
+      ScrollScreen(NULL, SCROLL_GO_ON);
+      FrameCounter++;
+      DrawAllPlayers();
+      BackToFront();
+    }
+  }
+
   if (player->last_move_dir & (MV_LEFT | MV_RIGHT))
   {
     if (!(moved |= MoveFigureOneStep(player, 0,dy, dx,dy)))
@@ -3284,24 +3350,11 @@ 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))
+      (player == local_player || !options.network))
   {
     int old_scroll_x = scroll_x, old_scroll_y = scroll_y;
-    int offset = (scroll_delay_on ? 3 : 0);
-
-    /*
-    if (player == local_player)
-    {
-      printf("MOVING LOCAL PLAYER && SCROLLING\n");
-    }
-    */
+    int offset = (setup.scroll_delay ? 3 : 0);
 
     if (!IN_VIS_FIELD(SCREENX(jx),SCREENY(jy)))
     {
@@ -3315,9 +3368,13 @@ BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy)
     {
       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);
+       if ((player->MovDir == MV_LEFT && scroll_x > jx-MIDPOSX+offset) ||
+           (player->MovDir == MV_RIGHT && scroll_x < jx-MIDPOSX-offset))
+         scroll_x = jx-MIDPOSX + (scroll_x < jx-MIDPOSX ? -offset : +offset);
+
+       /* don't scroll over playfield boundaries */
+       if (scroll_x < -1 || scroll_x > lev_fieldx - SCR_FIELDX + 1)
+         scroll_x = (scroll_x < -1 ? -1 : lev_fieldx - SCR_FIELDX + 1);
 
        /* don't scroll more than one field at a time */
        scroll_x = old_scroll_x + SIGN(scroll_x - old_scroll_x);
@@ -3329,9 +3386,13 @@ BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy)
       }
       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);
+       if ((player->MovDir == MV_UP && scroll_y > jy-MIDPOSY+offset) ||
+           (player->MovDir == MV_DOWN && scroll_y < jy-MIDPOSY-offset))
+         scroll_y = jy-MIDPOSY + (scroll_y < jy-MIDPOSY ? -offset : +offset);
+
+       /* don't scroll over playfield boundaries */
+       if (scroll_y < -1 || scroll_y > lev_fieldy - SCR_FIELDY + 1)
+         scroll_y = (scroll_y < -1 ? -1 : lev_fieldy - SCR_FIELDY + 1);
 
        /* don't scroll more than one field at a time */
        scroll_y = old_scroll_y + SIGN(scroll_y - old_scroll_y);
@@ -3343,25 +3404,9 @@ BOOL MoveFigure(struct PlayerInfo *player, int dx, int dy)
       }
     }
 
-#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)
     {
-      if (!network && !AllPlayersInVisibleScreen())
+      if (!options.network && !AllPlayersInVisibleScreen())
       {
        scroll_x = old_scroll_x;
        scroll_y = old_scroll_y;
@@ -3582,10 +3627,6 @@ void TestIfHeroHitsBadThing(int x, int y)
 
 void TestIfBadThingHitsHero(int x, int y)
 {
-  /*
-  TestIfGoodThingHitsBadThing(JX,JY);
-  */
-
   TestIfBadThingHitsGoodThing(x,y);
 }
 
@@ -3972,7 +4013,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;
@@ -4007,7 +4048,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;
@@ -4053,8 +4094,8 @@ void PlaySoundLevel(int x, int y, int sound_nr)
   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 && !IS_LOOP_SOUND(sound_nr)) ||
+      (!setup.sound_loops && IS_LOOP_SOUND(sound_nr)))
     return;
 
   if (!IN_LEV_FIELD(x,y) ||
@@ -4063,6 +4104,7 @@ void PlaySoundLevel(int x, int y, int sound_nr)
     return;
 
   volume = PSND_MAX_VOLUME;
+
 #ifndef MSDOS
   stereo = (sx-SCR_FIELDX/2)*12;
 #else