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);
216 demo_play_stat(status, coins, timer);
219 void progress_stop(void)
224 void progress_exit(void)
228 if (set_score_update(curr.times, curr.score, &score_rank, ×_rank))
232 int progress_replay(const char *filename)
234 if (demo_replay_init(filename, &goal, &mode,
246 int progress_next_avail(void)
248 if (mode == MODE_CHALLENGE)
249 return status == GAME_GOAL && level_exists(next);
251 return level_opened(next);
254 int progress_same_avail(void)
259 return mode != MODE_CHALLENGE;
262 if (mode == MODE_CHALLENGE)
263 return !progress_dead();
269 int progress_next(void)
272 return progress_play(next);
275 int progress_same(void)
279 /* Reset progress and goal enabled state. */
281 if (status == GAME_GOAL)
287 return progress_play(level);
290 int progress_dead(void)
292 return mode == MODE_CHALLENGE ? curr.balls < 0 : 0;
295 int progress_done(void)
300 int progress_lvl_high(void)
302 return time_rank < 3 || goal_rank < 3 || coin_rank < 3;
305 int progress_set_high(void)
307 return score_rank < 3 || times_rank < 3;
310 void progress_rename(int set_only)
312 char player[MAXNAM] = "";
314 config_get_s(CONFIG_PLAYER, player, sizeof (player));
318 set_rename_player(score_rank, times_rank, player);
322 level_rename_player(level, time_rank, goal_rank, coin_rank, player);
324 demo_rename_player(USER_REPLAY_FILE, player);
327 set_rename_player(score_rank, times_rank, player);
333 int progress_reward_ball(int s)
335 return s > 0 && s % 100 == 0;
338 /*---------------------------------------------------------------------------*/
340 int curr_level(void) { return level; }
341 int curr_balls(void) { return curr.balls; }
342 int curr_score(void) { return curr.score; }
343 int curr_mode (void) { return mode; }
344 int curr_bonus(void) { return bonus; }
345 int curr_goal (void) { return goal; }
347 int progress_time_rank(void) { return time_rank; }
348 int progress_goal_rank(void) { return goal_rank; }
349 int progress_coin_rank(void) { return coin_rank; }
351 int progress_times_rank(void) { return times_rank; }
352 int progress_score_rank(void) { return score_rank; }
354 /*---------------------------------------------------------------------------*/
356 const char *mode_to_str(int m, int l)
360 case MODE_CHALLENGE: return l ? _("Challenge Mode") : _("Challenge");
361 case MODE_NORMAL: return l ? _("Normal Mode") : _("Normal");
362 default: return l ? _("Unknown Mode") : _("Unknown");
366 /*---------------------------------------------------------------------------*/