2 * Copyright (C) 2007 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 #include "game_common.h"
25 #include "game_server.h"
26 #include "game_client.h"
35 #include "st_shared.h"
37 /*---------------------------------------------------------------------------*/
56 static int goal_action(int i)
58 audio_play(AUD_MENU, 1.0f);
67 return goto_state(&st_over);
73 return goto_save(&st_goal, &st_goal);
80 return goto_name(&st_goal, &st_goal, 0);
85 return goto_state(&st_done);
89 return goto_state(&st_start);
96 return goto_state(&st_goal);
100 return goto_state(&st_level);
105 return goto_state(&st_level);
112 static int goal_enter(void)
114 const char *s1 = _("New Record");
115 const char *s2 = _("GOAL");
119 const struct level *l = get_level(curr_level());
121 int high = progress_lvl_high();
129 if ((id = gui_vstack(0)))
134 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
136 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
140 if (curr_mode() == MODE_CHALLENGE)
142 int coins, score, balls;
143 char msg[MAXSTR] = "";
146 /* Reverse-engineer initial score and balls. */
151 score = curr_score();
152 balls = curr_balls();
156 coins = curr_coins();
157 score = curr_score() - coins;
158 balls = curr_balls();
160 for (i = curr_score(); i > score; i--)
161 if (progress_reward_ball(i))
165 sprintf(msg, ngettext("%d new bonus level",
166 "%d new bonus levels",
167 curr_bonus()), curr_bonus());
169 if ((jd = gui_hstack(id)))
172 if ((kd = gui_harray(jd)))
174 balls_id = gui_count(kd, 100, GUI_MED, GUI_NE);
175 gui_label(kd, _("Balls"), GUI_SML, 0, gui_wht, gui_wht);
177 if ((kd = gui_harray(jd)))
179 score_id = gui_count(kd, 1000, GUI_MED, 0);
180 gui_label(kd, _("Score"), GUI_SML, 0, gui_wht, gui_wht);
182 if ((kd = gui_harray(jd)))
184 coins_id = gui_count(kd, 100, GUI_MED, 0);
185 gui_label(kd, _("Coins"), GUI_SML, GUI_NW, gui_wht, gui_wht);
188 gui_set_count(balls_id, balls);
189 gui_set_count(score_id, score);
190 gui_set_count(coins_id, coins);
194 gui_label(id, msg, GUI_SML, GUI_BOT, 0, 0);
200 balls_id = score_id = coins_id = 0;
203 if ((jd = gui_hstack(id)))
204 gui_score_board(jd, GUI_MOST_COINS |
206 GUI_UNLOCK_GOAL, 1, high);
210 if ((jd = gui_harray(id)))
213 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
214 else if (progress_last())
215 gui_start(jd, _("Finish"), GUI_SML, GOAL_LAST, 0);
217 if (progress_next_avail())
218 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
220 if (progress_same_avail())
221 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
224 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
228 gui_pulse(gid, 1.2f);
230 gui_layout(id, 0, 0);
234 set_score_board(&l->score.most_coins, progress_coin_rank(),
235 &l->score.best_times, progress_time_rank(),
236 &l->score.unlock_goal, progress_goal_rank());
238 audio_music_fade_out(2.0f);
248 static void goal_timer(int id, float dt)
250 static float t = 0.0f;
254 if (time_state() < 1.f)
256 game_server_step(dt);
257 game_client_step(demo_file());
259 else if (t > 0.05f && coins_id)
261 int coins = gui_value(coins_id);
265 int score = gui_value(score_id);
266 int balls = gui_value(balls_id);
268 gui_set_count(coins_id, coins - 1);
269 gui_pulse(coins_id, 1.1f);
271 gui_set_count(score_id, score + 1);
272 gui_pulse(score_id, 1.1f);
274 if (progress_reward_ball(score + 1))
276 gui_set_count(balls_id, balls + 1);
277 gui_pulse(balls_id, 2.0f);
278 audio_play(AUD_BALL, 1.0f);
287 static int goal_keybd(int c, int d)
291 if (config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
292 return goal_action(gui_score_next(gui_score_get()));
293 if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
294 return goal_action(GOAL_SAME);
300 static int goal_buttn(int b, int d)
304 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
305 return goal_action(gui_token(gui_click()));
306 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
307 return goal_action(GOAL_BACK);
312 static void goal_leave(int id)
314 /* HACK: don't run animation if only "visiting" a state. */
315 st_goal.timer = resume ? shared_timer : goal_timer;
320 /*---------------------------------------------------------------------------*/
322 struct state st_goal = {