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.
25 #include "game_common.h"
26 #include "game_server.h"
27 #include "game_client.h"
36 #include "st_shared.h"
38 /*---------------------------------------------------------------------------*/
57 static int goal_action(int i)
59 audio_play(AUD_MENU, 1.0f);
68 return goto_state(&st_over);
74 return goto_save(&st_goal, &st_goal);
81 return goto_name(&st_goal, &st_goal, 0);
86 return goto_state(&st_done);
90 return goto_state(&st_start);
97 return goto_state(&st_goal);
101 return goto_state(&st_level);
106 return goto_state(&st_level);
113 static int goal_enter(void)
115 const char *s1 = _("New Record");
116 const char *s2 = _("GOAL");
120 const struct level *l = get_level(curr_level());
122 int high = progress_lvl_high();
130 if ((id = gui_vstack(0)))
135 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
137 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
141 if (curr_mode() == MODE_CHALLENGE)
143 int coins, score, balls;
144 char msg[MAXSTR] = "";
147 /* Reverse-engineer initial score and balls. */
152 score = curr_score();
153 balls = curr_balls();
157 coins = curr_coins();
158 score = curr_score() - coins;
159 balls = curr_balls();
161 for (i = curr_score(); i > score; i--)
162 if (progress_reward_ball(i))
166 sprintf(msg, ngettext("%d new bonus level",
167 "%d new bonus levels",
168 curr_bonus()), curr_bonus());
170 if ((jd = gui_hstack(id)))
173 if ((kd = gui_harray(jd)))
175 balls_id = gui_count(kd, 100, GUI_MED, GUI_NE);
176 gui_label(kd, _("Balls"), GUI_SML, 0, gui_wht, gui_wht);
178 if ((kd = gui_harray(jd)))
180 score_id = gui_count(kd, 1000, GUI_MED, 0);
181 gui_label(kd, _("Score"), GUI_SML, 0, gui_wht, gui_wht);
183 if ((kd = gui_harray(jd)))
185 coins_id = gui_count(kd, 100, GUI_MED, 0);
186 gui_label(kd, _("Coins"), GUI_SML, GUI_NW, gui_wht, gui_wht);
189 gui_set_count(balls_id, balls);
190 gui_set_count(score_id, score);
191 gui_set_count(coins_id, coins);
195 gui_label(id, msg, GUI_SML, GUI_BOT, 0, 0);
201 balls_id = score_id = coins_id = 0;
204 if ((jd = gui_hstack(id)))
205 gui_score_board(jd, GUI_MOST_COINS |
207 GUI_FAST_UNLOCK, 1, high);
211 if ((jd = gui_harray(id)))
214 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
215 else if (progress_last())
216 gui_start(jd, _("Finish"), GUI_SML, GOAL_LAST, 0);
218 if (progress_next_avail())
219 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
221 if (progress_same_avail())
222 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
225 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
229 gui_pulse(gid, 1.2f);
231 gui_layout(id, 0, 0);
235 set_score_board(&l->score.most_coins, progress_coin_rank(),
236 &l->score.best_times, progress_time_rank(),
237 &l->score.fast_unlock, progress_goal_rank());
239 audio_music_fade_out(2.0f);
249 static void goal_timer(int id, float dt)
251 static float t = 0.0f;
255 if (time_state() < 1.f)
257 game_server_step(dt);
258 game_client_step(demo_file());
260 else if (t > 0.05f && coins_id)
262 int coins = gui_value(coins_id);
266 int score = gui_value(score_id);
267 int balls = gui_value(balls_id);
269 gui_set_count(coins_id, coins - 1);
270 gui_pulse(coins_id, 1.1f);
272 gui_set_count(score_id, score + 1);
273 gui_pulse(score_id, 1.1f);
275 if (progress_reward_ball(score + 1))
277 gui_set_count(balls_id, balls + 1);
278 gui_pulse(balls_id, 2.0f);
279 audio_play(AUD_BALL, 1.0f);
288 static int goal_keybd(int c, int d)
292 if (config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
293 return goal_action(gui_score_next(gui_score_get()));
294 if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
295 return goal_action(GOAL_SAME);
301 static int goal_buttn(int b, int d)
305 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
306 return goal_action(gui_token(gui_click()));
307 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
308 return goal_action(GOAL_BACK);
313 static void goal_leave(int id)
315 /* HACK: don't run animation if only "visiting" a state. */
316 st_goal.timer = resume ? shared_timer : goal_timer;
321 /*---------------------------------------------------------------------------*/
323 struct state st_goal = {