rnd-20030816-1-src
[rocksndiamonds.git] / src / game.c
index 461518830eff29fd78da568bfbbbabecf7fc90f3..5956c7d899ca466076188317e162b2fbad6382b1 100644 (file)
@@ -427,7 +427,7 @@ static unsigned long trigger_events[MAX_NUM_ELEMENTS];
 void GetPlayerConfig()
 {
   if (!audio.sound_available)
-    setup.sound = FALSE;
+    setup.sound_simple = FALSE;
 
   if (!audio.loops_available)
     setup.sound_loops = FALSE;
@@ -438,7 +438,7 @@ void GetPlayerConfig()
   if (!video.fullscreen_available)
     setup.fullscreen = FALSE;
 
-  setup.sound_simple = setup.sound;
+  setup.sound = (setup.sound_simple || setup.sound_loops || setup.sound_music);
 
   SetAudioMode(setup.sound);
   InitJoysticks();
@@ -1222,47 +1222,60 @@ void InitGame()
   {
     int start_x = 0, start_y = 0;
     int found_rating = 0;
+    int found_element = EL_UNDEFINED;
 
-    for(y=0; y < lev_fieldy; y++)
+    for(y=0; y < lev_fieldy; y++) for(x=0; x < lev_fieldx; x++)
     {
-      for(x=0; x < lev_fieldx; x++)
+      int element = Feld[x][y];
+      int content;
+      int xx, yy;
+      boolean is_player;
+
+      if (!IS_CUSTOM_ELEMENT(element))
+       continue;
+
+      if (CAN_CHANGE(element))
       {
-       int element = Feld[x][y];
+       content = element_info[element].change.target_element;
+       is_player = (ELEM_IS_PLAYER(content) || content == EL_SP_MURPHY);
 
-       if (IS_CUSTOM_ELEMENT(element))
+       if (is_player && (found_rating < 3 || element < found_element))
        {
-         int xx, yy;
+         start_x = x;
+         start_y = y;
 
-         for(yy=0; yy < 3; yy++)
-         {
-           for(xx=0; xx < 3; xx++)
-           {
-             int content;
-             boolean is_player;
+         found_rating = 3;
+         found_element = element;
+       }
+      }
 
-             content = element_info[element].content[xx][yy];
-             is_player = (ELEM_IS_PLAYER(content) || content == EL_SP_MURPHY);
+      for(yy=0; yy < 3; yy++) for(xx=0; xx < 3; xx++)
+      {
+       content = element_info[element].content[xx][yy];
+       is_player = (ELEM_IS_PLAYER(content) || content == EL_SP_MURPHY);
 
-             if (is_player && found_rating < 2)
-             {
-               start_x = x + xx - 1;
-               start_y = y + yy - 1;
+       if (is_player && (found_rating < 2 || element < found_element))
+       {
+         start_x = x + xx - 1;
+         start_y = y + yy - 1;
 
-               found_rating = 2;
-             }
+         found_rating = 2;
+         found_element = element;
+       }
 
-             content = element_info[element].change.content[xx][yy];
-             is_player = (ELEM_IS_PLAYER(content) || content == EL_SP_MURPHY);
+       if (!CAN_CHANGE(element))
+         continue;
 
-             if (is_player && found_rating < 1)
-             {
-               start_x = x + xx - 1;
-               start_y = y + yy - 1;
+       content = element_info[element].change.content[xx][yy];
+       is_player = (ELEM_IS_PLAYER(content) || content == EL_SP_MURPHY);
 
-               found_rating = 1;
-             }
-           }
-         }
+       if (is_player && (found_rating < 1 || element < found_element))
+       {
+         start_x = x + xx - 1;
+         start_y = y + yy - 1;
+
+         found_rating = 1;
+         found_element = element;
        }
       }
     }
@@ -1960,22 +1973,50 @@ void RelocatePlayer(int x, int y, int element)
     }
 
     RemoveField(player->jx, player->jy);
+    DrawLevelField(player->jx, player->jy);
   }
 
   InitPlayerField(x, y, element, TRUE);
 
   if (player == local_player)
   {
-    scroll_x = (local_player->jx < SBX_Left  + MIDPOSX ? SBX_Left :
-               local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
-               local_player->jx - MIDPOSX);
+    int scroll_xx = -999, scroll_yy = -999;
 
-    scroll_y = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
-               local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
-               local_player->jy - MIDPOSY);
-  }
+    while (scroll_xx != scroll_x || scroll_yy != scroll_y)
+    {
+      int dx = 0, dy = 0;
+      int fx = FX, fy = FY;
 
-  DrawLevel();
+      scroll_xx = (local_player->jx < SBX_Left  + MIDPOSX ? SBX_Left :
+                  local_player->jx > SBX_Right + MIDPOSX ? SBX_Right :
+                  local_player->jx - MIDPOSX);
+
+      scroll_yy = (local_player->jy < SBY_Upper + MIDPOSY ? SBY_Upper :
+                  local_player->jy > SBY_Lower + MIDPOSY ? SBY_Lower :
+                  local_player->jy - MIDPOSY);
+
+      dx = (scroll_xx < scroll_x ? +1 : scroll_xx > scroll_x ? -1 : 0);
+      dy = (scroll_yy < scroll_y ? +1 : scroll_yy > scroll_y ? -1 : 0);
+
+      scroll_x -= dx;
+      scroll_y -= dy;
+
+      fx += dx * TILEX / 2;
+      fy += dy * TILEY / 2;
+
+      ScrollLevel(dx, dy);
+      DrawAllPlayers();
+
+      /* scroll in to steps of half tile size to make things smoother */
+      BlitBitmap(drawto_field, window, fx, fy, SXSIZE, SYSIZE, SX, SY);
+      FlushDisplay();
+      Delay(GAME_FRAME_DELAY);
+
+      /* scroll second step to align at full tile size */
+      BackToFront();
+      Delay(GAME_FRAME_DELAY);
+    }
+  }
 }
 
 void Explode(int ex, int ey, int phase, int mode)
@@ -5295,6 +5336,9 @@ static void ChangeElementNowExt(int x, int y, int target_element)
   TestIfBadThingTouchesHero(x, y);
   TestIfPlayerTouchesCustomElement(x, y);
   TestIfElementTouchesCustomElement(x, y);
+
+  if (ELEM_IS_PLAYER(target_element))
+    RelocatePlayer(x, y, target_element);
 }
 
 static void ChangeElementNow(int x, int y, int element)
@@ -6188,24 +6232,24 @@ void ScrollLevel(int dx, int dy)
   int x, y;
 
   BlitBitmap(drawto_field, drawto_field,
-            FX + TILEX*(dx == -1) - softscroll_offset,
-            FY + TILEY*(dy == -1) - softscroll_offset,
-            SXSIZE - TILEX*(dx!=0) + 2*softscroll_offset,
-            SYSIZE - TILEY*(dy!=0) + 2*softscroll_offset,
-            FX + TILEX*(dx == 1) - softscroll_offset,
-            FY + TILEY*(dy == 1) - softscroll_offset);
+            FX + TILEX * (dx == -1) - softscroll_offset,
+            FY + TILEY * (dy == -1) - softscroll_offset,
+            SXSIZE - TILEX * (dx!=0) + 2 * softscroll_offset,
+            SYSIZE - TILEY * (dy!=0) + 2 * softscroll_offset,
+            FX + TILEX * (dx == 1) - softscroll_offset,
+            FY + TILEY * (dy == 1) - softscroll_offset);
 
   if (dx)
   {
     x = (dx == 1 ? BX1 : BX2);
-    for (y=BY1; y<=BY2; y++)
+    for (y=BY1; y <= BY2; y++)
       DrawScreenField(x, y);
   }
 
   if (dy)
   {
     y = (dy == 1 ? BY1 : BY2);
-    for (x=BX1; x<=BX2; x++)
+    for (x=BX1; x <= BX2; x++)
       DrawScreenField(x, y);
   }