rnd-20040207-2-src
[rocksndiamonds.git] / src / game.c
index 0efc0328827c6ce3f65b309b3a1c92356c8ddea4..d304e76ee8b873daeb975bf330464948858afbba 100644 (file)
@@ -1385,6 +1385,7 @@ void InitGame()
       ChangeEvent[x][y] = CE_BITMASK_DEFAULT;
 
       ExplodePhase[x][y] = 0;
+      ExplodeDelay[x][y] = 0;
       ExplodeField[x][y] = EX_NO_EXPLOSION;
 
       RunnerVisit[x][y] = 0;
@@ -1419,6 +1420,30 @@ void InitGame()
                    emulate_sb ? EMU_SOKOBAN :
                    emulate_sp ? EMU_SUPAPLEX : EMU_NONE);
 
+  /* initialize explosion and ignition delay */
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+  {
+    if (!IS_CUSTOM_ELEMENT(i))
+    {
+      int num_phase = 9;
+      int delay = (game.emulation == EMU_SUPAPLEX ? 3 : 2);
+      int last_phase = num_phase * delay;
+      int half_phase = (num_phase / 2) * delay;
+
+      element_info[i].explosion_delay = last_phase;
+      element_info[i].ignition_delay = half_phase;
+
+      if (i == EL_BLACK_ORB)
+       element_info[i].ignition_delay = 1;
+    }
+
+    if (element_info[i].explosion_delay < 2)   /* !!! check again !!! */
+      element_info[i].explosion_delay = 2;
+
+    if (element_info[i].ignition_delay < 1)    /* !!! check again !!! */
+      element_info[i].ignition_delay = 1;
+  }
+
   /* correct non-moving belts to start moving left */
   for (i = 0; i < 4; i++)
     if (game.belt_dir[i] == MV_NO_MOVING)
@@ -2424,6 +2449,9 @@ void Explode(int ex, int ey, int phase, int mode)
   int last_phase = num_phase * delay;
   int half_phase = (num_phase / 2) * delay;
   int first_phase_after_start = EX_PHASE_START + 1;
+  int border_element;
+
+  int last_phase_TEST = last_phase;
 
   if (game.explosions_delayed)
   {
@@ -2458,6 +2486,10 @@ void Explode(int ex, int ey, int phase, int mode)
       Feld[ex][ey] = center_element;
     }
 
+#if 1
+    last_phase = element_info[center_element].explosion_delay;
+#endif
+
     for (y = ey - 1; y <= ey + 1; y++) for (x = ex - 1; x <= ex + 1; x++)
     {
       int xx = x - ex + 1;
@@ -2628,6 +2660,9 @@ void Explode(int ex, int ey, int phase, int mode)
 #endif
 
       ExplodePhase[x][y] = 1;
+#if 1
+      ExplodeDelay[x][y] = last_phase;
+#endif
       Stop[x][y] = TRUE;
     }
 
@@ -2644,6 +2679,10 @@ void Explode(int ex, int ey, int phase, int mode)
   x = ex;
   y = ey;
 
+#if 1
+  last_phase = ExplodeDelay[x][y];
+#endif
+
   ExplodePhase[x][y] = (phase < last_phase ? phase + 1 : 0);
 
 #ifdef DEBUG
@@ -2664,6 +2703,52 @@ void Explode(int ex, int ey, int phase, int mode)
   }
 #endif
 
+#if 1
+
+  border_element = Store2[x][y];
+  if (IS_PLAYER(x, y))
+    border_element = StorePlayer[x][y];
+
+  if (phase == element_info[border_element].ignition_delay ||
+      phase == last_phase)
+  {
+    boolean border_explosion = FALSE;
+
+    if (IS_PLAYER(x, y))
+    {
+      KillHeroUnlessExplosionProtected(x, y);
+      border_explosion = TRUE;
+
+      if (phase == last_phase)
+       printf("::: IS_PLAYER\n");
+    }
+    else if (CAN_EXPLODE_BY_FIRE(border_element))
+    {
+      Feld[x][y] = Store2[x][y];
+      Store2[x][y] = 0;
+      Bang(x, y);
+      border_explosion = TRUE;
+
+      if (phase == last_phase)
+       printf("::: CAN_EXPLODE_BY_FIRE\n");
+    }
+    else if (border_element == EL_AMOEBA_TO_DIAMOND)
+    {
+      AmoebeUmwandeln(x, y);
+      border_explosion = TRUE;
+
+      if (phase == last_phase)
+       printf("::: EL_AMOEBA_TO_DIAMOND\n");
+    }
+
+#if 0
+    if (border_explosion && phase == last_phase)
+      return;
+#endif
+  }
+
+#else
+
   if (phase == first_phase_after_start)
   {
     int element = Store2[x][y];
@@ -2690,6 +2775,7 @@ void Explode(int ex, int ey, int phase, int mode)
     else if (element == EL_AMOEBA_TO_DIAMOND)
       AmoebeUmwandeln(x, y);
   }
+#endif
 
   if (phase == last_phase)
   {
@@ -2738,7 +2824,11 @@ void Explode(int ex, int ey, int phase, int mode)
     if (ELEM_IS_PLAYER(element))
       RelocatePlayer(x, y, element);
   }
+#if 1
+  else if (IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+#else
   else if (phase >= delay && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
+#endif
   {
 #if 1
     int graphic = el_act2img(GfxElement[x][y], ACTION_EXPLODING);