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 /*---------------------------------------------------------------------------*/
33 static int mode = MODE_NORMAL;
41 static struct progress curr;
42 static struct progress prev;
46 static int score_rank = 3;
47 static int times_rank = 3;
51 static int status = GAME_NONE;
56 static int goal = 0; /* Current goal value. */
57 static int goal_i = 0; /* Initial goal value. */
59 static int time_rank = 3;
60 static int goal_rank = 3;
61 static int coin_rank = 3;
63 /*---------------------------------------------------------------------------*/
65 void progress_init(int m)
76 score_rank = times_rank = 3;
81 int progress_play(int i)
83 if (level_opened(i) || config_cheat())
91 goal = goal_i = level_goal(level);
95 time_rank = goal_rank = coin_rank = 3;
97 if (demo_play_init(USER_REPLAY_FILE, get_level(level), mode,
98 level_time(level), level_goal(level),
99 (mode != MODE_CHALLENGE && level_completed(level) &&
100 config_get_d(CONFIG_LOCK_GOALS) == 0) || goal == 0,
101 curr.score, curr.balls, curr.times))
114 void progress_step(void)
118 goal = goal_i - curr_coins();
128 void progress_stat(int s)
134 coins = curr_coins();
135 timer = level_time(level) - curr_clock();
141 for (i = curr.score + 1; i <= curr.score + coins; i++)
142 if (progress_reward_ball(i))
148 dirty = level_score_update(level, timer, coins,
150 goal == 0 ? &goal_rank : NULL,
153 if (!level_completed(level))
155 level_complete(level);
159 /* Compute next level. */
161 if (mode == MODE_CHALLENGE)
163 for (next = level + 1; level_bonus(next); next++)
164 if (!level_opened(next))
173 for (next = level + 1;
174 level_bonus(next) && !level_opened(next);
179 /* Complete the set or open next level. */
181 if (!level_exists(next))
183 if (mode == MODE_CHALLENGE)
185 dirty = set_score_update(curr.times, curr.score,
186 &score_rank, ×_rank);
202 for (next = level + 1;
203 level_exists(next) && !level_opened(next);
214 demo_play_stat(status, coins, timer);
217 void progress_stop(void)
222 void progress_exit(int s)
228 int progress_replay(const char *filename)
230 if (demo_replay_init(filename, &goal, &mode,
242 int progress_next_avail(void)
244 if (mode == MODE_CHALLENGE)
245 return status == GAME_GOAL && level_exists(next);
247 return level_opened(next);
250 int progress_same_avail(void)
255 return mode != MODE_CHALLENGE;
258 if (mode == MODE_CHALLENGE)
259 return !progress_dead();
265 int progress_next(void)
268 return progress_play(next);
271 int progress_same(void)
274 curr = status == GAME_GOAL ? prev : curr;
275 return progress_play(level);
278 int progress_dead(void)
280 return mode == MODE_CHALLENGE ? curr.balls < 0 : 0;
283 int progress_done(void)
288 int progress_lvl_high(void)
290 return time_rank < 3 || goal_rank < 3 || coin_rank < 3;
293 int progress_set_high(void)
295 return score_rank < 3 || times_rank < 3;
298 void progress_rename(int set_only)
300 char player[MAXNAM] = "";
302 config_get_s(CONFIG_PLAYER, player, sizeof (player));
306 set_rename_player(score_rank, times_rank, player);
310 level_rename_player(level, time_rank, goal_rank, coin_rank, player);
313 set_rename_player(score_rank, times_rank, player);
319 int progress_reward_ball(int s)
321 return s > 0 && s % 100 == 0;
324 /*---------------------------------------------------------------------------*/
326 int curr_level(void) { return level; }
327 int curr_balls(void) { return curr.balls; }
328 int curr_score(void) { return curr.score; }
329 int curr_mode (void) { return mode; }
330 int curr_bonus(void) { return bonus; }
331 int curr_goal (void) { return goal; }
333 int progress_time_rank(void) { return time_rank; }
334 int progress_goal_rank(void) { return goal_rank; }
335 int progress_coin_rank(void) { return coin_rank; }
337 int progress_times_rank(void) { return times_rank; }
338 int progress_score_rank(void) { return score_rank; }
340 /*---------------------------------------------------------------------------*/
342 const char *mode_to_str(int m, int l)
346 case MODE_CHALLENGE: return l ? _("Challenge Mode") : _("Challenge");
347 case MODE_NORMAL: return l ? _("Normal Mode") : _("Normal");
348 default: return l ? _("Unknown Mode") : _("Unknown");
352 /*---------------------------------------------------------------------------*/