}
static int set_load(struct set *s, const char *filename)
-/* Count levels */
{
FILE *fin;
- char buf[MAXSTR];
- int res = 0;
- /* Open the datafile */
+ char buf[MAXSTR];
+ int res;
- fin = fopen(filename, "r");
- if (fin == NULL)
+ fin = fopen(config_data(filename), "r");
+ if (!fin)
{
fprintf(stderr, _("Cannot load the set file '%s':"), filename);
perror(NULL);
return 0;
}
- /* Raz the set structure */
-
- memset(s, 0, sizeof(struct set));
+ memset(s, 0, sizeof (struct set));
/* Set some sane values in case the scores hs is missing. */
score_init_hs(&s->time_score, 359999, 0);
score_init_hs(&s->coin_score, 359999, 0);
- /* Load set metadata */
+ /* Load set metadata. */
+
+ strcpy(s->file, config_data(filename));
- strcpy(s->file, filename);
if ((res = fgets(buf, MAXSTR, fin) != NULL))
strcpy(s->name, chomp(buf));
if (res && (res = fgets(buf, MAXSTR, fin) != NULL))
&s->coin_score.coins[0],
&s->coin_score.coins[1],
&s->coin_score.coins[2]);
+
strcpy(s->user_scores, "neverballhs-");
strcat(s->user_scores, s->setname);
- /* Count levels levels. */
+ /* Count levels. */
s->count = 0;
while (s->count < MAXLVL && (fscanf(fin, "%s", buf) == 1))
s->count++;
- /* Close the file, since it's no more needed */
-
fclose(fin);
/* Load the levels states (stored in the user highscore file) */
+
s->locked = s->count;
s->completed = 0;
+
if ((fin = fopen(config_user(s->user_scores), "r")))
{
char states[MAXLVL + 1];
void set_init()
{
- FILE *fin;
struct set *set;
+ FILE *fin;
+
char filename[MAXSTR];
int res;
while (count < MAXSET && res)
{
set = &(set_v[count]);
-
- /* clean the set data */
-
res = (fgets(filename, MAXSTR, fin) != NULL);
+
if (res)
{
chomp(filename);
- res = set_load(set, config_data(filename));
+ res = set_load(set, filename);
if (res)
{
set->number = count;
/*---------------------------------------------------------------------------*/
static void set_load_levels(void)
-/* Load more the levels of the current set */
{
FILE *fin;
+ struct level *l;
+
char buf[MAXSTR];
char name[MAXSTR];
- struct level *l;
int i = 0, res;
int nb = 1, bnb = 1;
- fin = fopen(current_set->file, "r");
- assert(fin != NULL);
+ if ((fin = fopen(current_set->file, "r")))
+ {
+ res = 1;
- res = 1;
+ /* Skip the five first lines */
+ for (i = 0; i < 5; i++)
+ fgets(buf, MAXSTR, fin);
- /* Skip the five first lines */
- for(i = 0; i < 5; i++)
- fgets(buf, MAXSTR, fin);
+ for (i = 0; i < current_set->count && res; i++)
+ {
+ l = &level_v[i];
- for(i = 0; i < current_set->count && res; i++)
- {
- l = &level_v[i];
- res = (fscanf(fin, "%s", name) == 1);
- assert(res);
+ res = (fscanf(fin, "%s", name) == 1);
+ assert(res);
- level_load(config_data(name), l);
+ level_load(config_data(name), l);
- /* Initialize set related info */
- l->set = current_set;
- l->number = i;
- if (l->is_bonus)
- sprintf(l->numbername, _("B%d"), bnb++);
- else
- sprintf(l->numbername, "%02d", nb++);
- l->is_locked = 1;
- l->is_completed = 0;
+ /* Initialize set related info */
+ l->set = current_set;
+ l->number = i;
+ if (l->is_bonus)
+ sprintf(l->numbername, _("B%d"), bnb++);
+ else
+ sprintf(l->numbername, "%02d", nb++);
+ l->is_locked = 1;
+ l->is_completed = 0;
+ }
+ level_v[0].is_locked = 0; /* unlock the first level */
+ fclose(fin);
}
- level_v[0].is_locked = 0; /* unlock the first level */
- fclose(fin);
+
assert(i == current_set->count);
}
void set_goto(int i)
{
- assert(set_exists(i));
current_set = &set_v[i];
set_load_levels();
set_load_hs();