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.
28 /*---------------------------------------------------------------------------*/
30 /* Currently playing level. */
31 static struct level_game current_level_game;
33 /*---------------------------------------------------------------------------*/
35 int level_replay(const char *filename)
37 return demo_replay_init(filename, ¤t_level_game);
40 int level_play(const struct level *l, int m)
42 struct level_game *lg = ¤t_level_game;
44 memset(lg, 0, sizeof (struct level_game));
50 lg->goal = (lg->mode == MODE_PRACTICE) ? 0 : lg->level->goal;
51 lg->time = (lg->mode == MODE_PRACTICE) ? 0 : lg->level->time;
53 /* Clear other fields. */
55 lg->status = GAME_NONE;
58 lg->coin_rank = lg->goal_rank = lg->time_rank =
59 lg->score_rank = lg->times_rank = 3;
61 lg->win = lg->dead = lg->unlock = 0;
62 lg->next_level = NULL;
64 return demo_play_init(USER_REPLAY_FILE, lg->level, lg);
67 /*---------------------------------------------------------------------------*/
69 const struct level_game *curr_lg(void)
71 return ¤t_level_game;
74 int count_extra_balls(int old_score, int coins)
76 return ((old_score % 100) + coins) / 100;
79 void level_stat(int status, int clock, int coins)
81 struct level_game *lg = ¤t_level_game;
84 int timer = (mode == MODE_PRACTICE) ? clock : lg->time - clock;
88 config_get_s(CONFIG_PLAYER, player, MAXNAM);
94 if (mode == MODE_CHALLENGE)
99 /* sum coins an earn extra balls */
100 if (status == GAME_GOAL || lg->level->is_bonus)
102 lg->balls += count_extra_balls(lg->score, coins);
106 /* lose ball and game */
109 lg->dead = (lg->balls <= 0);
114 set_finish_level(lg, player);
119 void level_stop(void)
126 struct level_game *lg = ¤t_level_game;
129 lg->level = lg->next_level;
130 return level_play(lg->level, lg->mode);
136 return level_play(curr_lg()->level, curr_lg()->mode);
139 void level_update_player_name(void)
143 config_get_s(CONFIG_PLAYER, player, MAXNAM);
145 score_change_name(¤t_level_game, player);
148 /*---------------------------------------------------------------------------*/