#define LEVELCLASS_CONTRIBUTION_END 299
#define LEVELCLASS_USER_START 300
#define LEVELCLASS_USER_END 399
+
+#define LEVELCLASS_TUTORIAL LEVELCLASS_TUTORIAL_START
+#define LEVELCLASS_CLASSICS LEVELCLASS_CLASSICS_START
+#define LEVELCLASS_CONTRIBUTION LEVELCLASS_CONTRIBUTION_START
+#define LEVELCLASS_USER LEVELCLASS_USER_START
#define LEVELCLASS_UNDEFINED 999
+#define IS_LEVELCLASS_TUTORIAL(n) \
+ (leveldir[n].sort_priority >= LEVELCLASS_TUTORIAL_START && \
+ leveldir[n].sort_priority <= LEVELCLASS_TUTORIAL_END)
+#define IS_LEVELCLASS_CLASSICS(n) \
+ (leveldir[n].sort_priority >= LEVELCLASS_CLASSICS_START && \
+ leveldir[n].sort_priority <= LEVELCLASS_CLASSICS_END)
+#define IS_LEVELCLASS_CONTRIBUTION(n) \
+ (leveldir[n].sort_priority >= LEVELCLASS_CONTRIBUTION_START && \
+ leveldir[n].sort_priority <= LEVELCLASS_CONTRIBUTION_END)
+#define IS_LEVELCLASS_USER(n) \
+ (leveldir[n].sort_priority >= LEVELCLASS_USER_START && \
+ leveldir[n].sort_priority <= LEVELCLASS_USER_END)
+
+#define LEVELCLASS(n) (IS_LEVELCLASS_TUTORIAL(n) ? LEVELCLASS_TUTORIAL : \
+ IS_LEVELCLASS_CLASSICS(n) ? LEVELCLASS_CLASSICS : \
+ IS_LEVELCLASS_CONTRIBUTION(n) ? LEVELCLASS_CONTRIBUTION : \
+ IS_LEVELCLASS_USER(n) ? LEVELCLASS_USER : \
+ LEVELCLASS_UNDEFINED)
+
static void SaveUserLevelInfo(); /* for 'InitUserLevelDir()' */
static char *getSetupLine(char *, int); /* for 'SaveUserLevelInfo()' */
}
}
+static void getFileChunk(FILE *file, char *chunk_buffer, int *chunk_length)
+{
+ fgets(chunk_buffer, CHUNK_ID_LEN + 1, file);
+
+ *chunk_length =
+ (fgetc(file) << 24) |
+ (fgetc(file) << 16) |
+ (fgetc(file) << 8) |
+ (fgetc(file) << 0);
+}
+
+static void putFileChunk(FILE *file, char *chunk_name, int chunk_length)
+{
+ fputs(chunk_name, file);
+
+ fputc((chunk_length >> 24) & 0xff, file);
+ fputc((chunk_length >> 16) & 0xff, file);
+ fputc((chunk_length >> 8) & 0xff, file);
+ fputc((chunk_length >> 0) & 0xff, file);
+}
+
static void setLevelInfoToDefaults()
{
int i, x, y;
level.high_speed = FALSE;
- strcpy(level.name, "Nameless Level");
+ for(i=0; i<MAX_LEVEL_NAME_LEN; i++)
+ level.name[i] = '\0';
+ for(i=0; i<MAX_LEVEL_AUTHOR_LEN; i++)
+ level.author[i] = '\0';
+
+ strcpy(level.name, NAMELESS_LEVEL_NAME);
+ strcpy(level.author, ANONYMOUS_NAME);
for(i=0; i<LEVEL_SCORE_ELEMENTS; i++)
level.score[i] = 10;
Ur[STD_LEV_FIELDX-1][STD_LEV_FIELDY-1] = EL_AUSGANG_ZU;
BorderElement = EL_BETON;
+
+ /* try to determine better author name than 'anonymous' */
+ if (strcmp(leveldir[leveldir_nr].author, ANONYMOUS_NAME) != 0)
+ {
+ strncpy(level.author, leveldir[leveldir_nr].author, MAX_LEVEL_AUTHOR_LEN);
+ level.author[MAX_LEVEL_AUTHOR_LEN] = '\0';
+ }
+ else
+ {
+ switch (LEVELCLASS(leveldir_nr))
+ {
+ case LEVELCLASS_TUTORIAL:
+ strcpy(level.author, PROGRAM_AUTHOR_STRING);
+ break;
+
+ case LEVELCLASS_CONTRIBUTION:
+ strncpy(level.author, leveldir[leveldir_nr].name,MAX_LEVEL_AUTHOR_LEN);
+ level.author[MAX_LEVEL_AUTHOR_LEN] = '\0';
+ break;
+
+ case LEVELCLASS_USER:
+ strncpy(level.author, getRealName(), MAX_LEVEL_AUTHOR_LEN);
+ level.author[MAX_LEVEL_AUTHOR_LEN] = '\0';
+ break;
+
+ default:
+ /* keep default value */
+ break;
+ }
+ }
}
void LoadLevel(int level_nr)
/* read chunk "HEAD" */
if (file_version >= FILE_VERSION_1_2)
{
- /* first check header chunk identifier and chunk length */
- fgets(chunk, CHUNK_ID_LEN + 1, file);
- chunk_length =
- (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
+ getFileChunk(file, chunk, &chunk_length);
if (strcmp(chunk, "HEAD") || chunk_length != LEVEL_HEADER_SIZE)
{
Error(ERR_WARN, "wrong 'HEAD' chunk of level file '%s'", filename);
level.time = (fgetc(file)<<8) | fgetc(file);
level.edelsteine = (fgetc(file)<<8) | fgetc(file);
- for(i=0; i<MAX_LEVNAMLEN; i++)
+ for(i=0; i<MAX_LEVEL_NAME_LEN; i++)
level.name[i] = fgetc(file);
- level.name[MAX_LEVNAMLEN - 1] = 0;
+ level.name[MAX_LEVEL_NAME_LEN] = 0;
for(i=0; i<LEVEL_SCORE_ELEMENTS; i++)
level.score[i] = fgetc(file);
/* read chunk "BODY" */
if (file_version >= FILE_VERSION_1_2)
{
- fgets(chunk, CHUNK_ID_LEN + 1, file);
- chunk_length =
- (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
+ getFileChunk(file, chunk, &chunk_length);
+
+ /* look for optional author chunk */
+ if (strcmp(chunk, "AUTH") == 0 && chunk_length == MAX_LEVEL_AUTHOR_LEN)
+ {
+ for(i=0; i<MAX_LEVEL_AUTHOR_LEN; i++)
+ level.author[i] = fgetc(file);
+ level.author[MAX_LEVEL_NAME_LEN] = 0;
+
+ getFileChunk(file, chunk, &chunk_length);
+ }
/* look for optional content chunk */
if (strcmp(chunk, "CONT") == 0 && chunk_length == 4 + 8 * 3 * 3)
for(x=0; x<3; x++)
level.mampfer_inhalt[i][x][y] = fgetc(file);
- fgets(chunk, CHUNK_ID_LEN + 1, file);
- chunk_length =
- (fgetc(file)<<24) | (fgetc(file)<<16) | (fgetc(file)<<8) | fgetc(file);
+ getFileChunk(file, chunk, &chunk_length);
}
/* next check body chunk identifier and chunk length */
}
}
+ /* clear all other level fields (needed if resized in level editor later) */
+ for(x=0; x<MAX_LEV_FIELDX; x++)
+ for(y=0; y<MAX_LEV_FIELDY; y++)
+ Feld[x][y] = Ur[x][y] = EL_LEERRAUM;
+
+ /* now read in the valid level fields from level file */
for(y=0; y<lev_fieldy; y++)
for(x=0; x<lev_fieldx; x++)
Feld[x][y] = Ur[x][y] = fgetc(file);
fclose(file);
-#if 0
- if (level.time <= 10) /* minimum playing time of each level */
- level.time = 10;
-#endif
-
+ /* player was faster than monsters in pre-1.0 levels */
if (file_version == FILE_VERSION_1_0 &&
- leveldir[leveldir_nr].sort_priority >= LEVELCLASS_CONTRIBUTION_START &&
- leveldir[leveldir_nr].sort_priority <= LEVELCLASS_CONTRIBUTION_END)
+ IS_LEVELCLASS_CONTRIBUTION(leveldir_nr))
{
Error(ERR_WARN, "level file '%s' has version number 1.0", filename);
Error(ERR_WARN, "using high speed movement for player");
level.high_speed = TRUE;
}
-
- /* determine border element */
- BorderElement = EL_LEERRAUM;
- for(y=0; y<lev_fieldy && BorderElement == EL_LEERRAUM; y++)
- {
- for(x=0; x<lev_fieldx; x++)
- {
- if (!IS_MASSIVE(Feld[x][y]))
- BorderElement = EL_BETON;
-
- if (y != 0 && y != lev_fieldy - 1 && x != lev_fieldx - 1)
- x = lev_fieldx - 2;
- }
- }
}
void SaveLevel(int level_nr)
int i, x, y;
char *filename = getLevelFilename(level_nr);
FILE *file;
- int chunk_length;
if (!(file = fopen(filename, "w")))
{
fputs(LEVEL_COOKIE, file); /* file identifier */
fputc('\n', file);
- fputs("HEAD", file); /* chunk identifier for file header */
-
- chunk_length = LEVEL_HEADER_SIZE;
-
- fputc((chunk_length >> 24) & 0xff, file);
- fputc((chunk_length >> 16) & 0xff, file);
- fputc((chunk_length >> 8) & 0xff, file);
- fputc((chunk_length >> 0) & 0xff, file);
+ putFileChunk(file, "HEAD", LEVEL_HEADER_SIZE);
fputc(level.fieldx, file);
fputc(level.fieldy, file);
fputc(level.edelsteine / 256, file);
fputc(level.edelsteine % 256, file);
- for(i=0; i<MAX_LEVNAMLEN; i++)
+ 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<LEVEL_HEADER_UNUSED; i++) /* set unused header bytes to zero */
fputc(0, file);
- fputs("CONT", file); /* chunk identifier for contents */
+ putFileChunk(file, "AUTH", MAX_LEVEL_AUTHOR_LEN);
- chunk_length = 4 + 8 * 3 * 3;
+ for(i=0; i<MAX_LEVEL_AUTHOR_LEN; i++)
+ fputc(level.author[i], file);
- fputc((chunk_length >> 24) & 0xff, file);
- fputc((chunk_length >> 16) & 0xff, file);
- fputc((chunk_length >> 8) & 0xff, file);
- fputc((chunk_length >> 0) & 0xff, file);
+ putFileChunk(file, "CONT", 4 + 8 * 3 * 3);
fputc(EL_MAMPFER, file);
fputc(MampferMax, file);
for(x=0; x<3; x++)
fputc(level.mampfer_inhalt[i][x][y], file);
- fputs("BODY", file); /* chunk identifier for file body */
- chunk_length = lev_fieldx * lev_fieldy;
-
- fputc((chunk_length >> 24) & 0xff, file);
- fputc((chunk_length >> 16) & 0xff, file);
- fputc((chunk_length >> 8) & 0xff, file);
- fputc((chunk_length >> 0) & 0xff, file);
+ putFileChunk(file, "BODY", lev_fieldx * lev_fieldy);
for(y=0; y<lev_fieldy; y++)
for(x=0; x<lev_fieldx; x++)
/* level directory info */
#define LEVELINFO_TOKEN_NAME 29
-#define LEVELINFO_TOKEN_LEVELS 30
-#define LEVELINFO_TOKEN_FIRST_LEVEL 31
-#define LEVELINFO_TOKEN_SORT_PRIORITY 32
-#define LEVELINFO_TOKEN_READONLY 33
+#define LEVELINFO_TOKEN_AUTHOR 30
+#define LEVELINFO_TOKEN_LEVELS 31
+#define LEVELINFO_TOKEN_FIRST_LEVEL 32
+#define LEVELINFO_TOKEN_SORT_PRIORITY 33
+#define LEVELINFO_TOKEN_READONLY 34
#define FIRST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_PLAYER_NAME
#define LAST_GLOBAL_SETUP_TOKEN SETUP_TOKEN_TEAM_MODE
/* level directory info */
{ TYPE_STRING, &ldi.name, "name" },
+ { TYPE_STRING, &ldi.author, "author" },
{ TYPE_INTEGER, &ldi.levels, "levels" },
{ TYPE_INTEGER, &ldi.first_level, "first_level" },
{ TYPE_INTEGER, &ldi.sort_priority, "sort_priority" },
static void setLevelDirInfoToDefaults(struct LevelDirInfo *ldi)
{
- ldi->name = getStringCopy("non-existing");
+ ldi->name = getStringCopy(ANONYMOUS_NAME);
+ ldi->author = getStringCopy(ANONYMOUS_NAME);
ldi->levels = 0;
ldi->first_level = 0;
ldi->sort_priority = LEVELCLASS_UNDEFINED; /* default: least priority */
{
char *token_value;
int level_series_nr = getLevelSeriesNrFromLevelSeriesName(level_series_name);
- int last_level_nr = 0;
+ int last_level_nr = leveldir[level_series_nr].first_level;
if (!level_series_name)
return 0;
return;
}
+ /* always start with reliable default values */
+ setLevelDirInfoToDefaults(&ldi);
+
ldi.name = getLoginName();
+ ldi.author = getRealName();
ldi.levels = 100;
- ldi.first_level = 0;
+ ldi.first_level = 1;
ldi.sort_priority = LEVELCLASS_USER_START;
ldi.readonly = FALSE;