changed simple "printf()" debug output to new debug log function
[rocksndiamonds.git] / src / init.c
index be7447666d29dc90c4e29ca326d51a365bb2c84d..d126103a47d662fa6b7c4ece63852b4aa142632d 100644 (file)
@@ -650,15 +650,14 @@ static void InitGlobalAnimGraphicInfo(void)
   }
 
 #if 0
-  printf("::: InitGlobalAnimGraphicInfo\n");
-
   for (i = 0; i < NUM_GLOBAL_ANIMS; i++)
     for (j = 0; j < NUM_GLOBAL_ANIM_PARTS_ALL; j++)
       for (k = 0; k < NUM_SPECIAL_GFX_ARGS; k++)
        if (global_anim_info[i].graphic[j][k] != IMG_UNDEFINED &&
            graphic_info[global_anim_info[i].graphic[j][k]].bitmap != NULL)
-         printf("::: - anim %d, part %d, mode %d => %d\n",
-                i, j, k, global_anim_info[i].graphic[j][k]);
+         Debug("init:InitGlobalAnimGraphicInfo",
+               "anim %d, part %d, mode %d => %d",
+               i, j, k, global_anim_info[i].graphic[j][k]);
 #endif
 }
 
@@ -700,14 +699,13 @@ static void InitGlobalAnimSoundInfo(void)
   }
 
 #if 0
-  printf("::: InitGlobalAnimSoundInfo\n");
-
   for (i = 0; i < NUM_GLOBAL_ANIMS; i++)
     for (j = 0; j < NUM_GLOBAL_ANIM_PARTS_ALL; j++)
       for (k = 0; k < NUM_SPECIAL_GFX_ARGS; k++)
        if (global_anim_info[i].sound[j][k] != SND_UNDEFINED)
-         printf("::: - anim %d, part %d, mode %d => %d\n",
-                i, j, k, global_anim_info[i].sound[j][k]);
+         Debug("init:InitGlobalAnimSoundInfo",
+               "anim %d, part %d, mode %d => %d",
+               i, j, k, global_anim_info[i].sound[j][k]);
 #endif
 }
 
@@ -749,14 +747,13 @@ static void InitGlobalAnimMusicInfo(void)
   }
 
 #if 0
-  printf("::: InitGlobalAnimMusicInfo\n");
-
   for (i = 0; i < NUM_GLOBAL_ANIMS; i++)
     for (j = 0; j < NUM_GLOBAL_ANIM_PARTS_ALL; j++)
       for (k = 0; k < NUM_SPECIAL_GFX_ARGS; k++)
        if (global_anim_info[i].music[j][k] != MUS_UNDEFINED)
-         printf("::: - anim %d, part %d, mode %d => %d\n",
-                i, j, k, global_anim_info[i].music[j][k]);
+         Debug("init:InitGlobalAnimMusicInfo",
+               "anim %d, part %d, mode %d => %d",
+               i, j, k, global_anim_info[i].music[j][k]);
 #endif
 }
 
@@ -1224,13 +1221,13 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type)
 
     if (value == NULL)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_INFO, "warning: error found in config file:");
-      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-      Error(ERR_INFO, "error: invalid element token '%s'", value_raw);
-      Error(ERR_INFO, "custom graphic rejected for this element/action");
-      Error(ERR_INFO, "fallback done to undefined element for this graphic");
-      Error(ERR_INFO_LINE, "-");
+      Warn("---");
+      Warn("error found in config file:");
+      Warn("- config file: '%s'", getImageConfigFilename());
+      Warn("error: invalid element token '%s'", value_raw);
+      Warn("custom graphic rejected for this element/action");
+      Warn("fallback done to undefined element for this graphic");
+      Warn("---");
     }
 
     return (value != NULL ? atoi(value) : EL_UNDEFINED);
@@ -1242,13 +1239,13 @@ static int get_graphic_parameter_value(char *value_raw, char *suffix, int type)
 
     if (value == NULL)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_INFO, "warning: error found in config file:");
-      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-      Error(ERR_INFO, "error: invalid graphic token '%s'", value_raw);
-      Error(ERR_INFO, "custom graphic rejected for this element/action");
-      Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
-      Error(ERR_INFO_LINE, "-");
+      Warn("---");
+      Warn("error found in config file:");
+      Warn("- config file: '%s'", getImageConfigFilename());
+      Warn("error: invalid graphic token '%s'", value_raw);
+      Warn("custom graphic rejected for this element/action");
+      Warn("fallback done to 'char_exclam' for this graphic");
+      Warn("---");
     }
 
     return (value != NULL ? atoi(value) : fallback_graphic);
@@ -1379,20 +1376,20 @@ static void set_graphic_parameters_ext(int graphic, int *parameter,
   {
     if (g->width <= 0)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_WARN, "invalid value %d for '%s.width' (fallback done to %d)",
-           g->width, getTokenFromImageID(graphic), TILEX);
-      Error(ERR_INFO_LINE, "-");
+      Warn("---");
+      Warn("invalid value %d for '%s.width' (fallback done to %d)",
+          g->width, getTokenFromImageID(graphic), TILEX);
+      Warn("---");
 
       g->width = TILEX;                // will be checked to be inside bitmap later
     }
 
     if (g->height <= 0)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_WARN, "invalid value %d for '%s.height' (fallback done to %d)",
-           g->height, getTokenFromImageID(graphic), TILEY);
-      Error(ERR_INFO_LINE, "-");
+      Warn("---");
+      Warn("invalid value %d for '%s.height' (fallback done to %d)",
+          g->height, getTokenFromImageID(graphic), TILEY);
+      Warn("---");
 
       g->height = TILEY;       // will be checked to be inside bitmap later
     }
@@ -1650,18 +1647,18 @@ static void set_cloned_graphic_parameters(int graphic)
 
   if (num_references_followed >= max_num_images)
   {
-    Error(ERR_INFO_LINE, "-");
-    Error(ERR_INFO, "warning: error found in config file:");
-    Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-    Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(graphic));
-    Error(ERR_INFO, "error: loop discovered when resolving cloned graphics");
-    Error(ERR_INFO, "custom graphic rejected for this element/action");
+    Warn("---");
+    Warn("error found in config file:");
+    Warn("- config file: '%s'", getImageConfigFilename());
+    Warn("- config token: '%s'", getTokenFromImageID(graphic));
+    Warn("error: loop discovered when resolving cloned graphics");
+    Warn("custom graphic rejected for this element/action");
 
     if (graphic == fallback_graphic)
       Error(ERR_EXIT, "no fallback graphic available");
 
-    Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
-    Error(ERR_INFO_LINE, "-");
+    Warn("fallback done to 'char_exclam' for this graphic");
+    Warn("---");
 
     graphic_info[graphic] = graphic_info[fallback_graphic];
   }
@@ -1800,22 +1797,21 @@ static void InitGraphicInfo(void)
        src_x + width  > src_bitmap_width ||
        src_y + height > src_bitmap_height)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_INFO, "warning: error found in config file:");
-      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-      Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(i));
-      Error(ERR_INFO, "- image file: '%s'", src_bitmap->source_filename);
-      Error(ERR_INFO, "- frame size: %d, %d", width, height);
-      Error(ERR_INFO,
-           "error: first animation frame out of bounds (%d, %d) [%d, %d]",
-           src_x, src_y, src_bitmap_width, src_bitmap_height);
-      Error(ERR_INFO, "custom graphic rejected for this element/action");
+      Warn("---");
+      Warn("error found in config file:");
+      Warn("- config file: '%s'", getImageConfigFilename());
+      Warn("- config token: '%s'", getTokenFromImageID(i));
+      Warn("- image file: '%s'", src_bitmap->source_filename);
+      Warn("- frame size: %d, %d", width, height);
+      Warn("error: first animation frame out of bounds (%d, %d) [%d, %d]",
+          src_x, src_y, src_bitmap_width, src_bitmap_height);
+      Warn("custom graphic rejected for this element/action");
 
       if (i == fallback_graphic)
        Error(ERR_EXIT, "no fallback graphic available");
 
-      Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
-      Error(ERR_INFO_LINE, "-");
+      Warn("fallback done to 'char_exclam' for this graphic");
+      Warn("---");
 
       graphic_info[i] = graphic_info[fallback_graphic];
 
@@ -1832,22 +1828,21 @@ static void InitGraphicInfo(void)
        src_x + width  > src_bitmap_width ||
        src_y + height > src_bitmap_height)
     {
-      Error(ERR_INFO_LINE, "-");
-      Error(ERR_INFO, "warning: error found in config file:");
-      Error(ERR_INFO, "- config file: '%s'", getImageConfigFilename());
-      Error(ERR_INFO, "- config token: '%s'", getTokenFromImageID(i));
-      Error(ERR_INFO, "- image file: '%s'", src_bitmap->source_filename);
-      Error(ERR_INFO, "- frame size: %d, %d", width, height);
-      Error(ERR_INFO,
-           "error: last animation frame (%d) out of bounds (%d, %d) [%d, %d]",
-           last_frame, src_x, src_y, src_bitmap_width, src_bitmap_height);
-      Error(ERR_INFO, "custom graphic rejected for this element/action");
+      Warn("---");
+      Warn("error found in config file:");
+      Warn("- config file: '%s'", getImageConfigFilename());
+      Warn("- config token: '%s'", getTokenFromImageID(i));
+      Warn("- image file: '%s'", src_bitmap->source_filename);
+      Warn("- frame size: %d, %d", width, height);
+      Warn("error: last animation frame (%d) out of bounds (%d, %d) [%d, %d]",
+          last_frame, src_x, src_y, src_bitmap_width, src_bitmap_height);
+      Warn("custom graphic rejected for this element/action");
 
       if (i == fallback_graphic)
        Error(ERR_EXIT, "no fallback graphic available");
 
-      Error(ERR_INFO, "fallback done to 'char_exclam' for this graphic");
-      Error(ERR_INFO_LINE, "-");
+      Warn("fallback done to 'char_exclam' for this graphic");
+      Warn("---");
 
       graphic_info[i] = graphic_info[fallback_graphic];
     }
@@ -1884,7 +1879,10 @@ static void InitGraphicCompatibilityInfo(void)
        // process all images which default to same image as "global.door"
        if (strEqual(fi->default_filename, fi_global_door->default_filename))
        {
-         // printf("::: special treatment needed for token '%s'\n", fi->token);
+#if 0
+         Debug("init:InitGraphicCompatibilityInfo",
+               "special treatment needed for token '%s'", fi->token);
+#endif
 
          graphic_info[i].bitmaps = graphic_info[IMG_GLOBAL_DOOR].bitmaps;
          graphic_info[i].bitmap  = graphic_info[IMG_GLOBAL_DOOR].bitmap;
@@ -2442,7 +2440,7 @@ static void ResolveGroupElementExt(int group_element, int recursion_depth)
 
   if (recursion_depth > NUM_GROUP_ELEMENTS)    // recursion too deep
   {
-    Error(ERR_WARN, "recursion too deep when resolving group element %d",
+    Warn("recursion too deep when resolving group element %d",
          group_element - EL_GROUP_START + 1);
 
     // replace element which caused too deep recursion by question mark
@@ -5080,7 +5078,7 @@ static void Execute_Command(char *command)
        str_ptr++;
     }
 
-    if (global.autoplay_mode & AUTOPLAY_MODE_WARP_NO_DISPLAY)
+    if (global.autoplay_mode & AUTOPLAY_WARP_NO_DISPLAY)
       program.headless = TRUE;
   }
   else if (strPrefix(command, "patch tapes "))
@@ -5623,36 +5621,36 @@ static void InitImages(void)
   print_timestamp_init("InitImages");
 
 #if 0
-  printf("::: leveldir_current->identifier == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier);
-  printf("::: leveldir_current->graphics_path == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path);
-  printf("::: leveldir_current->graphics_set == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set);
-  printf("::: getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS));
+  Debug("init:InitImages", "leveldir_current->identifier == '%s'",
+       leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier);
+  Debug("init:InitImages", "leveldir_current->graphics_path == '%s'",
+       leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path);
+  Debug("init:InitImages", "leveldir_current->graphics_set == '%s'",
+       leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set);
+  Debug("init:InitImages", "getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'",
+       leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS));
 #endif
 
   setLevelArtworkDir(artwork.gfx_first);
 
 #if 0
-  printf("::: leveldir_current->identifier == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier);
-  printf("::: leveldir_current->graphics_path == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path);
-  printf("::: leveldir_current->graphics_set == '%s'\n",
+  Debug("init:InitImages", "leveldir_current->identifier == '%s'",
+       leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier);
+  Debug("init:InitImages", "leveldir_current->graphics_path == '%s'",
+       leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path);
+  Debug("init:InitImages", "leveldir_current->graphics_set == '%s'",
         leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set);
-  printf("::: getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS));
+  Debug("init:InitImages", "getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'",
+       leveldir_current == NULL ? "[NULL]" : LEVELDIR_ARTWORK_SET(leveldir_current, ARTWORK_TYPE_GRAPHICS));
 #endif
 
 #if 0
-  printf("::: InitImages for '%s' ['%s', '%s'] ['%s', '%s']\n",
-        leveldir_current->identifier,
-        artwork.gfx_current_identifier,
-        artwork.gfx_current->identifier,
-        leveldir_current->graphics_set,
-        leveldir_current->graphics_path);
+  Debug("init:InitImages", "InitImages for '%s' ['%s', '%s'] ['%s', '%s']",
+       leveldir_current->identifier,
+       artwork.gfx_current_identifier,
+       artwork.gfx_current->identifier,
+       leveldir_current->graphics_set,
+       leveldir_current->graphics_path);
 #endif
 
   UPDATE_BUSY_STATE();
@@ -5811,22 +5809,27 @@ static boolean CheckArtworkTypeForRedefinedCustomElements(int type)
   setLevelArtworkDir(ARTWORK_FIRST_NODE(artwork, type));
 
 #if 0
-  printf("::: leveldir_current->identifier == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier);
-  printf("::: leveldir_current->graphics_path == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path);
-  printf("::: leveldir_current->graphics_set == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set);
-  printf("::: getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'\n",
-        leveldir_current == NULL ? "[NULL]" :
-        LEVELDIR_ARTWORK_SET(leveldir_current, type));
+  Debug("init:CheckArtworkTypeForRedefinedCustomElements",
+       "leveldir_current->identifier == '%s'",
+       leveldir_current == NULL ? "[NULL]" : leveldir_current->identifier);
+  Debug("init:CheckArtworkTypeForRedefinedCustomElements",
+       "leveldir_current->graphics_path == '%s'",
+       leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_path);
+  Debug("init:CheckArtworkTypeForRedefinedCustomElements",
+       "leveldir_current->graphics_set == '%s'",
+       leveldir_current == NULL ? "[NULL]" : leveldir_current->graphics_set);
+  Debug("init:CheckArtworkTypeForRedefinedCustomElements",
+       "getLevelArtworkSet(ARTWORK_TYPE_GRAPHICS) == '%s'",
+       leveldir_current == NULL ? "[NULL]" :
+       LEVELDIR_ARTWORK_SET(leveldir_current, type));
 #endif
 
   // first look for special artwork configured in level series config
   filename_base = getCustomArtworkLevelConfigFilename(type);
 
 #if 0
-  printf("::: filename_base == '%s'\n", filename_base);
+  Debug("init:CheckArtworkTypeForRedefinedCustomElements",
+       "filename_base == '%s'", filename_base);
 #endif
 
   if (fileExists(filename_base))
@@ -5835,14 +5838,16 @@ static boolean CheckArtworkTypeForRedefinedCustomElements(int type)
   filename_local = getCustomArtworkConfigFilename(type);
 
 #if 0
-  printf("::: filename_local == '%s'\n", filename_local);
+  Debug("init:CheckArtworkTypeForRedefinedCustomElements",
+       "filename_local == '%s'", filename_local);
 #endif
 
   if (filename_local != NULL && !strEqual(filename_base, filename_local))
     redefined_ce_found |= CheckArtworkConfigForCustomElements(filename_local);
 
 #if 0
-  printf("::: redefined_ce_found == %d\n", redefined_ce_found);
+  Debug("init:CheckArtworkTypeForRedefinedCustomElements",
+       "redefined_ce_found == %d", redefined_ce_found);
 #endif
 
   return redefined_ce_found;
@@ -5867,7 +5872,8 @@ static void InitOverrideArtwork(void)
        CheckArtworkTypeForRedefinedCustomElements(ARTWORK_TYPE_MUSIC));
 
 #if 0
-  printf("::: redefined_ce_found == %d\n", redefined_ce_found);
+  Debug("init:InitOverrideArtwork", "redefined_ce_found == %d",
+       redefined_ce_found);
 #endif
 
   if (redefined_ce_found)
@@ -5886,10 +5892,10 @@ static void InitOverrideArtwork(void)
   }
 
 #if 0
-  printf("::: => %d, %d, %d\n",
-        gfx.override_level_graphics,
-        gfx.override_level_sounds,
-        gfx.override_level_music);
+  Debug("init:InitOverrideArtwork", "%d, %d, %d",
+       gfx.override_level_graphics,
+       gfx.override_level_sounds,
+       gfx.override_level_music);
 #endif
 }
 
@@ -6005,11 +6011,12 @@ void ReloadCustomArtwork(int force_reload)
   if (gfx_new_identifier != NULL || force_reload_gfx)
   {
 #if 0
-    printf("RELOADING GRAPHICS '%s' -> '%s' ['%s', '%s']\n",
-          artwork.gfx_current_identifier,
-          gfx_new_identifier,
-          artwork.gfx_current->identifier,
-          leveldir_current->graphics_set);
+    Debug("init:ReloadCustomArtwork",
+         "RELOADING GRAPHICS '%s' -> '%s' ['%s', '%s']",
+         artwork.gfx_current_identifier,
+         gfx_new_identifier,
+         artwork.gfx_current->identifier,
+         leveldir_current->graphics_set);
 #endif
 
     InitImages();
@@ -6155,7 +6162,7 @@ void OpenAll(void)
 #if defined(PLATFORM_UNIX)
     NetworkServer(network.server_port, TRUE);
 #else
-    Error(ERR_WARN, "networking only supported in Unix version");
+    Warn("networking only supported in Unix version");
 #endif
 
     exit(0);                   // never reached, server loops forever
@@ -6260,16 +6267,16 @@ void OpenAll(void)
   DrawMainMenu();
 
 #if 0
-  Error(ERR_DEBUG, "::: SDL_GetBasePath() == '%s'",
+  Debug("internal:path", "SDL_GetBasePath() == '%s'",
        SDL_GetBasePath());
-  Error(ERR_DEBUG, "::: SDL_GetPrefPath() == '%s'",
+  Debug("internal:path", "SDL_GetPrefPath() == '%s'",
        SDL_GetPrefPath("artsoft", "rocksndiamonds"));
 #if defined(PLATFORM_ANDROID)
-  Error(ERR_DEBUG, "::: SDL_AndroidGetInternalStoragePath() == '%s'",
+  Debug("internal:path", "SDL_AndroidGetInternalStoragePath() == '%s'",
        SDL_AndroidGetInternalStoragePath());
-  Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStoragePath() == '%s'",
+  Debug("internal:path", "SDL_AndroidGetExternalStoragePath() == '%s'",
        SDL_AndroidGetExternalStoragePath());
-  Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStorageState() == '%s'",
+  Debug("internal:path", "SDL_AndroidGetExternalStorageState() == '%s'",
        (SDL_AndroidGetExternalStorageState() &
         SDL_ANDROID_EXTERNAL_STORAGE_WRITE ? "writable" :
         SDL_AndroidGetExternalStorageState() &