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.
21 #include "solid_base.h"
28 /*---------------------------------------------------------------------------*/
30 static void scan_level_attribs(struct level *l, const struct s_base *base)
37 int need_time_easy = 0;
38 int need_goal_easy = 0;
39 int need_coin_easy = 0;
41 for (i = 0; i < base->dc; i++)
43 char *k = base->av + base->dv[i].ai;
44 char *v = base->av + base->dv[i].aj;
46 if (strcmp(k, "message") == 0)
47 SAFECPY(l->message, v);
48 else if (strcmp(k, "song") == 0)
50 else if (strcmp(k, "shot") == 0)
52 else if (strcmp(k, "goal") == 0)
57 else if (strcmp(k, "time") == 0)
62 else if (strcmp(k, "time_hs") == 0)
64 switch (sscanf(v, "%d %d %d",
65 &l->scores[SCORE_TIME].timer[RANK_HARD],
66 &l->scores[SCORE_TIME].timer[RANK_MEDM],
67 &l->scores[SCORE_TIME].timer[RANK_EASY]))
69 case 2: need_time_easy = 1; break;
73 else if (strcmp(k, "goal_hs") == 0)
75 switch (sscanf(v, "%d %d %d",
76 &l->scores[SCORE_GOAL].timer[RANK_HARD],
77 &l->scores[SCORE_GOAL].timer[RANK_MEDM],
78 &l->scores[SCORE_GOAL].timer[RANK_EASY]))
80 case 2: need_goal_easy = 1; break;
84 else if (strcmp(k, "coin_hs") == 0)
86 switch (sscanf(v, "%d %d %d",
87 &l->scores[SCORE_COIN].coins[RANK_HARD],
88 &l->scores[SCORE_COIN].coins[RANK_MEDM],
89 &l->scores[SCORE_COIN].coins[RANK_EASY]))
91 case 2: need_coin_easy = 1; break;
95 else if (strcmp(k, "version") == 0)
96 SAFECPY(l->version, v);
97 else if (strcmp(k, "author") == 0)
98 SAFECPY(l->author, v);
99 else if (strcmp(k, "bonus") == 0)
100 l->is_bonus = atoi(v) ? 1 : 0;
106 l->scores[SCORE_COIN].coins[RANK_EASY] = l->goal;
108 l->scores[SCORE_GOAL].coins[RANK_HARD] = l->goal;
109 l->scores[SCORE_GOAL].coins[RANK_MEDM] = l->goal;
110 l->scores[SCORE_GOAL].coins[RANK_EASY] = l->goal;
116 l->scores[SCORE_TIME].timer[RANK_EASY] = l->time;
118 l->scores[SCORE_GOAL].timer[RANK_EASY] = l->time;
120 l->scores[SCORE_COIN].timer[RANK_HARD] = l->time;
121 l->scores[SCORE_COIN].timer[RANK_MEDM] = l->time;
122 l->scores[SCORE_COIN].timer[RANK_EASY] = l->time;
126 int level_load(const char *filename, struct level *level)
130 memset(level, 0, sizeof (struct level));
131 memset(&base, 0, sizeof (base));
133 if (!sol_load_meta(&base, filename))
135 fprintf(stderr, L_("Failure to load level file '%s'\n"), filename);
139 SAFECPY(level->file, filename);
140 SAFECPY(level->name, "00");
142 score_init_hs(&level->scores[SCORE_TIME], 59999, 0);
143 score_init_hs(&level->scores[SCORE_GOAL], 59999, 0);
144 score_init_hs(&level->scores[SCORE_COIN], 59999, 0);
146 scan_level_attribs(level, &base);
148 sol_free_base(&base);
153 /*---------------------------------------------------------------------------*/
155 int level_exists(int i)
157 return !!get_level(i);
160 void level_open(struct level *level)
162 level->is_locked = 0;
165 int level_opened(const struct level *level)
167 return !level->is_locked;
170 void level_complete(struct level *level)
172 level->is_completed = 1;
175 int level_completed(const struct level *level)
177 return level->is_completed;
180 int level_time(const struct level *level)
185 int level_goal(const struct level *level)
190 int level_bonus(const struct level *level)
192 return level->is_bonus;
195 const char *level_shot(const struct level *level)
200 const char *level_file(const struct level *level)
205 const char *level_song(const struct level *level)
210 const char *level_name(const struct level *level)
215 const char *level_msg(const struct level *level)
217 if (strlen(level->message) > 0)
218 return _(level->message);
222 const struct score *level_score(struct level *level, int s)
224 return &level->scores[s];
227 /*---------------------------------------------------------------------------*/
229 int level_score_update(struct level *l,
236 const char *player = config_get_s(CONFIG_PLAYER);
238 score_time_insert(&l->scores[SCORE_TIME], time_rank, player, timer, coins);
239 score_time_insert(&l->scores[SCORE_GOAL], goal_rank, player, timer, coins);
240 score_coin_insert(&l->scores[SCORE_COIN], coin_rank, player, timer, coins);
242 if ((time_rank && *time_rank < 3) ||
243 (goal_rank && *goal_rank < 3) ||
244 (coin_rank && *coin_rank < 3))
250 void level_rename_player(struct level *l,
256 SAFECPY(l->scores[SCORE_TIME].player[time_rank], player);
257 SAFECPY(l->scores[SCORE_GOAL].player[goal_rank], player);
258 SAFECPY(l->scores[SCORE_COIN].player[coin_rank], player);
261 /*---------------------------------------------------------------------------*/