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.
23 #include "game_common.h"
24 #include "game_client.h"
25 #include "game_server.h"
29 /*---------------------------------------------------------------------------*/
38 static int replay = 0;
40 static int mode = MODE_NORMAL;
48 static struct progress curr;
49 static struct progress prev;
53 static int score_rank = 3;
54 static int times_rank = 3;
58 static int status = GAME_NONE;
63 static int goal = 0; /* Current goal value. */
64 static int goal_i = 0; /* Initial goal value. */
66 static int goal_e = 0; /* Goal enabled flag */
67 static int same_goal_e = 0; /* Reuse existing goal enabled flag */
69 static int time_rank = 3;
70 static int goal_rank = 3;
71 static int coin_rank = 3;
73 /*---------------------------------------------------------------------------*/
75 void progress_init(int m)
88 score_rank = times_rank = 3;
93 int progress_play(int i)
95 if (level_opened(i) || config_cheat())
103 goal = goal_i = level_goal(level);
108 goal_e = (mode != MODE_CHALLENGE && level_completed(level) &&
109 config_get_d(CONFIG_LOCK_GOALS) == 0) || goal == 0;
113 time_rank = goal_rank = coin_rank = 3;
115 if (demo_play_init(USER_REPLAY_FILE, get_level(level), mode,
116 level_time(level), level_goal(level),
117 goal_e, curr.score, curr.balls, curr.times))
130 void progress_step(void)
134 goal = goal_i - curr_coins();
138 if (!replay) game_set_goal();
144 void progress_stat(int s)
150 coins = curr_coins();
151 timer = level_time(level) - curr_clock();
157 for (i = curr.score + 1; i <= curr.score + coins; i++)
158 if (progress_reward_ball(i))
164 dirty = level_score_update(level, timer, coins,
166 goal == 0 ? &goal_rank : NULL,
169 if (!level_completed(level))
171 level_complete(level);
175 /* Compute next level. */
177 if (mode == MODE_CHALLENGE)
179 for (next = level + 1; level_bonus(next); next++)
180 if (!level_opened(next))
189 for (next = level + 1;
190 level_bonus(next) && !level_opened(next);
195 /* Open next level or complete the set. */
197 if (level_exists(next))
203 done = mode == MODE_CHALLENGE;
211 for (next = level + 1;
212 level_exists(next) && !level_opened(next);
225 demo_play_stat(status, coins, timer);
228 void progress_stop(void)
233 void progress_exit(void)
237 if (set_score_update(curr.times, curr.score, &score_rank, ×_rank))
241 int progress_replay(const char *filename)
243 if (demo_replay_init(filename, &goal, &mode,
256 int progress_next_avail(void)
258 if (mode == MODE_CHALLENGE)
259 return status == GAME_GOAL && level_exists(next);
261 return level_opened(next);
264 int progress_same_avail(void)
269 return mode != MODE_CHALLENGE;
272 if (mode == MODE_CHALLENGE)
273 return !progress_dead();
279 int progress_next(void)
282 return progress_play(next);
285 int progress_same(void)
289 /* Reset progress and goal enabled state. */
291 if (status == GAME_GOAL)
296 return progress_play(level);
299 int progress_dead(void)
301 return mode == MODE_CHALLENGE ? curr.balls < 0 : 0;
304 int progress_done(void)
309 int progress_last(void)
311 return mode != MODE_CHALLENGE && status == GAME_GOAL && !level_exists(next);
314 int progress_lvl_high(void)
316 return time_rank < 3 || goal_rank < 3 || coin_rank < 3;
319 int progress_set_high(void)
321 return score_rank < 3 || times_rank < 3;
324 void progress_rename(int set_only)
326 char player[MAXNAM] = "";
328 config_get_s(CONFIG_PLAYER, player, sizeof (player));
332 set_rename_player(score_rank, times_rank, player);
336 level_rename_player(level, time_rank, goal_rank, coin_rank, player);
338 demo_rename_player(USER_REPLAY_FILE, player);
341 set_rename_player(score_rank, times_rank, player);
347 int progress_reward_ball(int s)
349 return s > 0 && s % 100 == 0;
352 /*---------------------------------------------------------------------------*/
354 int curr_level(void) { return level; }
355 int curr_balls(void) { return curr.balls; }
356 int curr_score(void) { return curr.score; }
357 int curr_mode (void) { return mode; }
358 int curr_bonus(void) { return bonus; }
359 int curr_goal (void) { return goal; }
361 int progress_time_rank(void) { return time_rank; }
362 int progress_goal_rank(void) { return goal_rank; }
363 int progress_coin_rank(void) { return coin_rank; }
365 int progress_times_rank(void) { return times_rank; }
366 int progress_score_rank(void) { return score_rank; }
368 /*---------------------------------------------------------------------------*/
370 const char *mode_to_str(int m, int l)
374 case MODE_CHALLENGE: return l ? _("Challenge Mode") : _("Challenge");
375 case MODE_NORMAL: return l ? _("Normal Mode") : _("Normal");
376 default: return l ? _("Unknown Mode") : _("Unknown");
380 /*---------------------------------------------------------------------------*/