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 /*---------------------------------------------------------------------------*/
54 static int goal_action(int i)
56 audio_play(AUD_MENU, 1.0f);
65 return goto_state(&st_over);
69 return goto_save(&st_goal, &st_goal);
73 return goto_name(&st_goal, &st_goal, 0);
78 return goto_state(&st_done);
82 return goto_state(&st_start);
88 return goto_state(&st_goal);
92 return goto_state(&st_level);
97 return goto_state(&st_level);
104 static int goal_gui(void)
106 const char *s1 = _("New Record");
107 const char *s2 = _("GOAL");
109 int id, jd, kd, ld, md;
111 int high = progress_lvl_high();
112 int level = curr_level();
114 if ((id = gui_vstack(0)))
119 gid = gui_label(id, s1, GUI_MED, GUI_ALL, gui_grn, gui_grn);
121 gid = gui_label(id, s2, GUI_LRG, GUI_ALL, gui_blu, gui_grn);
125 if (curr_mode() == MODE_CHALLENGE)
127 int coins, score, balls;
128 char msg[MAXSTR] = "";
131 /* Reverse-engineer initial score and balls. */
136 score = curr_score();
137 balls = curr_balls();
141 coins = curr_coins();
142 score = curr_score() - coins;
143 balls = curr_balls();
145 for (i = curr_score(); i > score; i--)
146 if (progress_reward_ball(i))
150 sprintf(msg, ngettext("%d new bonus level",
151 "%d new bonus levels",
152 curr_bonus()), curr_bonus());
154 if ((jd = gui_hstack(id)))
158 if ((kd = gui_vstack(jd)))
160 if ((ld = gui_hstack(kd)))
162 if ((md = gui_harray(ld)))
164 balls_id = gui_count(md, 100, GUI_MED, GUI_NE);
165 gui_label(md, _("Balls"), GUI_SML, 0,
168 if ((md = gui_harray(ld)))
170 score_id = gui_count(md, 1000, GUI_MED, 0);
171 gui_label(md, _("Score"), GUI_SML, 0,
174 if ((md = gui_harray(ld)))
176 coins_id = gui_count(md, 100, GUI_MED, 0);
177 gui_label(md, _("Coins"), GUI_SML, GUI_NW,
181 gui_set_count(balls_id, balls);
182 gui_set_count(score_id, score);
183 gui_set_count(coins_id, coins);
186 gui_label(kd, msg, GUI_SML, GUI_BOT, 0, 0);
196 balls_id = score_id = coins_id = 0;
199 gui_score_board(id, (GUI_SCORE_COIN |
201 GUI_SCORE_GOAL), 1, high);
205 if ((jd = gui_harray(id)))
208 gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
209 else if (progress_last())
210 gui_start(jd, _("Finish"), GUI_SML, GOAL_LAST, 0);
212 if (progress_next_avail())
213 gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
215 if (progress_same_avail())
216 gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
219 gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
223 gui_pulse(gid, 1.2f);
225 gui_layout(id, 0, 0);
229 set_score_board(level_score(level, SCORE_COIN), progress_coin_rank(),
230 level_score(level, SCORE_TIME), progress_time_rank(),
231 level_score(level, SCORE_GOAL), progress_goal_rank());
237 static int goal_enter(struct state *st, struct state *prev)
239 if (prev == &st_name)
242 audio_music_fade_out(2.0f);
244 resume = (prev == &st_goal || prev == &st_name);
248 static void goal_timer(int id, float dt)
252 static float t = 0.0f;
256 if (time_state() < 1.f)
258 game_server_step(dt);
259 game_client_sync(demo_fp);
261 else if (t > 0.05f && coins_id)
263 int coins = gui_value(coins_id);
267 int score = gui_value(score_id);
268 int balls = gui_value(balls_id);
270 gui_set_count(coins_id, coins - 1);
271 gui_pulse(coins_id, 1.1f);
273 gui_set_count(score_id, score + 1);
274 gui_pulse(score_id, 1.1f);
276 if (progress_reward_ball(score + 1))
278 gui_set_count(balls_id, balls + 1);
279 gui_pulse(balls_id, 2.0f);
280 audio_play(AUD_BALL, 1.0f);
290 static int goal_keybd(int c, int d)
294 if (config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
295 return goal_action(gui_score_next(gui_score_get()));
296 if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
297 return goal_action(GOAL_SAME);
303 static int goal_buttn(int b, int d)
307 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
308 return goal_action(gui_token(gui_click()));
309 if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
310 return goal_action(GOAL_BACK);
315 /*---------------------------------------------------------------------------*/
317 struct state st_goal = {