fixed element scores for MM style elements (MM engine)
[rocksndiamonds.git] / src / files.c
index 30e10f5a5f60c7e50acd1af37109a68d62d12808..d42a2cd55e9effbcbdbb942dd06a167749b9354c 100644 (file)
@@ -57,7 +57,7 @@
 
 #define TAPE_CHUNK_VERS_SIZE   8       /* size of file version chunk */
 #define TAPE_CHUNK_HEAD_SIZE   20      /* size of tape file header   */
-#define TAPE_CHUNK_HEAD_UNUSED 3       /* unused tape header bytes   */
+#define TAPE_CHUNK_HEAD_UNUSED 2       /* unused tape header bytes   */
 
 #define LEVEL_CHUNK_CNT3_SIZE(x)        (LEVEL_CHUNK_CNT3_HEADER + (x))
 #define LEVEL_CHUNK_CUS3_SIZE(x)        (2 + (x) * LEVEL_CPART_CUS3_SIZE)
@@ -843,17 +843,17 @@ static struct LevelFileConfigInfo chunk_config_ELEM[] =
     TYPE_INTEGER,                      CONF_VALUE_16_BIT(1),
     &li.mm_time_fuse,                  0
   },
+  {
+    EL_MM_LIGHTBALL,                   -1,
+    TYPE_INTEGER,                      CONF_VALUE_16_BIT(1),
+    &li.score[SC_ELEM_BONUS],          10
+  },
 
   /* ---------- unused values ----------------------------------------------- */
 
   {
     EL_UNKNOWN,                                SAVE_CONF_NEVER,
     TYPE_INTEGER,                      CONF_VALUE_16_BIT(1),
-    &li.score[SC_UNKNOWN_14],          10
-  },
-  {
-    EL_UNKNOWN,                                SAVE_CONF_NEVER,
-    TYPE_INTEGER,                      CONF_VALUE_16_BIT(2),
     &li.score[SC_UNKNOWN_15],          10
   },
 
@@ -3976,10 +3976,6 @@ void CopyNativeLevel_RND_to_MM(struct LevelInfo *level)
   struct LevelInfo_MM *level_mm = level->native_mm_level;
   int x, y;
 
-  level_mm->file_version = level->file_version;
-  level_mm->game_version = level->game_version;
-  level_mm->encoding_16bit_field = level->encoding_16bit_field;
-
   level_mm->fieldx = MIN(level->fieldx, MM_MAX_PLAYFIELD_WIDTH);
   level_mm->fieldy = MIN(level->fieldy, MM_MAX_PLAYFIELD_HEIGHT);
 
@@ -3994,9 +3990,11 @@ void CopyNativeLevel_RND_to_MM(struct LevelInfo *level)
   strcpy(level_mm->name, level->name);
   strcpy(level_mm->author, level->author);
 
+  level_mm->score[SC_EMERALD]    = level->score[SC_EMERALD];
   level_mm->score[SC_PACMAN]     = level->score[SC_PACMAN];
-  level_mm->score[SC_KEY]        = level->score[SC_PACMAN];
+  level_mm->score[SC_KEY]        = level->score[SC_KEY];
   level_mm->score[SC_TIME_BONUS] = level->score[SC_TIME_BONUS];
+  level_mm->score[SC_ELEM_BONUS] = level->score[SC_ELEM_BONUS];
 
   level_mm->amoeba_speed = level->amoeba_speed;
   level_mm->time_fuse = level->mm_time_fuse;
@@ -4012,10 +4010,6 @@ void CopyNativeLevel_MM_to_RND(struct LevelInfo *level)
   struct LevelInfo_MM *level_mm = level->native_mm_level;
   int x, y;
 
-  level->file_version = level_mm->file_version;
-  level->game_version = level_mm->game_version;
-  level->encoding_16bit_field = level_mm->encoding_16bit_field;
-
   level->fieldx = MIN(level_mm->fieldx, MAX_LEV_FIELDX);
   level->fieldy = MIN(level_mm->fieldy, MAX_LEV_FIELDY);
 
@@ -4033,9 +4027,11 @@ void CopyNativeLevel_MM_to_RND(struct LevelInfo *level)
   if (!strEqual(level_mm->author, ANONYMOUS_NAME))
     strcpy(level->author, level_mm->author);
 
+  level->score[SC_EMERALD]    = level_mm->score[SC_EMERALD];
   level->score[SC_PACMAN]     = level_mm->score[SC_PACMAN];
-  level->score[SC_KEY]        = level_mm->score[SC_PACMAN];
+  level->score[SC_KEY]        = level_mm->score[SC_KEY];
   level->score[SC_TIME_BONUS] = level_mm->score[SC_TIME_BONUS];
+  level->score[SC_ELEM_BONUS] = level_mm->score[SC_ELEM_BONUS];
 
   level->amoeba_speed = level_mm->amoeba_speed;
   level->mm_time_fuse = level_mm->time_fuse;
@@ -7564,6 +7560,8 @@ static int LoadTape_HEAD(File *file, int chunk_size, struct TapeInfo *tape)
       }
     }
 
+    tape->use_mouse = (getFile8Bit(file) == 1 ? TRUE : FALSE);
+
     ReadUnusedBytesFromFile(file, TAPE_CHUNK_HEAD_UNUSED);
 
     engine_version = getFileVersion(file);
@@ -7599,8 +7597,9 @@ static int LoadTape_INFO(File *file, int chunk_size, struct TapeInfo *tape)
 static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
 {
   int i, j;
-  int chunk_size_expected =
-    (tape->num_participating_players + 1) * tape->length;
+  int tape_pos_size =
+    (tape->use_mouse ? 3 : tape->num_participating_players) + 1;
+  int chunk_size_expected = tape_pos_size * tape->length;
 
   if (chunk_size_expected != chunk_size)
   {
@@ -7622,12 +7621,23 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
       break;
     }
 
-    for (j = 0; j < MAX_PLAYERS; j++)
+    if (tape->use_mouse)
     {
-      tape->pos[i].action[j] = MV_NONE;
+      tape->pos[i].action[TAPE_ACTION_LX]     = getFile8Bit(file);
+      tape->pos[i].action[TAPE_ACTION_LY]     = getFile8Bit(file);
+      tape->pos[i].action[TAPE_ACTION_BUTTON] = getFile8Bit(file);
 
-      if (tape->player_participates[j])
-       tape->pos[i].action[j] = getFile8Bit(file);
+      tape->pos[i].action[TAPE_ACTION_UNUSED] = 0;
+    }
+    else
+    {
+      for (j = 0; j < MAX_PLAYERS; j++)
+      {
+       tape->pos[i].action[j] = MV_NONE;
+
+       if (tape->player_participates[j])
+         tape->pos[i].action[j] = getFile8Bit(file);
+      }
     }
 
     tape->pos[i].delay = getFile8Bit(file);
@@ -7684,7 +7694,7 @@ static int LoadTape_BODY(File *file, int chunk_size, struct TapeInfo *tape)
   }
 
   if (i != tape->length)
-    chunk_size = (tape->num_participating_players + 1) * i;
+    chunk_size = tape_pos_size * i;
 
   return chunk_size;
 }
@@ -7953,6 +7963,8 @@ static void SaveTape_HEAD(FILE *file, struct TapeInfo *tape)
 
   putFile8Bit(file, store_participating_players);
 
+  putFile8Bit(file, (tape->use_mouse ? 1 : 0));
+
   /* unused bytes not at the end here for 4-byte alignment of engine_version */
   WriteUnusedBytesToFile(file, TAPE_CHUNK_HEAD_UNUSED);
 
@@ -7978,9 +7990,18 @@ static void SaveTape_BODY(FILE *file, struct TapeInfo *tape)
 
   for (i = 0; i < tape->length; i++)
   {
-    for (j = 0; j < MAX_PLAYERS; j++)
-      if (tape->player_participates[j])
-       putFile8Bit(file, tape->pos[i].action[j]);
+    if (tape->use_mouse)
+    {
+      putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LX]);
+      putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_LY]);
+      putFile8Bit(file, tape->pos[i].action[TAPE_ACTION_BUTTON]);
+    }
+    else
+    {
+      for (j = 0; j < MAX_PLAYERS; j++)
+       if (tape->player_participates[j])
+         putFile8Bit(file, tape->pos[i].action[j]);
+    }
 
     putFile8Bit(file, tape->pos[i].delay);
   }
@@ -7991,6 +8012,7 @@ void SaveTape(int nr)
   char *filename = getTapeFilename(nr);
   FILE *file;
   int num_participating_players = 0;
+  int tape_pos_size;
   int info_chunk_size;
   int body_chunk_size;
   int i;
@@ -8011,8 +8033,10 @@ void SaveTape(int nr)
     if (tape.player_participates[i])
       num_participating_players++;
 
+  tape_pos_size = (tape.use_mouse ? 3 : num_participating_players) + 1;
+
   info_chunk_size = 2 + (strlen(tape.level_identifier) + 1) + 2;
-  body_chunk_size = (num_participating_players + 1) * tape.length;
+  body_chunk_size = tape_pos_size * tape.length;
 
   putFileChunkBE(file, "RND1", CHUNK_SIZE_UNDEFINED);
   putFileChunkBE(file, "TAPE", CHUNK_SIZE_NONE);