Import from neverball-1.3.1.tar.gz
[neverball-archive.git] / ball / set.c
blob7f80eb1889899fd4f8631917a2506e50341bc074
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];
36 GLuint text;
39 static int set_state = 0;
41 static int set;
42 static int count;
44 static struct set set_v[MAXSET];
46 /*---------------------------------------------------------------------------*/
48 void set_init()
50 FILE *fin;
52 if (set_state)
53 set_free();
55 count = 0;
57 if ((fin = fopen(config_data(SET_FILE), "r")))
59 while (fscanf(fin, "%s %s %s %s\n",
60 set_v[count].init_levels,
61 set_v[count].init_scores,
62 set_v[count].user_scores,
63 set_v[count].shot) == 4 &&
64 fgets(set_v[count].name, MAXSTR, fin) &&
65 fgets(set_v[count].desc, MAXSTR, fin))
67 char *p = set_v[count].name + strlen(set_v[count].name) - 1;
68 char *q = set_v[count].desc + strlen(set_v[count].desc) - 1;
70 if (*p == '\n') *p = 0;
71 if (*q == '\n') *q = 0;
73 count++;
76 fclose(fin);
78 set_state = 1;
82 int set_exists(int i)
84 return (0 <= i && i < count);
87 void set_goto(int i)
89 level_init(set_v[i].init_levels,
90 set_v[i].init_scores,
91 set_v[i].user_scores);
92 set = i;
95 int set_curr(void)
97 return set;
100 void set_free()
102 int i;
104 for (i = 0; i < count; i++)
105 if (glIsTexture(set_v[i].text))
107 glDeleteTextures(1, &set_v[i].text);
108 set_v[i].text = 0;
111 level_free();
113 set_state = 0;
116 /*---------------------------------------------------------------------------*/
118 const char *set_name(int i)
120 return (0 <= i && i < count) ? set_v[i].name : "";
123 const char *set_desc(int i)
125 return (0 <= i && i < count) ? set_v[i].desc : "";
128 const char *set_shot(int i)
130 if (0 <= i && i < count)
131 return set_v[i].shot;
132 else
133 return set_v[0].shot;
136 /*---------------------------------------------------------------------------*/