Import from neverball-1.4.0.tar.gz
[neverball-archive.git] / ball / set.c
blob603832ce5d1054691f5551af2d93a854ba533786
1 /*
2 * Copyright (C) 2003 Robert Kooima
4 * NEVERBALL is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published
6 * by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
15 #include <stdio.h>
16 #include <string.h>
18 #include "glext.h"
19 #include "config.h"
20 #include "image.h"
21 #include "level.h"
22 #include "set.h"
24 /*---------------------------------------------------------------------------*/
26 struct set
28 char init_levels[MAXSTR];
29 char init_scores[MAXSTR];
30 char user_scores[MAXSTR];
32 char shot[MAXSTR];
33 char name[MAXSTR];
34 char desc[MAXSTR];
37 static int set_state = 0;
39 static int set;
40 static int count;
42 static struct set set_v[MAXSET];
44 /*---------------------------------------------------------------------------*/
46 void set_init()
48 FILE *fin;
50 if (set_state)
51 set_free();
53 count = 0;
55 if ((fin = fopen(config_data(SET_FILE), "r")))
57 while (fscanf(fin, "%s %s %s %s\n",
58 set_v[count].init_levels,
59 set_v[count].init_scores,
60 set_v[count].user_scores,
61 set_v[count].shot) == 4 &&
62 fgets(set_v[count].name, MAXSTR, fin) &&
63 fgets(set_v[count].desc, MAXSTR, fin))
65 char *p = set_v[count].name + strlen(set_v[count].name) - 1;
66 char *q = set_v[count].desc + strlen(set_v[count].desc) - 1;
68 if (*p == '\n') *p = 0;
69 if (*q == '\n') *q = 0;
71 count++;
74 fclose(fin);
76 set_state = 1;
80 int set_exists(int i)
82 return (0 <= i && i < count);
85 void set_goto(int i)
87 level_init(set_v[i].init_levels,
88 set_v[i].init_scores,
89 set_v[i].user_scores);
90 set = i;
93 int set_curr(void)
95 return set;
98 void set_free(void)
100 level_free();
101 set_state = 0;
104 /*---------------------------------------------------------------------------*/
106 const char *set_name(int i)
108 return set_exists(i) ? set_v[i].name : "";
111 const char *set_desc(int i)
113 return set_exists(i) ? set_v[i].desc : "";
116 const char *set_shot(int i)
118 return set_exists(i) ? set_v[i].shot : set_v[0].shot;
121 /*---------------------------------------------------------------------------*/