X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fsetup.c;h=412779d0bc8ca28a90cd62a4cd1388578b73938d;hb=31b462a53d66e5d4fb8701c2b7d31180af1f5f6d;hp=3ccc53524dcb5d49e88f0501750965570215e10c;hpb=6077980c61e1985fcc5ac969cd5e15e696498191;p=rocksndiamonds.git diff --git a/src/libgame/setup.c b/src/libgame/setup.c index 3ccc5352..412779d0 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -2603,7 +2603,11 @@ static void setTreeInfoToDefaultsFromParent(TreeInfo *ti, TreeInfo *parent) ti->last_level = 0; ti->level_group = FALSE; ti->handicap_level = 0; +#if 1 + ti->readonly = parent->readonly; +#else ti->readonly = TRUE; +#endif ti->handicap = TRUE; ti->skip_levels = FALSE; } @@ -2675,7 +2679,7 @@ static TreeInfo *getTreeInfoCopy(TreeInfo *ti) return ti_copy; } -static void freeTreeInfo(TreeInfo *ti) +void freeTreeInfo(TreeInfo *ti) { if (ti == NULL) return; @@ -3137,6 +3141,12 @@ static boolean LoadLevelInfoFromLevelConf(TreeInfo **node_first, leveldir_new->in_user_dir = (!strEqual(leveldir_new->basepath, options.level_directory)); +#if 0 + printf("::: '%s' -> %d\n", + leveldir_new->identifier, + leveldir_new->in_user_dir); +#endif + /* adjust some settings if user's private level directory was detected */ if (leveldir_new->sort_priority == LEVELCLASS_UNDEFINED && leveldir_new->in_user_dir && @@ -4019,10 +4029,17 @@ void LoadLevelSetup_SeriesInfo() char *filename; SetupFileHash *level_setup_hash = NULL; char *level_subdir = leveldir_current->subdir; + int i; /* always start with reliable default values */ level_nr = leveldir_current->first_level; + for (i = 0; i < MAX_LEVELS; i++) + { + LevelStats_setPlayed(i, 0); + LevelStats_setSolved(i, 0); + } + checkSeriesInfo(leveldir_current); /* ----------------------------------------------------------------------- */ @@ -4037,6 +4054,8 @@ void LoadLevelSetup_SeriesInfo() { char *token_value; + /* get last played level in this level set */ + token_value = getHashEntry(level_setup_hash, TOKEN_STR_LAST_PLAYED_LEVEL); if (token_value) @@ -4049,6 +4068,8 @@ void LoadLevelSetup_SeriesInfo() level_nr = leveldir_current->last_level; } + /* get handicap level in this level set */ + token_value = getHashEntry(level_setup_hash, TOKEN_STR_HANDICAP_LEVEL); if (token_value) @@ -4066,6 +4087,31 @@ void LoadLevelSetup_SeriesInfo() leveldir_current->handicap_level = level_nr; } + /* get number of played and solved levels in this level set */ + + BEGIN_HASH_ITERATION(level_setup_hash, itr) + { + char *token = HASH_ITERATION_TOKEN(itr); + char *value = HASH_ITERATION_VALUE(itr); + + if (strlen(token) == 3 && + token[0] >= '0' && token[0] <= '9' && + token[1] >= '0' && token[1] <= '9' && + token[2] >= '0' && token[2] <= '9') + { + int level_nr = atoi(token); + + if (value != NULL) + LevelStats_setPlayed(level_nr, atoi(value)); /* read 1st column */ + + value = strchr(value, ' '); + + if (value != NULL) + LevelStats_setSolved(level_nr, atoi(value)); /* read 2nd column */ + } + } + END_HASH_ITERATION(hash, itr) + checkSetupFileHashIdentifier(level_setup_hash, filename, getCookie("LEVELSETUP")); @@ -4084,6 +4130,7 @@ void SaveLevelSetup_SeriesInfo() char *level_nr_str = int2str(level_nr, 0); char *handicap_level_str = int2str(leveldir_current->handicap_level, 0); FILE *file; + int i; /* ----------------------------------------------------------------------- */ /* ~/./levelsetup//levelsetup.conf */ @@ -4104,8 +4151,24 @@ void SaveLevelSetup_SeriesInfo() getCookie("LEVELSETUP"))); fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_LAST_PLAYED_LEVEL, level_nr_str)); - fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_HANDICAP_LEVEL, - handicap_level_str)); + fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_HANDICAP_LEVEL, + handicap_level_str)); + + for (i = leveldir_current->first_level; i <= leveldir_current->last_level; + i++) + { + if (LevelStats_getPlayed(i) > 0 || + LevelStats_getSolved(i) > 0) + { + char token[16]; + char value[16]; + + sprintf(token, "%03d", i); + sprintf(value, "%d %d", LevelStats_getPlayed(i), LevelStats_getSolved(i)); + + fprintf(file, "%s\n", getFormattedSetupEntry(token, value)); + } + } fclose(file); @@ -4113,3 +4176,37 @@ void SaveLevelSetup_SeriesInfo() free(filename); } + +int LevelStats_getPlayed(int nr) +{ + return (nr >= 0 && nr < MAX_LEVELS ? level_stats[nr].played : 0); +} + +int LevelStats_getSolved(int nr) +{ + return (nr >= 0 && nr < MAX_LEVELS ? level_stats[nr].solved : 0); +} + +void LevelStats_setPlayed(int nr, int value) +{ + if (nr >= 0 && nr < MAX_LEVELS) + level_stats[nr].played = value; +} + +void LevelStats_setSolved(int nr, int value) +{ + if (nr >= 0 && nr < MAX_LEVELS) + level_stats[nr].solved = value; +} + +void LevelStats_incPlayed(int nr) +{ + if (nr >= 0 && nr < MAX_LEVELS) + level_stats[nr].played++; +} + +void LevelStats_incSolved(int nr) +{ + if (nr >= 0 && nr < MAX_LEVELS) + level_stats[nr].solved++; +}