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.
26 /*---------------------------------------------------------------------------*/
35 static int mode = MODE_NORMAL;
43 static struct progress curr;
44 static struct progress prev;
48 static int score_rank = 3;
49 static int times_rank = 3;
53 static int status = GAME_NONE;
58 static int goal = 0; /* Current goal value. */
59 static int goal_i = 0; /* Initial goal value. */
61 static int goal_e = 0; /* Goal enabled flag */
62 static int same_goal_e = 0; /* Reuse existing goal enabled flag */
64 static int time_rank = 3;
65 static int goal_rank = 3;
66 static int coin_rank = 3;
68 /*---------------------------------------------------------------------------*/
70 void progress_init(int m)
81 score_rank = times_rank = 3;
86 int progress_play(int i)
88 if (level_opened(i) || config_cheat())
96 goal = goal_i = level_goal(level);
101 goal_e = (mode != MODE_CHALLENGE && level_completed(level) &&
102 config_get_d(CONFIG_LOCK_GOALS) == 0) || goal == 0;
106 time_rank = goal_rank = coin_rank = 3;
108 if (demo_play_init(USER_REPLAY_FILE, get_level(level), mode,
109 level_time(level), level_goal(level),
110 goal_e, curr.score, curr.balls, curr.times))
123 void progress_step(void)
127 goal = goal_i - curr_coins();
137 void progress_stat(int s)
143 coins = curr_coins();
144 timer = level_time(level) - curr_clock();
150 for (i = curr.score + 1; i <= curr.score + coins; i++)
151 if (progress_reward_ball(i))
157 dirty = level_score_update(level, timer, coins,
159 goal == 0 ? &goal_rank : NULL,
162 if (!level_completed(level))
164 level_complete(level);
168 /* Compute next level. */
170 if (mode == MODE_CHALLENGE)
172 for (next = level + 1; level_bonus(next); next++)
173 if (!level_opened(next))
182 for (next = level + 1;
183 level_bonus(next) && !level_opened(next);
188 /* Open next level or complete the set. */
190 if (level_exists(next))
196 done = mode == MODE_CHALLENGE;
204 for (next = level + 1;
205 level_exists(next) && !level_opened(next);
218 demo_play_stat(status, coins, timer);
221 void progress_stop(void)
226 void progress_exit(void)
230 if (set_score_update(curr.times, curr.score, &score_rank, ×_rank))
234 int progress_replay(const char *filename)
236 if (demo_replay_init(filename, &goal, &mode,
248 int progress_next_avail(void)
250 if (mode == MODE_CHALLENGE)
251 return status == GAME_GOAL && level_exists(next);
253 return level_opened(next);
256 int progress_same_avail(void)
261 return mode != MODE_CHALLENGE;
264 if (mode == MODE_CHALLENGE)
265 return !progress_dead();
271 int progress_next(void)
274 return progress_play(next);
277 int progress_same(void)
281 /* Reset progress and goal enabled state. */
283 if (status == GAME_GOAL)
289 return progress_play(level);
292 int progress_dead(void)
294 return mode == MODE_CHALLENGE ? curr.balls < 0 : 0;
297 int progress_done(void)
302 int progress_lvl_high(void)
304 return time_rank < 3 || goal_rank < 3 || coin_rank < 3;
307 int progress_set_high(void)
309 return score_rank < 3 || times_rank < 3;
312 void progress_rename(int set_only)
314 char player[MAXNAM] = "";
316 config_get_s(CONFIG_PLAYER, player, sizeof (player));
320 set_rename_player(score_rank, times_rank, player);
324 level_rename_player(level, time_rank, goal_rank, coin_rank, player);
326 demo_rename_player(USER_REPLAY_FILE, player);
329 set_rename_player(score_rank, times_rank, player);
335 int progress_reward_ball(int s)
337 return s > 0 && s % 100 == 0;
340 /*---------------------------------------------------------------------------*/
342 int curr_level(void) { return level; }
343 int curr_balls(void) { return curr.balls; }
344 int curr_score(void) { return curr.score; }
345 int curr_mode (void) { return mode; }
346 int curr_bonus(void) { return bonus; }
347 int curr_goal (void) { return goal; }
349 int progress_time_rank(void) { return time_rank; }
350 int progress_goal_rank(void) { return goal_rank; }
351 int progress_coin_rank(void) { return coin_rank; }
353 int progress_times_rank(void) { return times_rank; }
354 int progress_score_rank(void) { return score_rank; }
356 /*---------------------------------------------------------------------------*/
358 const char *mode_to_str(int m, int l)
362 case MODE_CHALLENGE: return l ? _("Challenge Mode") : _("Challenge");
363 case MODE_NORMAL: return l ? _("Normal Mode") : _("Normal");
364 default: return l ? _("Unknown Mode") : _("Unknown");
368 /*---------------------------------------------------------------------------*/