rnd-20060226-1-src
[rocksndiamonds.git] / src / files.c
index af9ac437de8353642a7ea0cea6f131aa99d7febb..0d4f895c34c050bd381c1df74a63ad641975b1f2 100644 (file)
 #define CONF_CONTENTS_ELEMENT(b,c,x,y) ((b[CONF_CONTENT_BYTE_POS(c,x,y)]<< 8)|\
                                        (b[CONF_CONTENT_BYTE_POS(c,x,y) + 1]))
 
+#if 0
+static void LoadLevel_InitPlayfield(struct LevelInfo *, char *);
+#endif
+
 static struct LevelInfo li;
 
 static struct
@@ -2497,6 +2501,45 @@ void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
     for (x = 0; x < EM_MAX_CAVE_WIDTH; x++)
       level_em->cave[x][y] = ZBORDER;
 
+#if 1
+
+#if 0
+#if 1
+  LoadLevel_InitPlayfield();
+#else
+  lev_fieldx = lev->width;     /* !!! also in LoadLevel_InitPlayfield() !!! */
+  lev_fieldy = lev->height;    /* !!! also in LoadLevel_InitPlayfield() !!! */
+  SetBorderElement();          /* !!! also in LoadLevel_InitPlayfield() !!! */
+#endif
+#endif
+
+#if 0
+  printf("::: BorderElement == %d\n", BorderElement);
+#endif
+
+  if (BorderElement == EL_STEELWALL)
+  {
+    for (y = 0; y < lev->height + 2; y++)
+      for (x = 0; x < lev->width + 2; x++)
+       level_em->cave[x + 1][y + 1] = map_element_RND_to_EM(EL_STEELWALL);
+  }
+
+  /* then copy the real level contents from level file into the playfield */
+  for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++)
+  {
+    int new_element = map_element_RND_to_EM(level->field[x][y]);
+    int offset = (BorderElement == EL_STEELWALL ? 1 : 0);
+    int xx = x + 1 + offset;
+    int yy = y + 1 + offset;
+
+    if (level->field[x][y] == EL_AMOEBA_DEAD)
+      new_element = map_element_RND_to_EM(EL_AMOEBA_WET);
+
+    level_em->cave[xx][yy] = new_element;
+  }
+
+#else
+
   /* then copy the real level contents from level file into the playfield */
   for (y = 0; y < lev->height; y++) for (x = 0; x < lev->width; x++)
   {
@@ -2508,6 +2551,8 @@ void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
     level_em->cave[x + 1][y + 1] = new_element;
   }
 
+#endif
+
 #if 1
 
   for (i = 0; i < MAX_PLAYERS; i++)
@@ -2531,15 +2576,17 @@ void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
   {
 
 #if 1
-
     if (ELEM_IS_PLAYER(level->field[x][y]))
     {
       int player_nr = GET_PLAYER_NR(level->field[x][y]);
+      int offset = (BorderElement == EL_STEELWALL ? 1 : 0);
+      int xx = x + 1 + offset;
+      int yy = y + 1 + offset;
 
-      ply[player_nr]->x_initial = x + 1;
-      ply[player_nr]->y_initial = y + 1;
+      ply[player_nr]->x_initial = xx;
+      ply[player_nr]->y_initial = yy;
 
-      level_em->cave[x + 1][y + 1] = map_element_RND_to_EM(EL_EMPTY);
+      level_em->cave[xx][yy] = map_element_RND_to_EM(EL_EMPTY);
     }
 
 #else
@@ -2571,6 +2618,14 @@ void CopyNativeLevel_RND_to_EM(struct LevelInfo *level)
 #endif
 
   }
+
+  if (BorderElement == EL_STEELWALL)
+  {
+#if 1
+    lev->width  += 2;
+    lev->height += 2;
+#endif
+  }
 }
 
 void CopyNativeLevel_EM_to_RND(struct LevelInfo *level)
@@ -3145,10 +3200,15 @@ void LoadLevelFromFileInfo(struct LevelInfo *level,
   if (level->game_engine_type == GAME_ENGINE_TYPE_UNKNOWN)
     level->game_engine_type = GAME_ENGINE_TYPE_RND;
 
+#if 1
+  if (level_file_info->type != LEVEL_FILE_TYPE_RND)
+    CopyNativeLevel_Native_to_RND(level);
+#else
   if (level_file_info->type == LEVEL_FILE_TYPE_RND)
     CopyNativeLevel_RND_to_Native(level);
   else
     CopyNativeLevel_Native_to_RND(level);
+#endif
 }
 
 void LoadLevelFromFilename(struct LevelInfo *level, char *filename)
@@ -3447,6 +3507,21 @@ static void LoadLevel_InitPlayfield(struct LevelInfo *level, char *filename)
   SetBorderElement();
 }
 
+static void LoadLevel_InitNativeEngines(struct LevelInfo *level,char *filename)
+{
+  struct LevelFileInfo *level_file_info = &level->file_info;
+
+#if 1
+  if (level_file_info->type == LEVEL_FILE_TYPE_RND)
+    CopyNativeLevel_RND_to_Native(level);
+#else
+  if (level_file_info->type == LEVEL_FILE_TYPE_RND)
+    CopyNativeLevel_RND_to_Native(level);
+  else
+    CopyNativeLevel_Native_to_RND(level);
+#endif
+}
+
 void LoadLevelTemplate(int nr)
 {
   char *filename;
@@ -3477,6 +3552,8 @@ void LoadLevel(int nr)
   LoadLevel_InitVersion(&level, filename);
   LoadLevel_InitElements(&level, filename);
   LoadLevel_InitPlayfield(&level, filename);
+
+  LoadLevel_InitNativeEngines(&level, filename);
 }
 
 static void SaveLevel_VERS(FILE *file, struct LevelInfo *level)
@@ -4692,6 +4769,7 @@ void SaveTape(int nr)
 
 void DumpTape(struct TapeInfo *tape)
 {
+  int tape_frame_counter;
   int i, j;
 
   if (tape->no_valid_file)
@@ -4709,12 +4787,14 @@ void DumpTape(struct TapeInfo *tape)
   printf("Level series identifier: '%s'\n", tape->level_identifier);
   printf_line("-", 79);
 
+  tape_frame_counter = 0;
+
   for (i = 0; i < tape->length; i++)
   {
     if (i >= MAX_TAPE_LEN)
       break;
 
-    printf("%03d: ", i);
+    printf("%04d: ", i);
 
     for (j = 0; j < MAX_PLAYERS; j++)
     {
@@ -4733,7 +4813,10 @@ void DumpTape(struct TapeInfo *tape)
       }
     }
 
-    printf("(%03d)\n", tape->pos[i].delay);
+    printf("(%03d) ", tape->pos[i].delay);
+    printf("[%05d]\n", tape_frame_counter);
+
+    tape_frame_counter += tape->pos[i].delay;
   }
 
   printf_line("-", 79);
@@ -4846,14 +4929,15 @@ void SaveScore(int nr)
 #define SETUP_TOKEN_TIME_LIMIT                 14
 #define SETUP_TOKEN_FULLSCREEN                 15
 #define SETUP_TOKEN_ASK_ON_ESCAPE              16
-#define SETUP_TOKEN_GRAPHICS_SET               17
-#define SETUP_TOKEN_SOUNDS_SET                 18
-#define SETUP_TOKEN_MUSIC_SET                  19
-#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS    20
-#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS      21
-#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC       22
+#define SETUP_TOKEN_QUICK_SWITCH               17
+#define SETUP_TOKEN_GRAPHICS_SET               18
+#define SETUP_TOKEN_SOUNDS_SET                 19
+#define SETUP_TOKEN_MUSIC_SET                  20
+#define SETUP_TOKEN_OVERRIDE_LEVEL_GRAPHICS    21
+#define SETUP_TOKEN_OVERRIDE_LEVEL_SOUNDS      22
+#define SETUP_TOKEN_OVERRIDE_LEVEL_MUSIC       23
 
-#define NUM_GLOBAL_SETUP_TOKENS                        23
+#define NUM_GLOBAL_SETUP_TOKENS                        24
 
 /* editor setup */
 #define SETUP_TOKEN_EDITOR_EL_BOULDERDASH      0
@@ -4956,6 +5040,7 @@ static struct TokenInfo global_setup_tokens[] =
   { TYPE_SWITCH, &si.time_limit,       "time_limit"                    },
   { TYPE_SWITCH, &si.fullscreen,       "fullscreen"                    },
   { TYPE_SWITCH, &si.ask_on_escape,    "ask_on_escape"                 },
+  { TYPE_SWITCH, &si.quick_switch,     "quick_player_switch"           },
   { TYPE_STRING, &si.graphics_set,     "graphics_set"                  },
   { TYPE_STRING, &si.sounds_set,       "sounds_set"                    },
   { TYPE_STRING, &si.music_set,                "music_set"                     },
@@ -5076,6 +5161,7 @@ static void setSetupInfoToDefaults(struct SetupInfo *si)
   si->time_limit = TRUE;
   si->fullscreen = FALSE;
   si->ask_on_escape = TRUE;
+  si->quick_switch = FALSE;
 
   si->graphics_set = getStringCopy(GFX_CLASSIC_SUBDIR);
   si->sounds_set = getStringCopy(SND_CLASSIC_SUBDIR);
@@ -6040,7 +6126,8 @@ void LoadHelpAnimInfo()
 
 #if 0
   for (i = 0; i < num_list_entries; i++)
-    printf("::: %d, %d, %d => %d\n",
+    printf("::: '%s': %d, %d, %d => %d\n",
+          EL_NAME(helpanim_info[i].element),
           helpanim_info[i].element,
           helpanim_info[i].action,
           helpanim_info[i].direction,