rnd-20030730-2-src
[rocksndiamonds.git] / src / game.c
index 78aa51586a8ece24210c35b23ed0c1c3c3b512e1..5a859675c607b680a25fdb11b29cedea4ede51ac 100644 (file)
@@ -1893,7 +1893,7 @@ void Explode(int ex, int ey, int phase, int mode)
       PlaySoundLevelAction(ex, ey, ACTION_EXPLODING);
 
     /* remove things displayed in background while burning dynamite */
-    if (!IS_INDESTRUCTIBLE(Back[ex][ey]))
+    if (Back[ex][ey] != EL_EMPTY && !IS_INDESTRUCTIBLE(Back[ex][ey]))
       Back[ex][ey] = 0;
 
     if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
@@ -1906,6 +1906,8 @@ void Explode(int ex, int ey, int phase, int mode)
 
     for (y = ey - 1; y <= ey + 1; y++) for(x = ex - 1; x <= ex + 1; x++)
     {
+      int xx = x - ex + 1;
+      int yy = y - ey + 1;
       int element;
 
       if (!IN_LEV_FIELD(x, y) ||
@@ -1925,7 +1927,7 @@ void Explode(int ex, int ey, int phase, int mode)
 
 #if 1
 
-#if 1
+#if 0
       if (IS_EXPLOSION_PROOF(element))
        continue;
 #else
@@ -1956,11 +1958,11 @@ void Explode(int ex, int ey, int phase, int mode)
       }
 
       /* save walkable background elements while explosion on same tile */
-#if 1
+#if 0
       if (IS_INDESTRUCTIBLE(element))
        Back[x][y] = element;
 #else
-      if (IS_INDESTRUCTIBLE(element) && IS_WALKABLE(element))
+      if (IS_WALKABLE(element) && IS_INDESTRUCTIBLE(element))
        Back[x][y] = element;
 #endif
 
@@ -2016,11 +2018,10 @@ void Explode(int ex, int ey, int phase, int mode)
       else if (center_element == EL_AMOEBA_TO_DIAMOND)
        Store[x][y] = level.amoeba_content;
       else if (center_element == EL_YAMYAM)
-       Store[x][y] =
-         level.yamyam_content[game.yamyam_content_nr][x - ex + 1][y - ey + 1];
-      else if (IS_CUSTOM_ELEMENT(center_element))
-       Store[x][y] =
-         element_info[center_element].content[x - ex + 1][y - ey + 1];
+       Store[x][y] = level.yamyam_content[game.yamyam_content_nr][xx][yy];
+      else if (IS_CUSTOM_ELEMENT(center_element) &&
+              element_info[center_element].content[xx][yy] != EL_EMPTY)
+       Store[x][y] = element_info[center_element].content[xx][yy];
       else if (element == EL_WALL_EMERALD)
        Store[x][y] = EL_EMERALD;
       else if (element == EL_WALL_DIAMOND)
@@ -2037,6 +2038,8 @@ void Explode(int ex, int ey, int phase, int mode)
        Store[x][y] = EL_PEARL;
       else if (element == EL_WALL_CRYSTAL)
        Store[x][y] = EL_CRYSTAL;
+      else if (IS_CUSTOM_ELEMENT(element))
+       Store[x][y] = element_info[element].content[1][1];
       else
        Store[x][y] = EL_EMPTY;
 
@@ -2133,6 +2136,9 @@ void Explode(int ex, int ey, int phase, int mode)
       InitMovDir(x, y);
     DrawLevelField(x, y);
 
+    if (CAN_BE_CRUMBLED(element))
+      DrawLevelFieldCrumbledSandNeighbours(x, y);
+
     if (IS_PLAYER(x, y) && !PLAYERINFO(x,y)->present)
       StorePlayer[x][y] = 0;
   }
@@ -2692,7 +2698,7 @@ void Impact(int x, int y)
     return;
   }
 #if 1
-  else if (impact && CheckElementChange(x, y, element, ACTION_IMPACT))
+  else if (impact && CheckElementChange(x, y, element, CE_IMPACT))
   {
     PlaySoundLevelElementAction(x, y, element, ACTION_IMPACT);
 
@@ -3440,7 +3446,7 @@ void StartMoving(int x, int y)
   if (Stop[x][y])
     return;
 
-  /* !!! this should be handled more generic (not only for more) !!! */
+  /* !!! this should be handled more generic (not only for mole) !!! */
   if (element != EL_MOLE && GfxAction[x][y] != ACTION_DIGGING)
     GfxAction[x][y] = ACTION_DEFAULT;
 
@@ -3837,7 +3843,9 @@ void StartMoving(int x, int y)
        return;
       }
 
+#if 0
       GfxAction[x][y] = ACTION_MOVING;
+#endif
     }
 
     /* now make next step */
@@ -4050,7 +4058,8 @@ void StartMoving(int x, int y)
       TurnRound(x, y);
 
 #if 1
-      DrawLevelElementAnimation(x, y, element);
+      if (GFX_ELEMENT(element) != EL_SAND)
+       DrawLevelElementAnimation(x, y, element);
 #else
       if (element == EL_BUG ||
          element == EL_SPACESHIP ||
@@ -5223,8 +5232,10 @@ static void ChangeElementNow(int x, int y, int element)
 
     if (!change->only_complete || complete_change)
     {
+      boolean something_has_changed = FALSE;
+
       if (change->only_complete && change->use_random_change &&
-         RND(change->random) != 0)
+         RND(100) < change->random)
        return;
 
       for (yy = 0; yy < 3; yy++) for(xx = 0; xx < 3 ; xx++)
@@ -5233,24 +5244,31 @@ static void ChangeElementNow(int x, int y, int element)
        int ey = y + yy - 1;
 
        if (can_change[xx][yy] && (!change->use_random_change ||
-                                  RND(change->random) == 0))
+                                  RND(100) < change->random))
        {
          if (IS_MOVING(ex, ey) || IS_BLOCKED(ex, ey))
            RemoveMovingField(ex, ey);
 
          ChangeElementNowExt(ex, ey, change->content[xx][yy]);
 
+         something_has_changed = TRUE;
+
          /* for symmetry reasons, stop newly created border elements */
          if (ex != x || ey != y)
            Stop[ex][ey] = TRUE;
        }
       }
 
-      return;
+      if (something_has_changed)
+       PlaySoundLevelElementAction(x, y, element, ACTION_CHANGING);
     }
   }
+  else
+  {
+    ChangeElementNowExt(x, y, change->target_element);
 
-  ChangeElementNowExt(x, y, change->target_element);
+    PlaySoundLevelElementAction(x, y, element, ACTION_CHANGING);
+  }
 }
 
 static void ChangeElement(int x, int y)
@@ -5583,6 +5601,16 @@ void GameActions()
 
     GfxFrame[x][y]++;
 
+#if 1
+    /* reset finished pushing action (not done in ContinueMoving() to allow
+       continous pushing animation for elements without push delay) */
+    if (GfxAction[x][y] == ACTION_PUSHING && !IS_MOVING(x, y))
+    {
+      ResetGfxAnimation(x, y);
+      DrawLevelField(x, y);
+    }
+#endif
+
 #if DEBUG
     if (IS_BLOCKED(x, y))
     {
@@ -6339,7 +6367,9 @@ void ScrollFigure(struct PlayerInfo *player, int mode)
     if (Feld[last_jx][last_jy] == EL_EMPTY)
       Feld[last_jx][last_jy] = EL_PLAYER_IS_LEAVING;
 
+#if 0
     DrawPlayer(player);
+#endif
     return;
   }
   else if (!FrameReached(&player->actual_frame_counter, 1))
@@ -6355,7 +6385,9 @@ void ScrollFigure(struct PlayerInfo *player, int mode)
   if (player->MovPos == 0)
     CheckGravityMovement(player);
 
-  DrawPlayer(player);
+#if 0
+  DrawPlayer(player);  /* needed here only to cleanup last field */
+#endif
 
   if (player->MovPos == 0)
   {
@@ -6417,6 +6449,7 @@ void ScrollScreen(struct PlayerInfo *player, int mode)
 
 void TestIfPlayerTouchesCustomElement(int x, int y)
 {
+  static boolean check_changing = FALSE;
   static int xy[4][2] =
   {
     { 0, -1 },
@@ -6427,6 +6460,12 @@ void TestIfPlayerTouchesCustomElement(int x, int y)
   boolean center_is_player = (IS_PLAYER(x, y));
   int i;
 
+  /* prevent TestIfPlayerTouchesCustomElement() from looping */
+  if (check_changing)
+    return;
+
+  check_changing = TRUE;
+
   for (i=0; i<4; i++)
   {
     int xx = x + xy[i][0];
@@ -6448,10 +6487,13 @@ void TestIfPlayerTouchesCustomElement(int x, int y)
       break;
     }
   }
+
+  check_changing = FALSE;
 }
 
 void TestIfElementTouchesCustomElement(int x, int y)
 {
+  static boolean check_changing = FALSE;
   static int xy[4][2] =
   {
     { 0, -1 },
@@ -6462,6 +6504,12 @@ void TestIfElementTouchesCustomElement(int x, int y)
   boolean center_is_custom = (IS_CUSTOM_ELEMENT(Feld[x][y]));
   int i;
 
+  /* prevent TestIfElementTouchesCustomElement() from looping */
+  if (check_changing)
+    return;
+
+  check_changing = TRUE;
+
   for (i=0; i<4; i++)
   {
     int xx = x + xy[i][0];
@@ -6482,6 +6530,8 @@ void TestIfElementTouchesCustomElement(int x, int y)
       CheckElementChange(xx, yy, Feld[xx][yy], CE_OTHER_IS_TOUCHING);
     }
   }
+
+  check_changing = FALSE;
 }
 
 void TestIfGoodThingHitsBadThing(int good_x, int good_y, int good_move_dir)
@@ -7152,8 +7202,12 @@ int DigField(struct PlayerInfo *player,
 
        if (mode != DF_SNAP)
        {
+#if 1
+         GfxElement[x][y] = GFX_ELEMENT(element);
+#else
          GfxElement[x][y] =
            (CAN_BE_CRUMBLED(element) ? EL_SAND : GFX_ELEMENT(element));
+#endif
          player->is_digging = TRUE;
        }
 
@@ -7309,6 +7363,7 @@ int DigField(struct PlayerInfo *player,
          PlaySoundLevelElementAction(x, y, element, ACTION_PUSHING);
 
        InitMovingField(x, y, move_direction);
+       GfxAction[x][y] = ACTION_PUSHING;
 
        if (mode == DF_SNAP)
          ContinueMoving(x, y);
@@ -7867,6 +7922,8 @@ static void HandleGameButtons(struct GadgetInfo *gi)
       else if (audio.music_available)
       { 
        setup.sound = setup.sound_music = TRUE;
+
+       SetAudioMode(setup.sound);
        PlayMusic(level_nr);
       }
       break;
@@ -7875,14 +7932,20 @@ static void HandleGameButtons(struct GadgetInfo *gi)
       if (setup.sound_loops)
        setup.sound_loops = FALSE;
       else if (audio.loops_available)
+      {
        setup.sound = setup.sound_loops = TRUE;
+       SetAudioMode(setup.sound);
+      }
       break;
 
     case SOUND_CTRL_ID_SIMPLE:
       if (setup.sound_simple)
        setup.sound_simple = FALSE;
       else if (audio.sound_available)
+      {
        setup.sound = setup.sound_simple = TRUE;
+       SetAudioMode(setup.sound);
+      }
       break;
 
     default: