rnd-20030118-5-src
[rocksndiamonds.git] / src / init.c
index b720f5764cc04d3933085ad76a98ca0ebf413a97..203d4093d6632e9182fae2af9042c8c2ff26e9ae 100644 (file)
@@ -692,21 +692,21 @@ void InitElementInfo()
   /* set values to -1 to identify later as "uninitialized" values */
   for (i=0; i<MAX_NUM_ELEMENTS; i++)
   {
-    for (act=0; act<NUM_GFX_ACTIONS; act++)
+    for (act=0; act<NUM_ACTIONS; act++)
     {
       element_info[i].graphic[act] = -1;
 
-      for (dir=0; dir<NUM_MV_DIRECTIONS; dir++)
+      for (dir=0; dir<NUM_DIRECTIONS; dir++)
        element_info[i].direction_graphic[act][dir] = -1;
     }
   }
 
   for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
-    element_info[i].graphic[GFX_ACTION_DEFAULT] =
+    element_info[i].graphic[ACTION_DEFAULT] =
       IMG_CHAR_START + (i - EL_CHAR_START);
 
   for (i=EL_CUSTOM_START; i<=EL_CUSTOM_END; i++)
-    element_info[i].graphic[GFX_ACTION_DEFAULT] =
+    element_info[i].graphic[ACTION_DEFAULT] =
       IMG_CUSTOM_START + (i - EL_CUSTOM_START);
 
   i = 0;
@@ -718,7 +718,7 @@ void InitElementInfo()
     int graphic   = element_to_graphic[i].graphic;
 
     if (action < 0)
-      action = GFX_ACTION_DEFAULT;
+      action = ACTION_DEFAULT;
 
     if (direction > -1)
     {
@@ -735,24 +735,24 @@ void InitElementInfo()
   /* now set all '-1' values to element specific default values */
   for (i=0; i<MAX_NUM_ELEMENTS; i++)
   {
-    int default_action_graphic = element_info[i].graphic[GFX_ACTION_DEFAULT];
-    int default_action_direction_graphic[NUM_MV_DIRECTIONS];
+    int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
+    int default_action_direction_graphic[NUM_DIRECTIONS];
 
     if (default_action_graphic == -1)
       default_action_graphic = IMG_CHAR_QUESTION;
 
-    for (dir=0; dir<NUM_MV_DIRECTIONS; dir++)
+    for (dir=0; dir<NUM_DIRECTIONS; dir++)
     {
       default_action_direction_graphic[dir] =
-       element_info[i].direction_graphic[GFX_ACTION_DEFAULT][dir];
+       element_info[i].direction_graphic[ACTION_DEFAULT][dir];
 
       if (default_action_direction_graphic[dir] == -1)
        default_action_direction_graphic[dir] = default_action_graphic;
     }
 
-    for (act=0; act<NUM_GFX_ACTIONS; act++)
+    for (act=0; act<NUM_ACTIONS; act++)
     {
-      for (dir=0; dir<NUM_MV_DIRECTIONS; dir++)
+      for (dir=0; dir<NUM_DIRECTIONS; dir++)
       {
        int default_direction_graphic = element_info[i].graphic[act];
 
@@ -790,7 +790,7 @@ static void InitGraphicInfo()
 
   /* set temporary graphics action field to default value */
   for (i=0; i<NUM_IMAGE_FILES; i++)
-    gfx_action[i] = GFX_ACTION_DEFAULT;
+    gfx_action[i] = ACTION_DEFAULT;
 
   /* set temporary graphics action field from element_to_graphic list */
   i = 0;
@@ -800,7 +800,7 @@ static void InitGraphicInfo()
     int graphic   = element_to_graphic[i].graphic;
 
     if (action == -1)
-      action = GFX_ACTION_DEFAULT;
+      action = ACTION_DEFAULT;
 
     gfx_action[graphic] = action;
 
@@ -900,7 +900,7 @@ static void InitGraphicInfo()
     /* set global_sync for all animations with undefined "animation action" */
     if (parameter[GFX_ARG_GLOBAL_SYNC] == GFX_ARG_UNDEFINED_VALUE)
       graphic_info[i].anim_global_sync =
-       (gfx_action[i] == GFX_ACTION_DEFAULT ? TRUE : FALSE);
+       (gfx_action[i] == ACTION_DEFAULT ? TRUE : FALSE);
 
     /* "linear" animations are never globally synchronized */
     if (parameter[GFX_ARG_MODE_LINEAR])
@@ -982,10 +982,78 @@ static void InitGraphicInfo()
 
 static void InitSoundInfo()
 {
+  int sound_effect_properties[NUM_SOUND_FILES];
+  int i, j;
+
   sound_files = getCurrentSoundList();
 
-  /* initialize sound effect lookup table for element actions */
-  InitGameSound();
+  /* initialize sound effect for all elements to "no sound" */
+  for (i=0; i<MAX_NUM_ELEMENTS; i++)
+    for (j=0; j<NUM_ACTIONS; j++)
+      element_info[i].sound[j] = SND_UNDEFINED;
+
+  for (i=0; i<NUM_SOUND_FILES; i++)
+  {
+    int len_effect_text = strlen(sound_files[i].token);
+
+    sound_effect_properties[i] = ACTION_OTHER;
+    sound_info[i].loop = FALSE;
+
+    /* determine all loop sounds and identify certain sound classes */
+
+    for (j=0; sound_action_properties[j].text; j++)
+    {
+      int len_action_text = strlen(sound_action_properties[j].text);
+
+      if (len_action_text < len_effect_text &&
+         strcmp(&sound_files[i].token[len_effect_text - len_action_text],
+                sound_action_properties[j].text) == 0)
+      {
+       sound_effect_properties[i] = sound_action_properties[j].value;
+
+       if (sound_action_properties[j].is_loop)
+         sound_info[i].loop = TRUE;
+      }
+    }
+
+    /* associate elements and some selected sound actions */
+
+    for (j=0; j<MAX_NUM_ELEMENTS; j++)
+    {
+      if (element_info[j].sound_class_name)
+      {
+       int len_class_text = strlen(element_info[j].sound_class_name);
+
+       if (len_class_text + 1 < len_effect_text &&
+           strncmp(sound_files[i].token,
+                   element_info[j].sound_class_name, len_class_text) == 0 &&
+           sound_files[i].token[len_class_text] == '.')
+       {
+         int sound_action_value = sound_effect_properties[i];
+
+         element_info[j].sound[sound_action_value] = i;
+       }
+      }
+    }
+  }
+
+#if 0
+  /* TEST ONLY */
+  {
+    int element = EL_SAND;
+    int sound_action = ACTION_DIGGING;
+    int j = 0;
+
+    while (sound_action_properties[j].text)
+    {
+      if (sound_action_properties[j].value == sound_action)
+       printf("element %d, sound action '%s'  == %d\n",
+              element, sound_action_properties[j].text,
+              element_info_[element].sound[sound_action]);
+      j++;
+    }
+  }
+#endif
 }
 
 void InitElementProperties()