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);
50 /* look for the start of the value */
57 /* look the end of the value */
66 strcpy(l->message, v);
67 else if (CASE("back"))
69 else if (CASE("song"))
71 else if (CASE("grad"))
73 else if (CASE("shot"))
75 else if (CASE("goal"))
78 l->coin_score.coins[2] = l->goal;
80 else if (CASE("time"))
83 l->time_score.timer[2] = l->time;
84 l->goal_score.timer[2] = l->time;
86 else if (CASE("time_hs"))
88 &l->time_score.timer[0],
89 &l->time_score.timer[1]);
90 else if (CASE("goal_hs"))
92 &l->goal_score.timer[0],
93 &l->goal_score.timer[1]);
94 else if (CASE("coin_hs"))
96 &l->coin_score.coins[0],
97 &l->coin_score.coins[1]);
98 else if (CASE("levelname"))
100 else if (CASE("version"))
101 l->version = atoi(v);
102 else if (CASE("author"))
103 strcpy(l->author, v);
104 else if (CASE("special"))
105 l->is_bonus = atoi(v);
107 fprintf(stderr, "File %s, ignore %s metadata.\n", l->file, c);*/
114 int level_load(const char *filename, struct level *level)
115 /* Load the sol file 'filename' and fill the 'level' structure
116 * return 1 on success, 0 on error */
118 struct s_file sol; /* The solid file data */
120 int money; /* sum of coin value */
123 memset(level, 0, sizeof(struct level));
125 memset(&sol, 0, sizeof(sol));
127 /* Try to load the sol file */
128 if (!sol_load_only_file(&sol, filename))
130 fprintf(stderr, "Error while loading level file '%s': ", filename);
134 fprintf(stderr, _("Not a valid level file\n"));
139 strcpy(level->file, filename);
141 /* Init hs with default values */
142 score_init_hs(&level->time_score, 59999, 0);
143 score_init_hs(&level->goal_score, 59999, 0);
144 score_init_hs(&level->coin_score, 59999, 0);
146 /* Compute money and default max money */
148 for (i = 0; i < sol.cc; i++)
149 money += sol.cv[i].n;
150 level->coin_score.coins[0] = money;
152 /* Scan sol metadata */
154 level_scan_metadata(level, sol.av);
156 /* Compute initial hs default values */
157 #define HOP(t, c) if (t[2] c t[0]) t[0] = t[1] = t[2]; else if (t[2] c t[1]) t[1] = (t[0] + t[2]) / 2
158 HOP(level->time_score.timer, <=);
159 HOP(level->goal_score.timer, <=);
160 HOP(level->coin_score.coins, >=);
162 /* Free the sol structure, no more needed */
168 void level_dump_info(const struct level * level)
170 printf("filename: %s\n"
177 level->file, level->back, level->grad, level->shot, level->song,
178 level->time, level->goal);
181 /*---------------------------------------------------------------------------*/
183 const char * mode_to_str(int m)
187 case MODE_CHALLENGE: return _("Challenge");
188 case MODE_NORMAL: return _("Normal");
189 case MODE_PRACTICE: return _("Practice");
190 case MODE_SINGLE: return _("Single");
191 default: return "???";
195 /*---------------------------------------------------------------------------*/
197 const char * state_to_str(int m)
201 case GAME_NONE: return _("Aborted");
202 case GAME_TIME: return _("Time-out");
203 case GAME_GOAL: return _("Success");
204 case GAME_FALL: return _("Fall-out");
205 default: return "???";
209 /*---------------------------------------------------------------------------*/