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)
29 strcpy(s->player[0], "Hard");
30 strcpy(s->player[1], "Medium");
31 strcpy(s->player[2], "Easy");
32 strcpy(s->player[3], "");
33 for (i = 0; i < NSCORE + 1; i++)
40 /*---------------------------------------------------------------------------*/
42 static int level_scan_metadata(struct level *l, char *av)
44 #define CASE(x) (strcmp((x), c) == 0)
46 char *stop = av + strlen(av);
51 /* look for the start of the value */
58 /* look the end of the value */
67 strcpy(l->message, v);
68 else if (CASE("back"))
70 else if (CASE("song"))
72 else if (CASE("grad"))
74 else if (CASE("shot"))
76 else if (CASE("goal"))
79 l->coin_score.coins[2] = l->goal;
81 else if (CASE("time"))
84 l->time_score.timer[2] = l->time;
85 l->goal_score.timer[2] = l->time;
87 else if (CASE("time_hs"))
89 &l->time_score.timer[0],
90 &l->time_score.timer[1]);
91 else if (CASE("goal_hs"))
93 &l->goal_score.timer[0],
94 &l->goal_score.timer[1]);
95 else if (CASE("coin_hs"))
97 &l->coin_score.coins[0],
98 &l->coin_score.coins[1]);
99 else if (CASE("levelname"))
101 else if (CASE("version"))
102 l->version = atoi(v);
103 else if (CASE("author"))
104 strcpy(l->author, v);
105 else if (CASE("special"))
106 l->is_bonus = atoi(v);
113 /* Load the sol file 'filename' and fill the 'level' structure. Return 1 on
114 * success, 0 on error. */
116 int level_load(const char *filename, struct level *level)
123 memset(level, 0, sizeof (struct level));
124 memset(&sol, 0, sizeof (sol));
126 /* Try to load the sol file */
127 if (!sol_load_only_file(&sol, filename))
129 fprintf(stderr, _("Error while loading level file '%s': "), filename);
133 fprintf(stderr, _("Not a valid level file\n"));
138 strcpy(level->file, filename);
140 /* Init hs with default values */
141 score_init_hs(&level->time_score, 59999, 0);
142 score_init_hs(&level->goal_score, 59999, 0);
143 score_init_hs(&level->coin_score, 59999, 0);
145 /* Compute money and default max money */
147 for (i = 0; i < sol.cc; i++)
148 money += sol.cv[i].n;
149 level->coin_score.coins[0] = money;
151 /* Scan sol metadata */
153 level_scan_metadata(level, sol.av);
155 /* Compute initial hs default values */
159 t[0] = t[1] = t[2]; \
160 else if (t[2] c t[1]) \
161 t[1] = (t[0] + t[2]) / 2
163 HOP(level->time_score.timer, <=);
164 HOP(level->goal_score.timer, <=);
165 HOP(level->coin_score.coins, >=);
167 /* Free the sol structure, no more needed */
173 /*---------------------------------------------------------------------------*/
175 void level_dump_info(const struct level *l)
176 /* This function dumps the info of a demo structure
177 * It's only a function for debugging, no need of I18N */
179 printf("filename: %s\n"
185 "time hs: %d %d %d\n"
186 "goal hs: %d %d %d\n"
187 "coin hs: %d %d %d\n"
193 l->file, l->name, l->version, l->author,
195 l->time_score.timer[0],
196 l->time_score.timer[1],
197 l->time_score.timer[2],
198 l->goal_score.timer[0],
199 l->goal_score.timer[1],
200 l->goal_score.timer[2],
201 l->coin_score.coins[0],
202 l->coin_score.coins[1],
203 l->coin_score.coins[2],
204 l->message, l->back, l->grad, l->shot, l->song);
207 /*---------------------------------------------------------------------------*/
209 const char *mode_to_str(int m)
213 case MODE_CHALLENGE: return _("Challenge");
214 case MODE_NORMAL: return _("Normal");
215 case MODE_PRACTICE: return _("Practice");
216 case MODE_SINGLE: return _("Single");
217 default: return "???";
221 /*---------------------------------------------------------------------------*/
223 const char *state_to_str(int m)
227 case GAME_NONE: return _("Aborted");
228 case GAME_TIME: return _("Time-out");
230 case GAME_GOAL: return _("Success");
231 case GAME_FALL: return _("Fall-out");
232 default: return "???";
236 /*---------------------------------------------------------------------------*/