// (c) 1994-2017 by Artsoft Entertainment
// Holger Schemel
// info@artsoft.org
-// http://www.artsoft.org/
+// https://www.artsoft.org/
// ----------------------------------------------------------------------------
// mm_files.c
// ============================================================================
#include "mm_main.h"
-#define CHUNK_ID_LEN 4 /* IFF style chunk id length */
-#define CHUNK_SIZE_UNDEFINED 0 /* undefined chunk size == 0 */
-#define CHUNK_SIZE_NONE -1 /* do not write chunk size */
-#define FILE_VERS_CHUNK_SIZE 8 /* size of file version chunk */
-#define LEVEL_HEADER_SIZE 80 /* size of level file header */
-#define LEVEL_HEADER_UNUSED 19 /* unused level header bytes */
+#define CHUNK_ID_LEN 4 // IFF style chunk id length
+#define CHUNK_SIZE_UNDEFINED 0 // undefined chunk size == 0
+#define CHUNK_SIZE_NONE -1 // do not write chunk size
+#define FILE_VERS_CHUNK_SIZE 8 // size of file version chunk
+#define LEVEL_HEADER_SIZE 80 // size of level file header
+#define LEVEL_HEADER_UNUSED 19 // unused level header bytes
-/* file identifier strings */
+// file identifier strings
#define LEVEL_COOKIE_TMPL "MIRRORMAGIC_LEVEL_FILE_VERSION_x.x"
#define SCORE_COOKIE "MIRRORMAGIC_SCORE_FILE_VERSION_1.4"
};
-/* ========================================================================= */
-/* level file functions */
-/* ========================================================================= */
+// ============================================================================
+// level file functions
+// ============================================================================
static void ReadChunk_MM_VERS(File *file, int *file_version, int *game_version)
{
file_version_major = getFile8Bit(file);
file_version_minor = getFile8Bit(file);
file_version_patch = getFile8Bit(file);
- getFile8Bit(file); /* not used */
+ getFile8Bit(file); // not used
game_version_major = getFile8Bit(file);
game_version_minor = getFile8Bit(file);
game_version_patch = getFile8Bit(file);
- getFile8Bit(file); /* not used */
+ getFile8Bit(file); // not used
*file_version = MM_VERSION_IDENT(file_version_major,
file_version_minor,
fputc(file_version_major, file);
fputc(file_version_minor, file);
fputc(file_version_patch, file);
- fputc(0, file); /* not used */
+ fputc(0, file); // not used
fputc(game_version_major, file);
fputc(game_version_minor, file);
fputc(game_version_patch, file);
- fputc(0, file); /* not used */
+ fputc(0, file); // not used
}
-void setLevelInfoToDefaults_MM()
+void setLevelInfoToDefaults_MM(void)
{
int i, x, y;
native_mm_level.file_version = MM_FILE_VERSION_ACTUAL;
native_mm_level.game_version = MM_GAME_VERSION_ACTUAL;
- native_mm_level.encoding_16bit_field = FALSE; /* default: only 8-bit elements */
+ native_mm_level.encoding_16bit_field = FALSE; // default: only 8-bit elements
native_mm_level.fieldx = STD_LEV_FIELDX;
native_mm_level.fieldy = STD_LEV_FIELDY;
{
if (element >= EL_FIRST_RUNTIME_EL)
{
- Error(ERR_WARN, "invalid level element %d", element);
+ Warn("invalid level element %d", element);
+
element = EL_CHAR_FRAGE;
}
{ NULL, 0, NULL }
};
- /* always start with reliable default values */
+ // always start with reliable default values
setLevelInfoToDefaults_MM();
if (!(file = openFile(filename, MODE_READ)))
{
if (!level_info_only)
- Error(ERR_WARN, "cannot read level '%s' - creating new level", filename);
+ Warn("cannot read level '%s' - creating new level", filename);
return FALSE;
}
getFileChunk(file, chunk_name, NULL, BYTE_ORDER_BIG_ENDIAN);
if (strcmp(chunk_name, "MMII") == 0)
{
- getFile32BitInteger(file, BYTE_ORDER_BIG_ENDIAN); /* not used */
+ getFile32BitInteger(file, BYTE_ORDER_BIG_ENDIAN); // not used
getFileChunk(file, chunk_name, NULL, BYTE_ORDER_BIG_ENDIAN);
if (strcmp(chunk_name, "CAVE") != 0)
{
- Error(ERR_WARN, "unknown format of level file '%s'", filename);
+ Warn("unknown format of level file '%s'", filename);
closeFile(file);
return FALSE;
}
}
- else /* check for pre-2.0 file format with cookie string */
+ else // check for pre-2.0 file format with cookie string
{
strcpy(cookie, chunk_name);
getStringFromFile(file, &cookie[4], MAX_LINE_LEN - 4);
if (!checkCookieString(cookie, LEVEL_COOKIE_TMPL))
{
- Error(ERR_WARN, "unknown format of level file '%s'", filename);
+ Warn("unknown format of level file '%s'", filename);
closeFile(file);
if ((native_mm_level.file_version = getFileVersionFromCookieString(cookie))
== -1)
{
- Error(ERR_WARN, "unsupported version of level file '%s'", filename);
+ Warn("unsupported version of level file '%s'", filename);
closeFile(file);
if (chunk_info[i].name == NULL)
{
- Error(ERR_WARN, "unknown chunk '%s' in level file '%s'",
+ Warn("unknown chunk '%s' in level file '%s'",
chunk_name, filename);
ReadUnusedBytesFromFile(file, chunk_size);
else if (chunk_info[i].size != -1 &&
chunk_info[i].size != chunk_size)
{
- Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'",
+ Warn("wrong size (%d) of chunk '%s' in level file '%s'",
chunk_size, chunk_name, filename);
ReadUnusedBytesFromFile(file, chunk_size);
}
else
{
- /* call function to load this level chunk */
+ // call function to load this level chunk
int chunk_size_expected =
(chunk_info[i].loader)(file, chunk_size, &native_mm_level);
- /* the size of some chunks cannot be checked before reading other
- chunks first (like "HEAD" and "BODY") that contain some header
- information, so check them here */
+ // the size of some chunks cannot be checked before reading other
+ // chunks first (like "HEAD" and "BODY") that contain some header
+ // information, so check them here
if (chunk_size_expected != chunk_size)
- Error(ERR_WARN, "wrong size (%d) of chunk '%s' in level file '%s'",
+ Warn("wrong size (%d) of chunk '%s' in level file '%s'",
chunk_size, chunk_name, filename);
}
}
if (!(file = fopen(filename, MODE_WRITE)))
{
- Error(ERR_WARN, "cannot save level file '%s'", filename);
+ Warn("cannot save level file '%s'", filename);
return;
}
- /* check level field for 16-bit elements */
+ // check level field for 16-bit elements
native_mm_level.encoding_16bit_field = FALSE;
for (y = 0; y < native_mm_level.fieldy; y++)