rnd-20070310-2-src
[rocksndiamonds.git] / src / tools.c
index 62965af09d2df0e90ce0f15107f6e4c2d9453fe6..3f9b7f26bdc436ee1e899dd8020eb7b3e67f5b62 100644 (file)
@@ -5725,10 +5725,94 @@ unsigned int InitRND(long seed)
     return InitEngineRandom_RND(seed);
 }
 
+#if 1
+static struct Mapping_EM_to_RND_object object_mapping[TILE_MAX];
+static struct Mapping_EM_to_RND_player player_mapping[MAX_PLAYERS][SPR_MAX];
+#endif
+
+void ResetGfxAnimation_EM(int x, int y, int tile)
+{
+  GfxFrame[x][y] = 0;
+}
+
+void getGraphicSourceObjectExt_EM(int tile, int frame_em,
+                                 Bitmap **src_bitmap, int *src_x, int *src_y,
+                                 int x, int y)
+{
+  int element         = object_mapping[tile].element_rnd;
+  int action          = object_mapping[tile].action;
+  int direction       = object_mapping[tile].direction;
+  boolean is_backside = object_mapping[tile].is_backside;
+  boolean action_removing = (action == ACTION_DIGGING ||
+                            action == ACTION_SNAPPING ||
+                            action == ACTION_COLLECTING);
+  int effective_element = (frame_em > 0 ? element :
+                          is_backside ? EL_EMPTY :
+                          action_removing ? EL_EMPTY :
+                          element);
+  int graphic = (direction == MV_NONE ?
+                el_act2img(effective_element, action) :
+                el_act_dir2img(effective_element, action, direction));
+  struct GraphicInfo *g = &graphic_info[graphic];
+  int sync_frame;
+
+  if (graphic_info[graphic].anim_global_sync)
+    sync_frame = FrameCounter;
+  else
+    sync_frame = 7 - frame_em;
+
+  SetRandomAnimationValue(x, y);
+
+  int frame = getAnimationFrame(g->anim_frames,
+                               g->anim_delay,
+                               g->anim_mode,
+                               g->anim_start_frame,
+                               sync_frame);
+
+  getGraphicSourceExt(graphic, frame, src_bitmap, src_x, src_y, FALSE);
+}
+
+void getGraphicSourcePlayerExt_EM(int player_nr, int anim, int frame_em,
+                                 Bitmap **src_bitmap, int *src_x, int *src_y)
+{
+  int element   = player_mapping[player_nr][anim].element_rnd;
+  int action    = player_mapping[player_nr][anim].action;
+  int direction = player_mapping[player_nr][anim].direction;
+  int graphic = (direction == MV_NONE ?
+                el_act2img(element, action) :
+                el_act_dir2img(element, action, direction));
+  struct GraphicInfo *g = &graphic_info[graphic];
+  int sync_frame;
+
+  InitPlayerGfxAnimation(&stored_player[player_nr], action, direction);
+
+  stored_player[player_nr].StepFrame = 7 - frame_em;
+
+  sync_frame = stored_player[player_nr].Frame;
+
+#if 0
+  printf("::: %d: %d, %d [%d]\n",
+        player_nr,
+        stored_player[player_nr].Frame,
+        stored_player[player_nr].StepFrame,
+        FrameCounter);
+#endif
+
+  int frame = getAnimationFrame(g->anim_frames,
+                               g->anim_delay,
+                               g->anim_mode,
+                               g->anim_start_frame,
+                               sync_frame);
+
+  getGraphicSourceExt(graphic, frame, src_bitmap, src_x, src_y, FALSE);
+}
+
 void InitGraphicInfo_EM(void)
 {
+#if 0
   struct Mapping_EM_to_RND_object object_mapping[TILE_MAX];
   struct Mapping_EM_to_RND_player player_mapping[MAX_PLAYERS][SPR_MAX];
+#endif
   int i, j, p;
 
 #if DEBUG_EM_GFX
@@ -6275,7 +6359,7 @@ void InitGraphicInfo_EM(void)
                                      g->anim_start_frame,
                                      sync_frame);
 
-       getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x,&src_y, FALSE);
+       getGraphicSourceExt(graphic, frame, &src_bitmap, &src_x, &src_y, FALSE);
 
        g_em->bitmap = src_bitmap;
        g_em->src_x = src_x;