+ /* check yam content for 16-bit elements */
+ for(i=0; i<MAX_ELEMENT_CONTENTS; i++)
+ for(y=0; y<3; y++)
+ for(x=0; x<3; x++)
+ if (level.yam_content[i][x][y] > 255)
+ encoding_16bit = TRUE;
+
+ /* check level field for 16-bit elements */
+ for(y=0; y<lev_fieldy; y++)
+ for(x=0; x<lev_fieldx; x++)
+ if (Ur[x][y] > 255)
+ encoding_16bit = TRUE;
+
+ oldest_possible_cookie = (encoding_16bit ? LEVEL_COOKIE : LEVEL_COOKIE_12);
+
+ fputs(oldest_possible_cookie, file); /* file identifier */
+ fputc('\n', file);
+
+ putFileChunk(file, "HEAD", LEVEL_HEADER_SIZE, BYTE_ORDER_BIG_ENDIAN);
+
+ fputc(level.fieldx, file);
+ fputc(level.fieldy, file);
+
+ putFile16BitInteger(file, level.time, BYTE_ORDER_BIG_ENDIAN);
+ putFile16BitInteger(file, level.gems_needed, BYTE_ORDER_BIG_ENDIAN);
+
+ for(i=0; i<MAX_LEVEL_NAME_LEN; i++)
+ fputc(level.name[i], file);
+ for(i=0; i<LEVEL_SCORE_ELEMENTS; i++)
+ fputc(level.score[i], file);
+ for(i=0; i<STD_ELEMENT_CONTENTS; i++)
+ for(y=0; y<3; y++)
+ for(x=0; x<3; x++)
+ fputc(encoding_16bit ? EL_LEERRAUM : level.yam_content[i][x][y], file);
+ fputc(level.amoeba_speed, file);
+ fputc(level.time_magic_wall, file);
+ fputc(level.time_wheel, file);
+ fputc(level.amoeba_content, file);
+ fputc((level.double_speed ? 1 : 0), file);
+ fputc((level.gravity ? 1 : 0), file);
+
+ fputc((encoding_16bit ? 1 : 0), file);
+
+ for(i=0; i<LEVEL_HEADER_UNUSED; i++) /* set unused header bytes to zero */
+ fputc(0, file);
+
+ putFileChunk(file, "AUTH", MAX_LEVEL_AUTHOR_LEN, BYTE_ORDER_BIG_ENDIAN);
+
+ for(i=0; i<MAX_LEVEL_AUTHOR_LEN; i++)
+ fputc(level.author[i], file);
+
+ putFileChunk(file, "CONT", 4 + MAX_ELEMENT_CONTENTS * 3 * 3,
+ BYTE_ORDER_BIG_ENDIAN);
+
+ fputc(EL_MAMPFER, file);
+ fputc(level.num_yam_contents, file);
+ fputc(0, file);
+ fputc(0, file);
+
+ for(i=0; i<MAX_ELEMENT_CONTENTS; i++)
+ for(y=0; y<3; y++)
+ for(x=0; x<3; x++)
+ if (encoding_16bit)
+ putFile16BitInteger(file, level.yam_content[i][x][y],
+ BYTE_ORDER_BIG_ENDIAN);
+ else
+ fputc(level.yam_content[i][x][y], file);
+
+ putFileChunk(file, "BODY", lev_fieldx * lev_fieldy, BYTE_ORDER_BIG_ENDIAN);
+
+ for(y=0; y<lev_fieldy; y++)
+ for(x=0; x<lev_fieldx; x++)
+ if (encoding_16bit)
+ putFile16BitInteger(file, Ur[x][y], BYTE_ORDER_BIG_ENDIAN);
+ else
+ fputc(Ur[x][y], file);
+
+ fclose(file);
+
+ chmod(filename, LEVEL_PERMS);
+}
+
+static void SaveLevel_HEAD(struct LevelInfo *level, FILE *file)
+{
+ int i, x, y;
+
+ fputc(level->fieldx, file);
+ fputc(level->fieldy, file);
+
+ putFile16BitInteger(file, level->time, BYTE_ORDER_BIG_ENDIAN);
+ putFile16BitInteger(file, level->gems_needed, BYTE_ORDER_BIG_ENDIAN);
+
+ for(i=0; i<MAX_LEVEL_NAME_LEN; i++)
+ fputc(level->name[i], file);
+
+ for(i=0; i<LEVEL_SCORE_ELEMENTS; i++)
+ fputc(level->score[i], file);
+
+ for(i=0; i<STD_ELEMENT_CONTENTS; i++)
+ for(y=0; y<3; y++)
+ for(x=0; x<3; x++)
+ fputc((level->encoding_16bit_yamyam ? EL_LEERRAUM :
+ level->yam_content[i][x][y]),
+ file);
+ fputc(level->amoeba_speed, file);
+ fputc(level->time_magic_wall, file);
+ fputc(level->time_wheel, file);
+ fputc((level->encoding_16bit_amoeba ? EL_LEERRAUM : level->amoeba_content),
+ file);
+ fputc((level->double_speed ? 1 : 0), file);
+ fputc((level->gravity ? 1 : 0), file);
+
+ fputc((level->encoding_16bit_field ? 1 : 0), file);
+
+ WriteUnusedBytesToFile(file, LEVEL_HEADER_UNUSED);
+}
+
+static void SaveLevel_AUTH(struct LevelInfo *level, FILE *file)
+{
+ int i;
+
+ for(i=0; i<MAX_LEVEL_AUTHOR_LEN; i++)
+ fputc(level->author[i], file);
+}
+
+#if 0
+static void SaveLevel_CONT(struct LevelInfo *level, FILE *file)
+{
+ int i, x, y;
+
+ fputc(EL_MAMPFER, file);
+ fputc(level->num_yam_contents, file);
+ fputc(0, file);
+ fputc(0, file);
+
+ for(i=0; i<MAX_ELEMENT_CONTENTS; i++)
+ for(y=0; y<3; y++)
+ for(x=0; x<3; x++)
+ if (level->encoding_16bit_field)
+ putFile16BitInteger(file, level->yam_content[i][x][y],
+ BYTE_ORDER_BIG_ENDIAN);
+ else
+ fputc(level->yam_content[i][x][y], file);
+}
+#endif
+
+static void SaveLevel_BODY(struct LevelInfo *level, FILE *file)
+{
+ int x, y;
+
+ for(y=0; y<lev_fieldy; y++)
+ for(x=0; x<lev_fieldx; x++)
+ if (level->encoding_16bit_field)
+ putFile16BitInteger(file, Ur[x][y], BYTE_ORDER_BIG_ENDIAN);
+ else
+ fputc(Ur[x][y], file);
+}
+
+static void SaveLevel_CNT2(struct LevelInfo *level, FILE *file, int element)
+{
+ int i, x, y;
+ int num_contents, content_xsize, content_ysize;
+ int content_array[MAX_ELEMENT_CONTENTS][3][3];
+
+ if (element == EL_MAMPFER)
+ {
+ num_contents = level->num_yam_contents;
+ content_xsize = 3;
+ content_ysize = 3;
+
+ for(i=0; i<MAX_ELEMENT_CONTENTS; i++)