rnd-20100214-2-src
[rocksndiamonds.git] / src / game_sp / BugsTerminals.c
index 91b60de2a6279bc6fed8b8748f9520c41ecb5668..f12a1a0b64ce5da8fa6633afc9216235045f0e10 100644 (file)
@@ -12,7 +12,10 @@ long MyGetTickCount();
 
 byte *TerminalState;
 int TerminalMaxCycles;
+
+#if 0
 #define aniTerminal                    (0x80)
+#endif
 
 // ==========================================================================
 //                              SUBROUTINE
@@ -25,16 +28,33 @@ int subAnimateBugs(int si)
 
   // int ax, bx, cx, dx, di;
   // int ah, bh, ch, dh, al, bl, cl, dl;
-  int cx;
+  // int cx;
+  int graphic, sync_frame;
   int bl;
 
   if (fiBug != LowByte(PlayField16[si]))
     return subAnimateBugs;
 
+#if 0
   if (0 != (TimerVar & 3))
     return subAnimateBugs;
+#endif
 
   bl = SgnHighByte(PlayField16[si]); // get and increment sequence#
+
+#if 1
+  if ((TimerVar & 3) == 0)
+  {
+    bl = bl + 1;
+    if (bl >= 0xE)
+    {
+      bl = subGetRandomNumber(); // generate new random number
+      bl = -((bl & 0x3F) + 0x20);
+    }
+
+    MovHighByte(&PlayField16[si], bl); // save sequence#
+  }
+#else
   bl = bl + 1;
   if (bl >= 0xE)
   {
@@ -43,9 +63,15 @@ int subAnimateBugs(int si)
   }
 
   MovHighByte(&PlayField16[si], bl); // save sequence#
+#endif
   if (bl < 0) // bug sleeps / is inactive
     return subAnimateBugs;
 
+#if 1
+  if ((TimerVar & 3) != 0)
+    goto markDisplay;
+#endif
+
   // now the bug is active! Beware Murphy!
   if ((ByteMask && PlayField16[si - FieldWidth - 1]) == fiMurphy)
     goto markPlaySound;
@@ -78,8 +104,32 @@ markPlaySound:
 
 markDisplay:
   // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-  cx = aniBug[bl];
+#if 1
+
+#if 1
+
+  graphic = (bl == 0  ? aniBugActivating :
+            bl == 12 ? aniBugDeactivating :
+            bl == 13 ? aniBug : aniBugActive);
+  sync_frame = (bl >= 1 && bl <= 11 ? (bl - 1) * 4 : 0) + (TimerVar & 3);
+
+  // printf("::: %d [%d]\n", sync_frame, gfx.anim_random_frame);
+
+  /* a general random frame treatment would be needed for _all_ animations */
+  if (isRandomAnimation_SP(graphic) &&
+      !isNextAnimationFrame_SP(graphic, sync_frame))
+    return subAnimateBugs;
+
+  subCopyAnimToScreen(si, graphic, sync_frame);
+
+#else
+  subCopyFieldToScreen(si, aniFramesBug[bl]);
+#endif
+
+#else
+  cx = aniFramesBug[bl];
   StretchedSprites.BltEx(GetStretchX(si), GetStretchY(si), cx);
+#endif
   // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
   return subAnimateBugs;
@@ -95,27 +145,47 @@ int subAnimateTerminals(int si)
 
   // int bl, ax, al, X, Y;
 #if 1
-  short bl, al, X, Y;
+  short bl;
 #else
   int bl, al, X, Y;
 #endif
 
+#if 1
+  int lx = GetX(si);
+  int ly = GetY(si);
+  int graphic;
+#endif
+
   if (LowByte(PlayField16[si]) != fiTerminal)
     return subAnimateTerminals;
 
+  /* use native frame handling (undo frame incrementation in main loop) */
+  if (game.use_native_sp_graphics_engine)
+    GfxFrame[lx][ly]--;
+
+  /* get last random animation delay */
   bl = HighByte(PlayField16[si]);
   if ((bl & 0x80) == 0x80)
     bl = (bl | 0xFF00);
 
   bl = bl + 1;
-  if (bl <= 0)
+  if (bl <= 0)         /* return if random animation delay not yet reached */
   {
     MovHighByte(&PlayField16[si], bl);
+
+#if 1
+    if (game.use_native_sp_graphics_engine)
+      return subAnimateTerminals;
+#else
     return subAnimateTerminals;
+#endif
   }
 
+  /* calculate new random animation delay */
   bl = -(subGetRandomNumber() & TerminalMaxCycles); // generate new random number
   MovHighByte(&PlayField16[si], bl); // save new sequence#
+
+  /* check terminal state (active or inactive) */
   bl = TerminalState[si] + 1;
   if (bl == 8)
   {
@@ -127,16 +197,35 @@ int subAnimateTerminals(int si)
   }
 
   TerminalState[si] = bl;
+
   // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-  al = aniTerminal + bl;
+#if 1
+
+  graphic = (bl < 8 ? aniTerminal : aniTerminalActive);
+
+  if (game.use_native_sp_graphics_engine)
+    GfxFrame[lx][ly] += getGraphicInfo_Delay(graphic);
+
+#if 1
+  subCopyAnimToScreen(si, graphic, GfxFrame[lx][ly]);
+#else
   X = GetStretchX(si);
   Y = GetStretchY(si);
+  StretchedSprites.BltImg(X, Y, graphic, GfxFrame[lx][ly]);
+#endif
+
+#else
+
+  al = aniTerminal + bl;
+
 #if 1
-  StretchedSprites.BltImg(X, Y,
-                         bl < 8 ? IMG_SP_TERMINAL : IMG_SP_TERMINAL_ACTIVE,
-                         FrameCounter);
+  subCopyFieldToScreen(si, al);
 #else
+  X = GetStretchX(si);
+  Y = GetStretchY(si);
   StretchedSprites.BltEx(X, Y, al);
+#endif
+
 #endif
   // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++