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 static int mode = MODE_NORMAL;
40 static int score_rank = 3;
41 static int times_rank = 3;
45 static int status = GAME_NONE;
50 static int goal = 0; /* Current goal value. */
51 static int goal_i = 0; /* Initial goal value. */
53 static int time_rank = 3;
54 static int goal_rank = 3;
55 static int coin_rank = 3;
57 /*---------------------------------------------------------------------------*/
59 void progress_init(int m)
68 score_rank = times_rank = 3;
73 int progress_play(int i)
75 if (level_opened(i) || config_cheat())
83 goal = goal_i = level_goal(level);
85 time_rank = goal_rank = coin_rank = 3;
87 if (demo_play_init(USER_REPLAY_FILE, get_level(level), mode,
88 level_time(level), level_goal(level),
89 (mode != MODE_CHALLENGE && level_completed(level) &&
90 config_get_d(CONFIG_LOCK_GOALS) == 0) || goal == 0,
104 void progress_step(void)
108 goal = goal_i - curr_coins();
118 void progress_stat(int s)
124 coins = curr_coins();
125 timer = level_time(level) - curr_clock();
131 for (i = score + 1; i <= score + coins; i++)
132 if (progress_reward_ball(i))
138 dirty = level_score_update(level, timer, coins,
140 goal == 0 ? &goal_rank : NULL,
143 if (!level_completed(level))
145 level_complete(level);
149 /* Compute next level. */
151 if (mode == MODE_CHALLENGE)
153 for (next = level + 1; level_bonus(next); next++)
154 if (!level_opened(next))
163 for (next = level + 1;
164 level_bonus(next) && !level_opened(next);
169 /* Complete the set or open next level. */
171 if (!level_exists(next))
173 if (mode == MODE_CHALLENGE)
175 dirty = set_score_update(times, score, &score_rank, ×_rank);
191 for (next = level + 1;
192 level_exists(next) && !level_opened(next);
203 demo_play_stat(status, coins, timer);
206 void progress_stop(void)
211 void progress_exit(int s)
217 int progress_replay(const char *filename)
219 if (demo_replay_init(filename, &goal, &mode, &balls, &score, ×))
228 int progress_next_avail(void)
230 if (mode == MODE_CHALLENGE)
231 return status == GAME_GOAL && level_exists(next);
233 return level_opened(next);
236 int progress_same_avail(void)
241 return mode != MODE_CHALLENGE;
244 if (mode == MODE_CHALLENGE)
245 return status != GAME_GOAL && !progress_dead();
251 int progress_next(void)
254 return progress_play(next);
257 int progress_same(void)
260 return progress_play(level);
263 int progress_dead(void)
265 return mode == MODE_CHALLENGE ? balls < 0 : 0;
268 int progress_done(void)
273 int progress_lvl_high(void)
275 return time_rank < 3 || goal_rank < 3 || coin_rank < 3;
278 int progress_set_high(void)
280 return score_rank < 3 || times_rank < 3;
283 void progress_rename(void)
285 char player[MAXNAM] = "";
287 config_get_s(CONFIG_PLAYER, player, sizeof (player));
289 level_rename_player(level, time_rank, goal_rank, coin_rank, player);
290 set_rename_player (score_rank, times_rank, player);
295 int progress_reward_ball(int s)
297 return s > 0 && s % 100 == 0;
300 /*---------------------------------------------------------------------------*/
302 int curr_level(void) { return level; }
303 int curr_balls(void) { return balls; }
304 int curr_score(void) { return score; }
305 int curr_mode (void) { return mode; }
306 int curr_bonus(void) { return bonus; }
307 int curr_goal (void) { return goal; }
309 int progress_time_rank(void) { return time_rank; }
310 int progress_goal_rank(void) { return goal_rank; }
311 int progress_coin_rank(void) { return coin_rank; }
313 int progress_times_rank(void) { return times_rank; }
314 int progress_score_rank(void) { return score_rank; }
316 /*---------------------------------------------------------------------------*/
318 const char *mode_to_str(int m, int l)
322 case MODE_CHALLENGE: return l ? _("Challenge Mode") : _("Challenge");
323 case MODE_NORMAL: return l ? _("Normal Mode") : _("Normal");
324 default: return l ? _("Unknown Mode") : _("Unknown");
328 /*---------------------------------------------------------------------------*/