rnd-20030126-1-src
[rocksndiamonds.git] / src / tools.c
index c61cc5a3494c69c51db38a00ce6483fb0234079c..9f42b57dc2b327852133807a0ce230e2c4b77f06 100644 (file)
@@ -455,6 +455,11 @@ static int getGraphicAnimationPhase(int frames, int delay, int mode)
   return phase;
 }
 
+void SetRandomAnimationValue(int x, int y)
+{
+  anim.random_frame = GfxRandom[x][y];
+}
+
 inline int getGraphicAnimationFrame(int graphic, int sync_frame)
 {
   /* animation synchronized with global frame counter, not move position */
@@ -479,26 +484,31 @@ inline void DrawGraphicAnimationExt(DrawBuffer *dst_bitmap, int x, int y,
     DrawGraphicExt(dst_bitmap, x, y, graphic, frame);
 }
 
-inline boolean checkDrawGraphicAnimation(int x, int y, int graphic)
+inline boolean checkDrawGraphicAnimation(int sx, int sy, int graphic)
 {
-  int lx = LEVELX(x), ly = LEVELY(y);
+  int lx = LEVELX(sx), ly = LEVELY(sy);
 
-  return (IN_SCR_FIELD(x, y) &&
-         GfxFrame[lx][ly] % graphic_info[graphic].anim_delay == 0);
+  return (IN_SCR_FIELD(sx, sy) && IS_NEW_FRAME(GfxFrame[lx][ly], graphic));
 }
 
-inline boolean checkDrawLevelGraphicAnimation(int x, int y, int graphic)
+inline boolean checkDrawLevelGraphicAnimation(int lx, int ly, int graphic)
 {
-  return (IN_SCR_FIELD(SCREENX(x), SCREENY(y)) &&
-         GfxFrame[x][y] % graphic_info[graphic].anim_delay == 0);
+  int sx = SCREENX(lx), sy = SCREENY(ly);
+
+  return (IN_SCR_FIELD(sx, sy) && IS_NEW_FRAME(GfxFrame[lx][ly], graphic));
 }
 
 inline boolean DrawGraphicAnimation(int x, int y, int graphic)
 {
   int lx = LEVELX(x), ly = LEVELY(y);
 
+#if 0
   if (!checkDrawGraphicAnimation(x, y, graphic))
     return FALSE;
+#else
+  if (!IN_SCR_FIELD(x, y))
+    return FALSE;
+#endif
 
   DrawGraphicAnimationExt(drawto_field, FX + x * TILEX, FY + y * TILEY,
                          graphic, GfxFrame[lx][ly], NO_MASKING);
@@ -517,6 +527,19 @@ boolean DrawLevelElementAnimation(int x, int y, int element)
   return DrawGraphicAnimation(SCREENX(x), SCREENY(y), el2img(element));
 }
 
+inline void ContinueLevelGraphicAnimation(int x, int y, int graphic)
+{
+  if (!IS_NEW_FRAME(GfxFrame[x][y], graphic))
+    return;
+
+  DrawGraphicAnimation(SCREENX(x), SCREENY(y), graphic);
+}
+
+void ContinueLevelElementAnimation(int x, int y, int element)
+{
+  ContinueLevelGraphicAnimation(x, y, el2img(element));
+}
+
 void DrawAllPlayers()
 {
   int i;
@@ -626,37 +649,37 @@ void DrawPlayer(struct PlayerInfo *player)
     if (player->Pushing)
     {
       if (player->MovDir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_LEFT_PUSHING;
+       graphic = IMG_SP_MURPHY_PUSHING_LEFT;
       else if (player->MovDir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_RIGHT_PUSHING;
+       graphic = IMG_SP_MURPHY_PUSHING_RIGHT;
       else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_LEFT_PUSHING;
+       graphic = IMG_SP_MURPHY_PUSHING_LEFT;
       else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_RIGHT_PUSHING;
+       graphic = IMG_SP_MURPHY_PUSHING_RIGHT;
     }
     else if (player->snapped)
     {
       if (player->MovDir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_LEFT_SNAPPING;
+       graphic = IMG_SP_MURPHY_SNAPPING_LEFT;
       else if (player->MovDir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_RIGHT_SNAPPING;
+       graphic = IMG_SP_MURPHY_SNAPPING_RIGHT;
       else if (player->MovDir == MV_UP)
-       graphic = IMG_SP_MURPHY_UP_SNAPPING;
+       graphic = IMG_SP_MURPHY_SNAPPING_UP;
       else if (player->MovDir == MV_DOWN)
-       graphic = IMG_SP_MURPHY_DOWN_SNAPPING;
+       graphic = IMG_SP_MURPHY_SNAPPING_DOWN;
     }
     else if (action_moving)
     {
       if (player->MovDir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_LEFT_MOVING;
+       graphic = IMG_SP_MURPHY_MOVING_LEFT;
       else if (player->MovDir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_RIGHT_MOVING;
+       graphic = IMG_SP_MURPHY_MOVING_RIGHT;
       else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_LEFT)
-       graphic = IMG_SP_MURPHY_LEFT_MOVING;
+       graphic = IMG_SP_MURPHY_MOVING_LEFT;
       else if (player->MovDir & (MV_UP | MV_DOWN) && last_dir == MV_RIGHT)
-       graphic = IMG_SP_MURPHY_RIGHT_MOVING;
+       graphic = IMG_SP_MURPHY_MOVING_RIGHT;
       else
-       graphic = IMG_SP_MURPHY_LEFT_MOVING;
+       graphic = IMG_SP_MURPHY_MOVING_LEFT;
 
       frame = getGraphicAnimationFrame(graphic, -1);
     }
@@ -667,20 +690,20 @@ void DrawPlayer(struct PlayerInfo *player)
   else
   {
     if (player->MovDir == MV_LEFT)
-      graphic = (player->Pushing ? IMG_PLAYER1_LEFT_PUSHING :
-                player->is_moving ? IMG_PLAYER1_LEFT_MOVING :
+      graphic = (player->Pushing ? IMG_PLAYER1_PUSHING_LEFT :
+                player->is_moving ? IMG_PLAYER1_MOVING_LEFT :
                 IMG_PLAYER1_LEFT);
     else if (player->MovDir == MV_RIGHT)
-      graphic = (player->Pushing ? IMG_PLAYER1_RIGHT_PUSHING :
-                player->is_moving ? IMG_PLAYER1_RIGHT_MOVING :
+      graphic = (player->Pushing ? IMG_PLAYER1_PUSHING_RIGHT :
+                player->is_moving ? IMG_PLAYER1_MOVING_RIGHT :
                 IMG_PLAYER1_RIGHT);
     else if (player->MovDir == MV_UP)
-      graphic = (player->Pushing ? IMG_PLAYER1_UP_PUSHING :
-                player->is_moving ? IMG_PLAYER1_UP_MOVING :
+      graphic = (player->Pushing ? IMG_PLAYER1_PUSHING_UP :
+                player->is_moving ? IMG_PLAYER1_MOVING_UP :
                 IMG_PLAYER1_UP);
     else       /* MV_DOWN || MV_NO_MOVING */
-      graphic = (player->Pushing ? IMG_PLAYER1_DOWN_PUSHING :
-                player->is_moving ? IMG_PLAYER1_DOWN_MOVING :
+      graphic = (player->Pushing ? IMG_PLAYER1_PUSHING_DOWN :
+                player->is_moving ? IMG_PLAYER1_MOVING_DOWN :
                 IMG_PLAYER1_DOWN);
 
     graphic = PLAYER_NR_GFX(graphic, player->index_nr);
@@ -742,7 +765,7 @@ void DrawPlayer(struct PlayerInfo *player)
 
       if ((sxx || syy) && IS_PUSHABLE(element))
       {
-       graphic = el_dir_act2img(element, player->MovDir, GFX_ACTION_MOVING);
+       graphic = el_dir_act2img(element, player->MovDir, ACTION_MOVING);
 #if 1
        frame = getGraphicAnimationFrame(graphic, player->GfxPos);
 
@@ -1140,13 +1163,13 @@ inline static int getFramePosition(int x, int y)
 
 inline static int getGfxAction(int x, int y)
 {
-  int gfx_action = GFX_ACTION_DEFAULT;
+  int gfx_action = ACTION_DEFAULT;
 
 #if 0
-  if (GfxAction[x][y] != GFX_ACTION_DEFAULT)
+  if (GfxAction[x][y] != ACTION_DEFAULT)
     gfx_action = GfxAction[x][y];
   else if (IS_MOVING(x, y))
-    gfx_action = GFX_ACTION_MOVING;
+    gfx_action = ACTION_MOVING;
 #else
   gfx_action = GfxAction[x][y];
 #endif
@@ -1173,6 +1196,8 @@ void DrawScreenElementExt(int x, int y, int dx, int dy, int element,
     int move_pos = getFramePosition(ux, uy);
     int gfx_action = getGfxAction(ux, uy);
 
+    SetRandomAnimationValue(ux, uy);
+
     graphic = el_dir_act2img(element, move_dir, gfx_action);
     frame = getGraphicAnimationFrame(graphic, move_pos);
   }
@@ -2480,7 +2505,7 @@ int get_next_element(int element)
 
 int el2img(int element)
 {
-  int graphic = element_info[element].graphic[GFX_ACTION_DEFAULT];
+  int graphic = element_info[element].graphic[ACTION_DEFAULT];
 
 #if DEBUG
   if (graphic < 0)
@@ -2493,7 +2518,7 @@ int el2img(int element)
 
 int el_dir2img(int element, int direction)
 {
-  return el_dir_act2img(element, direction, GFX_ACTION_DEFAULT);
+  return el_dir_act2img(element, direction, ACTION_DEFAULT);
 }
 
 int el_dir_act2img(int element, int direction, int action)