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");
118 int id, jd, kd, ld, md;
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)))
174 if ((kd = gui_vstack(jd)))
176 if ((ld = gui_hstack(kd)))
178 if ((md = gui_harray(ld)))
180 balls_id = gui_count(md, 100, GUI_MED, GUI_NE);
181 gui_label(md, _("Balls"), GUI_SML, 0,
184 if ((md = gui_harray(ld)))
186 score_id = gui_count(md, 1000, GUI_MED, 0);
187 gui_label(md, _("Score"), GUI_SML, 0,
190 if ((md = gui_harray(ld)))
192 coins_id = gui_count(md, 100, GUI_MED, 0);
193 gui_label(md, _("Coins"), GUI_SML, GUI_NW,
197 gui_set_count(balls_id, balls);
198 gui_set_count(score_id, score);
199 gui_set_count(coins_id, coins);
202 gui_label(kd, msg, GUI_SML, GUI_BOT, 0, 0);
212 balls_id = score_id = coins_id = 0;
215 if ((jd = gui_hstack(id)))
216 gui_score_board(jd, GUI_MOST_COINS |
218 GUI_FAST_UNLOCK, 1, high);
222 if ((jd = gui_harray(id)))
225 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
226 else if (progress_last())
227 gui_start(jd, _("Finish"), GUI_SML, GOAL_LAST, 0);
229 if (progress_next_avail())
230 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
232 if (progress_same_avail())
233 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
236 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
240 gui_pulse(gid, 1.2f);
242 gui_layout(id, 0, 0);
246 set_score_board(&l->score.most_coins, progress_coin_rank(),
247 &l->score.best_times, progress_time_rank(),
248 &l->score.fast_unlock, progress_goal_rank());
250 audio_music_fade_out(2.0f);
260 static void goal_timer(int id, float dt)
262 static float t = 0.0f;
266 if (time_state() < 1.f)
268 game_server_step(dt);
269 game_client_step(demo_file());
271 else if (t > 0.05f && coins_id)
273 int coins = gui_value(coins_id);
277 int score = gui_value(score_id);
278 int balls = gui_value(balls_id);
280 gui_set_count(coins_id, coins - 1);
281 gui_pulse(coins_id, 1.1f);
283 gui_set_count(score_id, score + 1);
284 gui_pulse(score_id, 1.1f);
286 if (progress_reward_ball(score + 1))
288 gui_set_count(balls_id, balls + 1);
289 gui_pulse(balls_id, 2.0f);
290 audio_play(AUD_BALL, 1.0f);
299 static int goal_keybd(int c, int d)
303 if (config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
304 return goal_action(gui_score_next(gui_score_get()));
305 if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
306 return goal_action(GOAL_SAME);
312 static int goal_buttn(int b, int d)
316 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
317 return goal_action(gui_token(gui_click()));
318 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
319 return goal_action(GOAL_BACK);
324 static void goal_leave(int id)
326 /* HACK: don't run animation if only "visiting" a state. */
327 st_goal.timer = resume ? shared_timer : goal_timer;
332 /*---------------------------------------------------------------------------*/
334 struct state st_goal = {