rnd-20020914-1-src
[rocksndiamonds.git] / src / init.c
index 8f957e30837f16165db67f41dee238b7f5fcc3ca..9b553f1e419672c5990263cd805a235cb1ba70cf 100644 (file)
 static char *image_filename[NUM_PICTURES] =
 {
   "RocksScreen.pcx",
+  "RocksElements.pcx",
   "RocksDoor.pcx",
   "RocksHeroes.pcx",
   "RocksToons.pcx",
   "RocksSP.pcx",
   "RocksDC.pcx",
   "RocksMore.pcx",
-  "RocksFont.pcx",
-  "RocksFont2.pcx",
-  "RocksFont3.pcx"
+  "RocksFontBig.pcx",
+  "RocksFontSmall.pcx",
+  "RocksFontMedium.pcx",
+  "RocksFontEM.pcx"
 }; 
 
 static void InitSetup(void);
@@ -55,6 +57,7 @@ static void InitGadgets(void);
 static void InitElementProperties(void);
 static void InitElementInfo(void);
 static void InitGraphicInfo(void);
+static void InitSoundInfo();
 static void Execute_Debug_Command(char *);
 
 void OpenAll(void)
@@ -100,7 +103,6 @@ void OpenAll(void)
   InitGfx();
   InitElementProperties();     /* initializes IS_CHAR() for el2gfx() */
   InitElementInfo();
-  InitGraphicInfo();
 
   InitLevelInfo();
   InitLevelArtworkInfo();
@@ -176,16 +178,19 @@ void InitNetworkServer()
 
 static void InitImages()
 {
-  InitImageList(image_config, NUM_IMAGE_CONFIG_ENTRIES);
+  InitImageList(image_config, image_config_suffix, NUM_IMAGE_FILES);
 
   /* load custom images */
   ReloadCustomImages();
+
+  InitGraphicInfo();
 }
 
 static void InitMixer()
 {
   OpenAudio();
-  InitSoundList(sound_config, NUM_SOUND_CONFIG_ENTRIES);
+
+  InitSoundList(sound_config, sound_config_suffix, NUM_SOUND_FILES);
 
   StartMixer();
 }
@@ -196,8 +201,7 @@ static void InitSound()
   InitReloadSounds(artwork.snd_current->identifier);
   InitReloadMusic(artwork.mus_current->identifier);
 
-  /* initialize sound effect lookup table for element actions */
-  InitGameSound();
+  InitSoundInfo();
 }
 
 static void InitTileClipmasks()
@@ -379,9 +383,9 @@ void InitGfx()
   pix[PIX_DB_DOOR] = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
   pix[PIX_DB_FIELD] = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
 
-  pix[PIX_SMALLFONT] = LoadCustomImage(image_filename[PIX_SMALLFONT]);
+  pix[PIX_FONT_SMALL] = LoadCustomImage(image_filename[PIX_FONT_SMALL]);
 
-  InitFontInfo(NULL, NULL, pix[PIX_SMALLFONT]);
+  InitFontInfo(NULL, NULL, pix[PIX_FONT_SMALL], NULL);
 
   DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
   DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
@@ -390,7 +394,7 @@ void InitGfx()
 
   for(i=0; i<NUM_PICTURES; i++)
   {
-    if (i != PIX_SMALLFONT)
+    if (i != PIX_FONT_SMALL)
     {
       DrawInitText(image_filename[i], 150, FC_YELLOW);
 
@@ -398,7 +402,8 @@ void InitGfx()
     }
   }
 
-  InitFontInfo(pix[PIX_BIGFONT], pix[PIX_MEDIUMFONT], pix[PIX_SMALLFONT]);
+  InitFontInfo(pix[PIX_FONT_BIG], pix[PIX_FONT_MEDIUM], pix[PIX_FONT_SMALL],
+              pix[PIX_FONT_EM]);
 
   InitTileClipmasks();
 }
@@ -497,6 +502,7 @@ void ReloadCustomArtwork()
     }
 
     ReloadCustomImages();
+    InitGraphicInfo();
 
     FreeTileClipmasks();
     InitTileClipmasks();
@@ -848,24 +854,68 @@ void InitElementInfo()
   }
 }
 
-void InitGraphicInfo()
+static void InitGraphicInfo()
 {
   int i;
 
-  /* always start with reliable default values */
+  image_files = getCurrentImageList();
+
   for(i=0; i<MAX_GRAPHICS; i++)
   {
-    graphic_info[i].bitmap = pix[PIX_SP];      /* graphic that ... */
-    graphic_info[i].src_x = 0;                 /* ... contains ... */
-    graphic_info[i].src_y = 0;                 /* ... empty space. */
-    graphic_info[i].anim_frames = 1;
-    graphic_info[i].anim_delay = 0;
-    graphic_info[i].anim_mode = ANIM_NORMAL;
-  }
+    /* always start with reliable default values */
+    graphic_info[i].bitmap = NULL;
+    graphic_info[i].src_x = 0;
+    graphic_info[i].src_y = 0;
 
-  for(i=0; i<MAX_GRAPHICS; i++)
     getGraphicSource(i, &graphic_info[i].bitmap,
                     &graphic_info[i].src_x, &graphic_info[i].src_y);
+  }
+
+  for(i=0; i<NUM_IMAGE_FILES; i++)
+  {
+    int *parameter = image_files[i].parameter;
+
+    /* always start with reliable default values */
+    new_graphic_info[i].bitmap = getBitmapFromImageID(i);
+    new_graphic_info[i].src_x = parameter[GFXARG_XPOS] * TILEX;
+    new_graphic_info[i].src_y = parameter[GFXARG_YPOS] * TILEY;
+    new_graphic_info[i].anim_frames = parameter[GFXARG_FRAMES];
+    new_graphic_info[i].anim_delay = parameter[GFXARG_DELAY];
+    new_graphic_info[i].anim_vertical = parameter[GFXARG_VERTICAL];
+    new_graphic_info[i].anim_mode =
+      (parameter[GFXARG_PINGPONG] ? ANIM_PINGPONG :
+       parameter[GFXARG_REVERSE]  ? ANIM_REVERSE  : ANIM_NORMAL);
+
+    if (new_graphic_info[i].anim_delay == 0)   /* delay must be at least 1 */
+      new_graphic_info[i].anim_delay = 1;
+  }
+
+#if 0
+  printf("D> %d\n", image_files[GFX_BD_DIAMOND].parameter[GFXARG_NUM_FRAMES]);
+  printf("W> %d\n", image_files[GFX_ROBOT_WHEEL].parameter[GFXARG_NUM_FRAMES]);
+
+  graphic_info[GFX_ABLENK].bitmap = getBitmapFromImageID(GFX_ROBOT_WHEEL);
+  graphic_info[GFX_ABLENK].src_x = 0;
+  graphic_info[GFX_ABLENK].src_y = 0;
+
+  graphic_info[GFX_ABLENK + 1].bitmap = getBitmapFromImageID(GFX_ROBOT_WHEEL);
+  graphic_info[GFX_ABLENK + 2].bitmap = getBitmapFromImageID(GFX_ROBOT_WHEEL);
+  graphic_info[GFX_ABLENK + 3].bitmap = getBitmapFromImageID(GFX_ROBOT_WHEEL);
+  graphic_info[GFX_ABLENK + 1].src_x = 1 * TILEX;
+  graphic_info[GFX_ABLENK + 2].src_x = 2 * TILEX;
+  graphic_info[GFX_ABLENK + 3].src_x = 3 * TILEX;
+  graphic_info[GFX_ABLENK + 1].src_y = 0;
+  graphic_info[GFX_ABLENK + 2].src_y = 0;
+  graphic_info[GFX_ABLENK + 3].src_y = 0;
+#endif
+}
+
+static void InitSoundInfo()
+{
+  sound_files = getCurrentSoundList();
+
+  /* initialize sound effect lookup table for element actions */
+  InitGameSound();
 }
 
 void InitElementProperties()
@@ -2069,10 +2119,10 @@ void Execute_Debug_Command(char *command)
     printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
     printf("\n");
 
-    for (i=0; i<NUM_IMAGE_CONFIG_ENTRIES; i++)
+    for (i=0; image_config[i].token != NULL; i++)
       printf("# %s\n",
             getFormattedSetupEntry(image_config[i].token,
-                                   image_config[i].default_filename));
+                                   image_config[i].value));
   }
   else if (strcmp(command, "create soundsinfo.conf") == 0)
   {
@@ -2086,10 +2136,10 @@ void Execute_Debug_Command(char *command)
     printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
     printf("\n");
 
-    for (i=0; i<NUM_SOUND_CONFIG_ENTRIES; i++)
+    for (i=0; sound_config[i].token != NULL; i++)
       printf("# %s\n",
             getFormattedSetupEntry(sound_config[i].token,
-                                   sound_config[i].default_filename));
+                                   sound_config[i].value));
   }
   else if (strcmp(command, "create musicinfo.conf") == 0)
   {
@@ -2117,6 +2167,8 @@ void CloseAllAndExit(int exit_value)
   FreeAllMusic();
   CloseAudio();                /* called after freeing sounds (needed for SDL) */
 
+  FreeAllImages();
+
   FreeTileClipmasks();
   for(i=0; i<NUM_BITMAPS; i++)
     FreeBitmap(pix[i]);