added command line function to write element collecting image to directory
[rocksndiamonds.git] / src / files.c
index 38b19f83c58c1429a246a833fef20bcdac685407..83efc95803ba9dd0324b153219d81728ad06d33c 100644 (file)
@@ -7656,10 +7656,33 @@ void DumpLevel(struct LevelInfo *level)
   Print("SP player blocks last field: %s\n", (level->sp_block_last_field ? "yes" : "no"));
   Print("use spring bug: %s\n", (level->use_spring_bug ? "yes" : "no"));
   Print("use step counter: %s\n", (level->use_step_counter ? "yes" : "no"));
+  Print("rate time over score: %s\n", (level->rate_time_over_score ? "yes" : "no"));
 
   PrintLine("-", 79);
 }
 
+void DumpLevels(void)
+{
+  static LevelDirTree *dumplevel_leveldir = NULL;
+
+  dumplevel_leveldir = getTreeInfoFromIdentifier(leveldir_first,
+                                                global.dumplevel_leveldir);
+
+  if (dumplevel_leveldir == NULL)
+    Fail("no such level identifier: '%s'", global.dumplevel_leveldir);
+
+  if (global.dumplevel_level_nr < dumplevel_leveldir->first_level ||
+      global.dumplevel_level_nr > dumplevel_leveldir->last_level)
+    Fail("no such level number: %d", global.dumplevel_level_nr);
+
+  leveldir_current = dumplevel_leveldir;
+
+  LoadLevel(global.dumplevel_level_nr);
+  DumpLevel(&level);
+
+  CloseAllAndExit(0);
+}
+
 
 // ============================================================================
 // tape file functions
@@ -8419,6 +8442,32 @@ void DumpTape(struct TapeInfo *tape)
   PrintLine("-", 79);
 }
 
+void DumpTapes(void)
+{
+  static LevelDirTree *dumptape_leveldir = NULL;
+
+  dumptape_leveldir = getTreeInfoFromIdentifier(leveldir_first,
+                                               global.dumptape_leveldir);
+
+  if (dumptape_leveldir == NULL)
+    Fail("no such level identifier: '%s'", global.dumptape_leveldir);
+
+  if (global.dumptape_level_nr < dumptape_leveldir->first_level ||
+      global.dumptape_level_nr > dumptape_leveldir->last_level)
+    Fail("no such level number: %d", global.dumptape_level_nr);
+
+  leveldir_current = dumptape_leveldir;
+
+  if (options.mytapes)
+    LoadTape(global.dumptape_level_nr);
+  else
+    LoadSolutionTape(global.dumptape_level_nr);
+
+  DumpTape(&tape);
+
+  CloseAllAndExit(0);
+}
+
 
 // ============================================================================
 // score file functions
@@ -8441,6 +8490,7 @@ static void setScoreInfoToDefaultsExt(struct ScoreInfo *scores)
   scores->last_added_local = -1;
 
   scores->updated = FALSE;
+  scores->force_last_added = FALSE;
 }
 
 static void setScoreInfoToDefaults(void)
@@ -8742,7 +8792,6 @@ void LoadScore(int nr)
 void SaveScore_OLD(int nr)
 {
   int i;
-  int permissions = (program.global_scores ? PERMS_PUBLIC : PERMS_PRIVATE);
   char *filename = getScoreFilename(nr);
   FILE *file;
 
@@ -8763,7 +8812,7 @@ void SaveScore_OLD(int nr)
 
   fclose(file);
 
-  SetFilePermissions(filename, permissions);
+  SetFilePermissions(filename, PERMS_PRIVATE);
 }
 #endif
 
@@ -8832,7 +8881,6 @@ static void SaveScore_TAPE(FILE *file, struct ScoreInfo *scores)
 static void SaveScoreToFilename(char *filename)
 {
   FILE *file;
-  int permissions = (program.global_scores ? PERMS_PUBLIC : PERMS_PRIVATE);
   int info_chunk_size;
   int name_chunk_size;
   int scor_chunk_size;
@@ -8875,7 +8923,7 @@ static void SaveScoreToFilename(char *filename)
 
   fclose(file);
 
-  SetFilePermissions(filename, permissions);
+  SetFilePermissions(filename, PERMS_PRIVATE);
 }
 
 void SaveScore(int nr)
@@ -8929,7 +8977,7 @@ static void DownloadServerScoreToCacheExt(struct HttpRequest *request,
                                          struct HttpResponse *response,
                                          int nr)
 {
-  request->hostname = API_SERVER_HOSTNAME;
+  request->hostname = setup.api_server_hostname;
   request->port     = API_SERVER_PORT;
   request->method   = API_SERVER_METHOD;
   request->uri      = API_SERVER_URI_GET;
@@ -9094,7 +9142,7 @@ void LoadServerScore(int nr, boolean download_score)
   // (this should prevent reading it while the thread is writing to it)
   LoadServerScoreFromCache(nr);
 
-  if (download_score)
+  if (download_score && runtime.api_server)
   {
     // 2nd step: download server scores from score server to cache file
     // (as thread, as it might time out if the server is not reachable)
@@ -9162,7 +9210,7 @@ static void UploadScoreToServerExt(struct HttpRequest *request,
 {
   struct ScoreEntry *score_entry = &scores.entry[scores.last_added];
 
-  request->hostname = API_SERVER_HOSTNAME;
+  request->hostname = setup.api_server_hostname;
   request->port     = API_SERVER_PORT;
   request->method   = API_SERVER_METHOD;
   request->uri      = API_SERVER_URI_ADD;
@@ -9253,7 +9301,7 @@ static void UploadScoreToServerAsThread(int nr)
 
 void SaveServerScore(int nr)
 {
-  if (!setup.api_server)
+  if (!runtime.api_server)
     return;
 
   UploadScoreToServerAsThread(nr);
@@ -9268,7 +9316,7 @@ void LoadLocalAndServerScore(int nr, boolean download_score)
   // restore last added local score entry (before merging server scores)
   scores.last_added = scores.last_added_local = last_added_local;
 
-  if (setup.api_server)
+  if (setup.api_server && !setup.only_show_local_scores)
   {
     // load server scores from cache file and trigger update from server
     LoadServerScore(nr, download_score);
@@ -9464,6 +9512,10 @@ static struct TokenInfo global_setup_tokens[] =
     TYPE_SWITCH,
     &setup.show_snapshot_buttons,              "show_snapshot_buttons"
   },
+  {
+    TYPE_SWITCH,
+    &setup.only_show_local_scores,             "only_show_local_scores"
+  },
   {
     TYPE_STRING,
     &setup.graphics_set,                       "graphics_set"
@@ -10136,6 +10188,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->sp_show_border_elements = FALSE;
   si->small_game_graphics = FALSE;
   si->show_snapshot_buttons = FALSE;
+  si->only_show_local_scores = FALSE;
 
   si->graphics_set = getStringCopy(GFX_CLASSIC_SUBDIR);
   si->sounds_set   = getStringCopy(SND_CLASSIC_SUBDIR);
@@ -13033,8 +13086,8 @@ void CreateLevelSketchImages(void)
     sprintf(basename1, "%04d.bmp", i);
     sprintf(basename2, "%04ds.bmp", i);
 
-    filename1 = getPath2(global.create_images_dir, basename1);
-    filename2 = getPath2(global.create_images_dir, basename2);
+    filename1 = getPath2(global.create_sketch_images_dir, basename1);
+    filename2 = getPath2(global.create_sketch_images_dir, basename2);
 
     DrawSizedElement(0, 0, element, TILESIZE);
     BlitBitmap(drawto, bitmap1, SX, SY, TILEX, TILEY, 0, 0);
@@ -13078,6 +13131,104 @@ void CreateLevelSketchImages(void)
 }
 
 
+// ----------------------------------------------------------------------------
+// create and save images for element collecting animations (raw BMP format)
+// ----------------------------------------------------------------------------
+
+static boolean createCollectImage(int element)
+{
+  return (IS_COLLECTIBLE(element) && !IS_SP_ELEMENT(element));
+}
+
+void CreateCollectElementImages(void)
+{
+  int i, j;
+  int num_steps = 8;
+  int anim_frames = num_steps - 1;
+  int tile_size = TILESIZE;
+  int anim_width  = tile_size * anim_frames;
+  int anim_height = tile_size;
+  int num_collect_images = 0;
+  int pos_collect_images = 0;
+
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+    if (createCollectImage(i))
+      num_collect_images++;
+
+  Info("Creating %d element collecting animation images ...",
+       num_collect_images);
+
+  int dst_width  = anim_width * 2;
+  int dst_height = anim_height * num_collect_images / 2;
+  Bitmap *dst_bitmap = CreateBitmap(dst_width, dst_height, DEFAULT_DEPTH);
+  char *basename = "RocksCollect.bmp";
+  char *filename = getPath2(global.create_collect_images_dir, basename);
+
+  for (i = 0; i < MAX_NUM_ELEMENTS; i++)
+  {
+    if (!createCollectImage(i))
+      continue;
+
+    int dst_x = (pos_collect_images / (num_collect_images / 2)) * anim_width;
+    int dst_y = (pos_collect_images % (num_collect_images / 2)) * anim_height;
+    int graphic = el2img(i);
+    char *token_name = element_info[i].token_name;
+    Bitmap *tmp_bitmap = CreateBitmap(tile_size, tile_size, DEFAULT_DEPTH);
+    Bitmap *src_bitmap;
+    int src_x, src_y;
+
+    Info("- creating collecting image for '%s' ...", token_name);
+
+    getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
+
+    BlitBitmap(src_bitmap, tmp_bitmap, src_x, src_y,
+              tile_size, tile_size, 0, 0);
+
+    tmp_bitmap->surface_masked = tmp_bitmap->surface;
+
+    for (j = 0; j < anim_frames; j++)
+    {
+      int frame_size_final = tile_size * (anim_frames - j) / num_steps;
+      int frame_size = frame_size_final * num_steps;
+      int offset = (tile_size - frame_size_final) / 2;
+      Bitmap *frame_bitmap = ZoomBitmap(tmp_bitmap, frame_size, frame_size);
+
+      while (frame_size > frame_size_final)
+      {
+       frame_size /= 2;
+
+       Bitmap *half_bitmap = ZoomBitmap(frame_bitmap, frame_size, frame_size);
+
+       FreeBitmap(frame_bitmap);
+
+       frame_bitmap = half_bitmap;
+      }
+
+      BlitBitmap(frame_bitmap, dst_bitmap, 0, 0,
+                frame_size_final, frame_size_final,
+                dst_x + j * tile_size + offset, dst_y + offset);
+
+      FreeBitmap(frame_bitmap);
+    }
+
+    tmp_bitmap->surface_masked = NULL;
+
+    FreeBitmap(tmp_bitmap);
+
+    pos_collect_images++;
+  }
+
+  if (SDL_SaveBMP(dst_bitmap->surface, filename) != 0)
+    Fail("cannot save element collecting image file '%s'", filename);
+
+  FreeBitmap(dst_bitmap);
+
+  Info("Done.");
+
+  CloseAllAndExit(0);
+}
+
+
 // ----------------------------------------------------------------------------
 // create and save images for custom and group elements (raw BMP format)
 // ----------------------------------------------------------------------------