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.
24 /*---------------------------------------------------------------------------*/
26 void score_init_hs(struct score *s, int timer, int coins)
30 strcpy(s->player[0], "Hard");
31 strcpy(s->player[1], "Medium");
32 strcpy(s->player[2], "Easy");
33 strcpy(s->player[3], "");
35 for (i = 0; i < NSCORE + 1; i++)
42 /*---------------------------------------------------------------------------*/
44 static int level_scan_metadata(struct level *l, char *av)
46 #define CASE(x) (strcmp((x), c) == 0)
48 char *stop = av + strlen(av);
53 /* look for the start of the value */
60 /* look the end of the value */
69 strcpy(l->message, v);
70 else if (CASE("back"))
72 else if (CASE("song"))
74 else if (CASE("grad"))
76 else if (CASE("shot"))
78 else if (CASE("goal"))
81 l->coin_score.coins[2] = l->goal;
83 else if (CASE("time"))
86 l->time_score.timer[2] = l->time;
87 l->goal_score.timer[2] = l->time;
89 else if (CASE("time_hs"))
91 &l->time_score.timer[0],
92 &l->time_score.timer[1]);
93 else if (CASE("goal_hs"))
95 &l->goal_score.timer[0],
96 &l->goal_score.timer[1]);
97 else if (CASE("coin_hs"))
99 &l->coin_score.coins[0],
100 &l->coin_score.coins[1]);
101 else if (CASE("levelname"))
103 else if (CASE("version"))
104 l->version = atoi(v);
105 else if (CASE("author"))
106 strcpy(l->author, v);
107 else if (CASE("special"))
108 l->is_bonus = atoi(v);
115 /* Load the sol file 'filename' and fill the 'level' structure. Return 1 on
116 * success, 0 on error. */
118 int level_load(const char *filename, struct level *level)
125 memset(level, 0, sizeof (struct level));
126 memset(&sol, 0, sizeof (sol));
128 /* Try to load the sol file */
129 if (!sol_load_only_file(&sol, filename))
132 _("Error while loading level file '%s': %s\n"), filename,
133 errno ? strerror(errno) : _("Not a valid level file"));
137 strcpy(level->file, filename);
139 /* Init hs with default values */
140 score_init_hs(&level->time_score, 59999, 0);
141 score_init_hs(&level->goal_score, 59999, 0);
142 score_init_hs(&level->coin_score, 59999, 0);
144 /* Compute money and default max money */
146 for (i = 0; i < sol.cc; i++)
147 money += sol.cv[i].n;
148 level->coin_score.coins[0] = money;
150 /* Scan sol metadata */
152 level_scan_metadata(level, sol.av);
154 /* Compute initial hs default values */
158 t[0] = t[1] = t[2]; \
159 else if (t[2] c t[1]) \
160 t[1] = (t[0] + t[2]) / 2
162 HOP(level->time_score.timer, <=);
163 HOP(level->goal_score.timer, <=);
164 HOP(level->coin_score.coins, >=);
171 /*---------------------------------------------------------------------------*/
173 void level_dump_info(const struct level *l)
174 /* This function dumps the info of a demo structure
175 * It's only a function for debugging, no need of I18N */
177 printf("filename: %s\n"
183 "time hs: %d %d %d\n"
184 "goal hs: %d %d %d\n"
185 "coin hs: %d %d %d\n"
191 l->file, l->name, l->version, l->author,
193 l->time_score.timer[0],
194 l->time_score.timer[1],
195 l->time_score.timer[2],
196 l->goal_score.timer[0],
197 l->goal_score.timer[1],
198 l->goal_score.timer[2],
199 l->coin_score.coins[0],
200 l->coin_score.coins[1],
201 l->coin_score.coins[2],
202 l->message, l->back, l->grad, l->shot, l->song);
205 /*---------------------------------------------------------------------------*/
207 const char *mode_to_str(int m)
211 case MODE_CHALLENGE: return _("Challenge");
212 case MODE_NORMAL: return _("Normal");
213 case MODE_PRACTICE: return _("Practice");
214 case MODE_SINGLE: return _("Single");
215 default: return _("Unknown");
219 /*---------------------------------------------------------------------------*/
221 const char *state_to_str(int m)
225 case GAME_NONE: return _("Aborted");
226 case GAME_TIME: return _("Time-out");
228 case GAME_GOAL: return _("Success");
229 case GAME_FALL: return _("Fall-out");
230 default: return _("Unknown");
234 /*---------------------------------------------------------------------------*/