rnd-20030916-1-src
[rocksndiamonds.git] / src / game.c
index 91694d2d7ea0e2ab2fd617081c89a046c14e5105..f571fd1f62e9455751e79c1c80ad204f6f1f8ff8 100644 (file)
@@ -241,6 +241,14 @@ static struct ChangingElementInfo change_delay_list[] =
     NULL,
     NULL
   },
+  {
+    EL_EXIT_CLOSING,
+    EL_EXIT_CLOSED,
+    29,
+    NULL,
+    NULL,
+    NULL
+  },
   {
     EL_SWITCHGATE_OPENING,
     EL_SWITCHGATE_OPEN,
@@ -1646,6 +1654,14 @@ void GameWon()
       StopSound(SND_GAME_LEVELTIME_BONUS);
   }
 
+  /* close exit door after last player */
+  if (Feld[ExitX][ExitY] == EL_EXIT_OPEN && AllPlayersGone)
+  {
+    Feld[ExitX][ExitY] = EL_EXIT_CLOSING;
+
+    PlaySoundLevelElementAction(ExitX, ExitY, EL_EXIT_OPEN, ACTION_CLOSING);
+  }
+
   /* Hero disappears */
   DrawLevelField(ExitX, ExitY);
   BackToFront();
@@ -2285,6 +2301,24 @@ void Explode(int ex, int ey, int phase, int mode)
 
   ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
 
+#ifdef DEBUG
+
+  /* activate this even in non-DEBUG version until cause for crash in
+     getGraphicAnimationFrame() (see below) is found and eliminated */
+#endif
+#if 1
+
+  if (GfxElement[x][y] == EL_UNDEFINED)
+  {
+    printf("\n\n\n");
+    printf("Explode(): x = %d, y = %d: GfxElement == EL_UNDEFINED\n", x, y);
+    printf("Explode(): This should never happen!\n");
+    printf("\n\n\n");
+
+    GfxElement[x][y] = EL_EMPTY;
+  }
+#endif
+
   if (phase == first_phase_after_start)
   {
     int element = Store2[x][y];
@@ -4973,6 +5007,9 @@ void CheckExit(int x, int y)
     return;
   }
 
+  if (AllPlayersGone)  /* do not re-open exit door closed after last player */
+    return;
+
   Feld[x][y] = EL_EXIT_OPENING;
 
   PlaySoundLevelNearest(x, y, SND_CLASS_EXIT_OPENING);
@@ -5364,10 +5401,13 @@ static void ChangeElementNowExt(int x, int y, int target_element)
     RelocatePlayer(x, y, target_element);
 }
 
-static void ChangeElementNow(int x, int y, int element, int page)
+static boolean ChangeElementNow(int x, int y, int element, int page)
 {
   struct ElementChangeInfo *change = &element_info[element].change_page[page];
 
+  if (Changed[x][y])           /* do not change already changed elements */
+    return FALSE;
+
   Changed[x][y] = TRUE;                /* no more changes in this frame */
 
   CheckTriggeredElementChange(x, y, Feld[x][y], CE_OTHER_IS_CHANGING);
@@ -5375,7 +5415,8 @@ static void ChangeElementNow(int x, int y, int element, int page)
   if (change->explode)
   {
     Bang(x, y);
-    return;
+
+    return TRUE;
   }
 
   if (change->use_content)
@@ -5433,7 +5474,7 @@ static void ChangeElementNow(int x, int y, int element, int page)
 
       if (change->only_complete && change->use_random_change &&
          RND(100) < change->random)
-       return;
+       return FALSE;
 
       for (yy = 0; yy < 3; yy++) for(xx = 0; xx < 3 ; xx++)
       {
@@ -5466,6 +5507,8 @@ static void ChangeElementNow(int x, int y, int element, int page)
 
     PlaySoundLevelElementAction(x, y, element, ACTION_CHANGING);
   }
+
+  return TRUE;
 }
 
 static void ChangeElement(int x, int y, int page)
@@ -5506,10 +5549,11 @@ static void ChangeElement(int x, int y, int page)
       return;
     }
 
-    ChangeElementNow(x, y, element, page);
-
-    if (change->post_change_function)
-      change->post_change_function(x, y);
+    if (ChangeElementNow(x, y, element, page))
+    {
+      if (change->post_change_function)
+       change->post_change_function(x, y);
+    }
   }
 }
 
@@ -5566,8 +5610,10 @@ static boolean CheckTriggeredElementChange(int lx, int ly, int trigger_element,
       if (x == lx && y == ly)  /* do not change trigger element itself */
        continue;
 
+#if 0
       if (Changed[x][y])       /* do not change already changed elements */
        continue;
+#endif
 
       if (Feld[x][y] == element)
       {