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"
33 #include "st_shared.h"
35 /*---------------------------------------------------------------------------*/
51 static int goal_action(int i)
53 audio_play(AUD_MENU, 1.0f);
62 return goto_state(&st_exit);
66 return goto_save(&st_goal, &st_goal);
70 return goto_name(&st_goal, &st_goal, 0);
75 return goto_state(&st_exit);
79 return goto_state(&st_exit);
85 return goto_state(&st_goal);
89 return goto_state(&st_level);
94 return goto_state(&st_level);
101 static int goal_gui(void)
103 const char *s1 = _("New Record");
104 const char *s2 = _("GOAL");
106 int id, jd, kd, ld, md;
108 int high = progress_lvl_high();
110 if ((id = gui_vstack(0)))
115 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
117 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
121 if (curr_mode() == MODE_CHALLENGE)
123 int coins, score, balls;
124 char msg[MAXSTR] = "";
127 /* Reverse-engineer initial score and balls. */
132 score = curr_score();
133 balls = curr_balls();
137 coins = curr_coins();
138 score = curr_score() - coins;
139 balls = curr_balls();
141 for (i = curr_score(); i > score; i--)
142 if (progress_reward_ball(i))
146 sprintf(msg, ngettext("%d new bonus level",
147 "%d new bonus levels",
148 curr_bonus()), curr_bonus());
150 if ((jd = gui_hstack(id)))
154 if ((kd = gui_vstack(jd)))
156 if ((ld = gui_hstack(kd)))
158 if ((md = gui_harray(ld)))
160 balls_id = gui_count(md, 100, GUI_MED, GUI_NE);
161 gui_label(md, _("Balls"), GUI_SML, 0,
164 if ((md = gui_harray(ld)))
166 score_id = gui_count(md, 1000, GUI_MED, 0);
167 gui_label(md, _("Score"), GUI_SML, 0,
170 if ((md = gui_harray(ld)))
172 coins_id = gui_count(md, 100, GUI_MED, 0);
173 gui_label(md, _("Coins"), GUI_SML, GUI_NW,
177 gui_set_count(balls_id, balls);
178 gui_set_count(score_id, score);
179 gui_set_count(coins_id, coins);
182 gui_label(kd, msg, GUI_SML, GUI_BOT, 0, 0);
192 balls_id = score_id = coins_id = 0;
195 gui_score_board(id, (GUI_SCORE_COIN |
197 GUI_SCORE_GOAL), 1, high);
201 if ((jd = gui_harray(id)))
204 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
205 else if (progress_last())
206 gui_start(jd, _("Finish"), GUI_SML, GOAL_LAST, 0);
208 if (progress_next_avail())
209 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
211 if (progress_same_avail())
212 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
215 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
219 gui_pulse(gid, 1.2f);
221 gui_layout(id, 0, 0);
225 set_score_board(level_score(curr_level(), SCORE_COIN), progress_coin_rank(),
226 level_score(curr_level(), SCORE_TIME), progress_time_rank(),
227 level_score(curr_level(), SCORE_GOAL), progress_goal_rank());
232 static int goal_enter(struct state *st, struct state *prev)
234 if (prev == &st_name)
237 audio_music_fade_out(2.0f);
239 resume = (prev == &st_goal || prev == &st_name || prev == &st_save);
243 static void goal_timer(int id, float dt)
247 static float t = 0.0f;
251 if (time_state() < 1.f)
253 game_server_step(dt);
254 game_client_sync(demo_fp);
255 game_client_blend(game_server_blend());
257 else if (t > 0.05f && coins_id)
259 int coins = gui_value(coins_id);
263 int score = gui_value(score_id);
264 int balls = gui_value(balls_id);
266 gui_set_count(coins_id, coins - 1);
267 gui_pulse(coins_id, 1.1f);
269 gui_set_count(score_id, score + 1);
270 gui_pulse(score_id, 1.1f);
272 if (progress_reward_ball(score + 1))
274 gui_set_count(balls_id, balls + 1);
275 gui_pulse(balls_id, 2.0f);
276 audio_play(AUD_BALL, 1.0f);
286 static int goal_keybd(int c, int d)
290 if (config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
291 return goal_action(gui_score_next(gui_score_get()));
292 if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
293 return goal_action(GOAL_SAME);
299 static int goal_buttn(int b, int d)
303 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
304 return goal_action(gui_token(gui_click()));
305 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
306 return goal_action(GOAL_BACK);
311 /*---------------------------------------------------------------------------*/
313 struct state st_goal = {