rnd-20030128-1-src
[rocksndiamonds.git] / src / init.c
index 61838c68232306d4dda9e3da361cd8e0e9c774dc..14acc191bb0038c66c6e4784421cfe51d764b399 100644 (file)
@@ -57,28 +57,31 @@ static char *image_filename[NUM_PICTURES] =
 
 static Bitmap *bitmap_font_initial = NULL;
 
-static void InitGlobal(void);
-static void InitSetup(void);
-static void InitPlayerInfo(void);
-static void InitLevelInfo(void);
-static void InitArtworkInfo(void);
-static void InitLevelArtworkInfo(void);
-static void InitNetworkServer(void);
-static void InitArtworkConfig(void);
-static void InitImages(void);
-static void InitMixer(void);
-static void InitSound(void);
-static void InitMusic(void);
-static void InitGfx(void);
-static void InitGfxBackground(void);
-static void InitGadgets(void);
-static void InitElementProperties(void);
-static void InitElementInfo(void);
-static void InitGraphicInfo(void);
+static void InitGlobal();
+static void InitSetup();
+static void InitPlayerInfo();
+static void InitLevelInfo();
+static void InitArtworkInfo();
+static void InitLevelArtworkInfo();
+static void InitNetworkServer();
+static void InitArtworkConfig();
+static void InitImages();
+static void InitMixer();
+static void InitSound();
+static void InitMusic();
+static void InitGfx();
+static void InitGfxBackground();
+static void InitGadgets();
+static void InitElementImages();
+static void InitElementGraphicInfo();
+static void InitElementEditorGraphicInfo();
+static void InitElementSoundInfo();
+static void InitElementProperties();
+static void InitGraphicInfo();
 static void InitSoundInfo();
 static void Execute_Command(char *);
 
-void OpenAll(void)
+void OpenAll()
 {
   InitGlobal();                /* initialize some global variables */
 
@@ -119,7 +122,6 @@ void OpenAll(void)
   InitEventFilter(FilterMouseMotionEvents);
 
   InitElementProperties();
-  InitElementInfo();
 
   InitGfx();
 
@@ -188,6 +190,7 @@ static void InitArtworkConfig()
   static char *sound_class_prefix[MAX_NUM_ELEMENTS + 1];
   static char *action_suffix[NUM_ACTIONS + 1];
   static char *direction_suffix[NUM_DIRECTIONS + 1];
+  static char *special_suffix[NUM_SPECIAL_GFX_ARGS + 1];
   static char *dummy[1] = { NULL };
   int i;
 
@@ -199,11 +202,13 @@ static void InitArtworkConfig()
     action_suffix[i] = element_action_info[i].suffix;
   for (i=0; i<NUM_DIRECTIONS + 1; i++)
     direction_suffix[i] = element_direction_info[i].suffix;
+  for (i=0; i<NUM_SPECIAL_GFX_ARGS + 1; i++)
+    special_suffix[i] = special_suffix_info[i].suffix;
 
   InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
-               element_prefix, action_suffix, direction_suffix);
+               element_prefix, action_suffix,direction_suffix,special_suffix);
   InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
-               sound_class_prefix, action_suffix, dummy);
+               sound_class_prefix, action_suffix, dummy, dummy);
 }
 
 void InitLevelArtworkInfo()
@@ -242,7 +247,9 @@ static void InitMixer()
 
 static void ReinitializeGraphics()
 {
-  InitGraphicInfo();   /* initialize graphic info from config file */
+  InitElementGraphicInfo();            /* element => game graphic mapping */
+  InitElementEditorGraphicInfo();      /* element => editor graphic mapping */
+  InitGraphicInfo();                   /* graphic => properties mapping */
 
   InitFontInfo(bitmap_font_initial,
               graphic_info[IMG_FONT_BIG].bitmap,
@@ -255,13 +262,43 @@ static void ReinitializeGraphics()
 
   InitGadgets();
   InitToons();
+
+
+
+  /* !!! TEST ONLY !!! */
+  if (0)
+  {
+    Bitmap *tst_bitmap = graphic_info[IMG_SAND].bitmap;
+    Bitmap *tmp_bitmap = ZoomBitmap(tst_bitmap,
+                                   tst_bitmap->width / 2,
+                                   tst_bitmap->height / 2);
+
+    BlitBitmap(tmp_bitmap, tst_bitmap, 0, 0, 256, 224, 0, 448);
+
+    FreeBitmap(tmp_bitmap);
+  }
+
+  if (1)
+  {
+    printf("CREATING SMALL IMAGES...\n");
+
+#if 1
+    InitElementImages();
+#else
+    CreateImageWithSmallImages(IMG_SAND);
+    CreateImageWithSmallImages(IMG_SAND);
+#endif
+
+    printf("DONE!\n");
+  }
 }
 
 static void ReinitializeSounds()
 {
-  InitSoundInfo();     /* initialize sounds info from config file */
+  InitElementSoundInfo();      /* element => game sound mapping */
+  InitSoundInfo();             /* sound   => properties mapping */
 
-  InitPlaySoundLevel();
+  InitPlaySoundLevel();                /* internal game sound settings */
 }
 
 static void ReinitializeMusic()
@@ -273,6 +310,8 @@ static void InitImages()
 {
   ReloadCustomImages();
   ReinitializeGraphics();
+
+  LoadCustomElementDescriptions();
 }
 
 static void InitSound()
@@ -617,6 +656,8 @@ void ReloadCustomArtwork()
     ReloadCustomImages();
     ReinitializeGraphics();
 
+    LoadCustomElementDescriptions();
+
     FreeTileClipmasks();
     InitTileClipmasks();
 
@@ -698,8 +739,25 @@ void InitGadgets()
   gadgets_initialized = TRUE;
 }
 
-void InitElementInfo()
+void InitElementImages()
 {
+  struct PropertyMapping *property_mapping = getImageListPropertyMapping();
+  int num_property_mappings = getImageListPropertyMappingSize();
+  int i;
+
+  /* initialize images from static configuration */
+  for (i=0; element_to_graphic[i].element > -1; i++)
+    CreateImageWithSmallImages(element_to_graphic[i].graphic);
+
+  /* initialize images from dynamic configuration */
+  for (i=0; i < num_property_mappings; i++)
+    CreateImageWithSmallImages(property_mapping[i].artwork_index);
+}
+
+void InitElementGraphicInfo()
+{
+  struct PropertyMapping *property_mapping = getImageListPropertyMapping();
+  int num_property_mappings = getImageListPropertyMappingSize();
   int i, act, dir;
 
   /* set values to -1 to identify later as "uninitialized" values */
@@ -722,27 +780,42 @@ void InitElementInfo()
     element_info[i].graphic[ACTION_DEFAULT] =
       IMG_CUSTOM_START + (i - EL_CUSTOM_START);
 
-  i = 0;
-  while (element_to_graphic[i].element > -1)
+  /* initialize element/graphic mapping from static configuration */
+  for (i=0; element_to_graphic[i].element > -1; i++)
   {
     int element   = element_to_graphic[i].element;
-    int direction = element_to_graphic[i].direction;
     int action    = element_to_graphic[i].action;
+    int direction = element_to_graphic[i].direction;
     int graphic   = element_to_graphic[i].graphic;
 
     if (action < 0)
       action = ACTION_DEFAULT;
 
     if (direction > -1)
-    {
-      direction = MV_DIR_BIT(direction);
-
       element_info[element].direction_graphic[action][direction] = graphic;
-    }
     else
       element_info[element].graphic[action] = graphic;
+  }
+
+  /* initialize element/graphic mapping from dynamic configuration */
+  for (i=0; i < num_property_mappings; i++)
+  {
+    int element   = property_mapping[i].base_index;
+    int action    = property_mapping[i].ext1_index;
+    int direction = property_mapping[i].ext2_index;
+    int special   = property_mapping[i].ext3_index;
+    int graphic   = property_mapping[i].artwork_index;
+
+    if (special != -1)
+      continue;
+
+    if (action < 0)
+      action = ACTION_DEFAULT;
 
-    i++;
+    if (direction > -1)
+      element_info[element].direction_graphic[action][direction] = graphic;
+    else
+      element_info[element].graphic[action] = graphic;
   }
 
   /* now set all '-1' values to element specific default values */
@@ -785,6 +858,50 @@ void InitElementInfo()
   }
 }
 
+void InitElementEditorGraphicInfo()
+{
+  struct PropertyMapping *property_mapping = getImageListPropertyMapping();
+  int num_property_mappings = getImageListPropertyMappingSize();
+  int i;
+
+  /* always start with reliable default values */
+  for (i=0; i<MAX_NUM_ELEMENTS; i++)
+    element_info[i].editor_graphic = element_info[i].graphic[ACTION_DEFAULT];
+
+#if 0
+  /* initialize element/graphic mapping from static configuration */
+  for (i=0; ... ; i++)
+  {
+    int element   = ... element;
+    int special   = ... special;
+    int graphic   = ... graphic;
+
+    if (special != GFX_SPECIAL_ARG_EDITOR)
+      continue;
+
+    element_info[element].editor_graphic = graphic;
+  }
+#endif
+
+  /* initialize element/graphic mapping from dynamic configuration */
+  for (i=0; i < num_property_mappings; i++)
+  {
+    int element   = property_mapping[i].base_index;
+    int special   = property_mapping[i].ext3_index;
+    int graphic   = property_mapping[i].artwork_index;
+
+    if (special != GFX_SPECIAL_ARG_EDITOR)
+      continue;
+
+    element_info[element].editor_graphic = graphic;
+  }
+}
+
+static void InitElementSoundInfo()
+{
+  /* soon to come */
+}
+
 static void set_graphic_parameters(int graphic, int *parameter)
 {
   Bitmap *src_bitmap = getBitmapFromImageID(graphic);
@@ -1015,14 +1132,11 @@ static void InitSoundInfo()
     struct FileInfo *sound = getSoundListEntry(i);
     int len_effect_text = strlen(sound->token);
 
-#if 1
     sound_effect_properties[i] = ACTION_OTHER;
     sound_info[i].loop = FALSE;
-#endif
 
     /* determine all loop sounds and identify certain sound classes */
 
-#if 1
     for (j=0; element_action_info[j].suffix; j++)
     {
       int len_action_text = strlen(element_action_info[j].suffix);
@@ -1037,11 +1151,9 @@ static void InitSoundInfo()
          sound_info[i].loop = TRUE;
       }
     }
-#endif
 
     /* associate elements and some selected sound actions */
 
-#if 1
     for (j=0; j<MAX_NUM_ELEMENTS; j++)
     {
       if (element_info[j].sound_class_name)
@@ -1059,7 +1171,6 @@ static void InitSoundInfo()
        }
       }
     }
-#endif
 
     set_sound_parameters(i, sound->parameter);
   }