-/*
- * Copyright (C) 2003 Robert Kooima
+/*
+ * Copyright (C) 2007 Robert Kooima
*
* NEVERBALL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* General Public License for more details.
*/
-#include <string.h>
+#include <stdio.h>
#include "gui.h"
-#include "set.h"
#include "game.h"
#include "util.h"
-#include "levels.h"
+#include "progress.h"
#include "audio.h"
#include "config.h"
#include "demo.h"
-#include "st_shared.h"
#include "st_goal.h"
#include "st_save.h"
#include "st_start.h"
#include "st_level.h"
#include "st_name.h"
+#include "st_shared.h"
/*---------------------------------------------------------------------------*/
-#define GOAL_NEXT 2
-#define GOAL_SAME 3
-#define GOAL_SAVE 4
-#define GOAL_BACK 5
-#define GOAL_DONE 6
-#define GOAL_NAME 7
+#define GOAL_NEXT 1
+#define GOAL_SAME 2
+#define GOAL_SAVE 3
+#define GOAL_BACK 4
+#define GOAL_DONE 5
+#define GOAL_OVER 6
static int balls_id;
static int coins_id;
static int score_id;
-extern struct state st_goal_bis;
+/* Bread crumbs. */
+
+static int new_name;
+static int resume;
static int goal_action(int i)
{
switch (i)
{
case GOAL_BACK:
- return goto_end_level();
+ /* Fall through. */
+
+ case GOAL_OVER:
+ progress_stop();
+ return goto_state(&st_over);
case GOAL_SAVE:
- return goto_save(&st_goal_bis, &st_goal_bis);
+ resume = 1;
+
+ progress_stop();
+ return goto_save(&st_goal, &st_goal);
+
+ case GUI_NAME:
+ new_name = 1;
+ resume = 1;
+
+ progress_stop();
+ return goto_name(&st_goal, &st_goal, 0);
- case GOAL_NAME:
- return goto_name(&st_goal_bis, &st_goal_bis);
-
case GOAL_DONE:
- return goto_state(&st_done);
-
+ progress_stop();
+ progress_exit();
+ return goto_state(&st_done);
+
+ case GUI_MOST_COINS:
+ case GUI_BEST_TIMES:
+ case GUI_UNLOCK_GOAL:
+ gui_score_set(i);
+ resume = 1;
+ return goto_state(&st_goal);
+
case GOAL_NEXT:
- level_next();
- return goto_state(&st_level);
+ if (progress_next())
+ return goto_state(&st_level);
+ break;
case GOAL_SAME:
- return goto_state(&st_level);
+ if (progress_same())
+ return goto_state(&st_level);
+ break;
}
return 1;
}
-static int goal_init(int * gidp)
+static int goal_enter(void)
{
const char *s1 = _("New Record");
const char *s2 = _("GOAL");
- const struct level_game *lg = curr_lg();
- int mode = curr_lg()->mode;
- const struct level *level = lg->level;
int id, jd, kd;
- int high;
- high = (lg->time_rank < 3) || (lg->goal_rank < 3) || (lg->coin_rank < 3);
+ const struct level *l = get_level(curr_level());
+
+ int high = progress_lvl_high();
+
+ if (new_name)
+ {
+ progress_rename(0);
+ new_name = 0;
+ }
if ((id = gui_vstack(0)))
{
gui_space(id);
- if (mode == MODE_CHALLENGE)
- {
- int coins = lg->coins;
- int score = lg->score - coins;
- int balls = lg->balls - count_extra_balls(score, coins);
- if ((jd = gui_hstack(id)))
- {
+ if (curr_mode() == MODE_CHALLENGE)
+ {
+ int coins, score, balls;
+ char msg[MAXSTR] = "";
+ int i;
+
+ /* Reverse-engineer initial score and balls. */
+
+ if (resume)
+ {
+ coins = 0;
+ score = curr_score();
+ balls = curr_balls();
+ }
+ else
+ {
+ coins = curr_coins();
+ score = curr_score() - coins;
+ balls = curr_balls();
+
+ for (i = curr_score(); i > score; i--)
+ if (progress_reward_ball(i))
+ balls--;
+ }
+
+ sprintf(msg, ngettext("%d new bonus level",
+ "%d new bonus levels",
+ curr_bonus()), curr_bonus());
+
+ if ((jd = gui_hstack(id)))
+ {
+
+ if ((kd = gui_harray(jd)))
+ {
+ balls_id = gui_count(kd, 100, GUI_MED, GUI_NE);
+ gui_label(kd, _("Balls"), GUI_SML, 0, gui_wht, gui_wht);
+ }
if ((kd = gui_harray(jd)))
{
- balls_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
- gui_label(kd, _("Balls"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
- }
- if ((kd = gui_harray(jd)))
- {
- score_id = gui_count(kd, 1000, GUI_MED, GUI_RGT);
- gui_label(kd, _("Score"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
- }
- if ((kd = gui_harray(jd)))
- {
- coins_id = gui_count(kd, 100, GUI_MED, GUI_RGT);
- gui_label(kd, _("Coins"), GUI_SML, GUI_LFT, gui_wht, gui_wht);
- }
-
- gui_set_count(balls_id, balls);
- gui_set_count(score_id, score);
- gui_set_count(coins_id, coins);
- }
- }
-
- gui_space(id);
+ score_id = gui_count(kd, 1000, GUI_MED, 0);
+ gui_label(kd, _("Score"), GUI_SML, 0, gui_wht, gui_wht);
+ }
+ if ((kd = gui_harray(jd)))
+ {
+ coins_id = gui_count(kd, 100, GUI_MED, 0);
+ gui_label(kd, _("Coins"), GUI_SML, GUI_NW, gui_wht, gui_wht);
+ }
- if ((jd = gui_harray(id)))
+ gui_set_count(balls_id, balls);
+ gui_set_count(score_id, score);
+ gui_set_count(coins_id, coins);
+
+ }
+
+ gui_label(id, msg, GUI_SML, GUI_BOT, 0, 0);
+
+ gui_space(id);
+ }
+ else
{
- gui_most_coins(jd, 1);
- gui_best_times(jd, 1);
+ balls_id = score_id = coins_id = 0;
}
+ if ((jd = gui_hstack(id)))
+ gui_score_board(jd, 1, high);
+
gui_space(id);
if ((jd = gui_harray(id)))
{
- if (demo_play_saved())
- gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
- else
- gui_label(jd, _("Save Replay"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
-
- if (mode != MODE_CHALLENGE)
+ if (progress_done())
+ gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
+
+ if (progress_next_avail())
+ gui_start(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
+
+ if (progress_same_avail())
gui_start(jd, _("Retry Level"), GUI_SML, GOAL_SAME, 0);
-
- if (lg->win)
- gui_start(jd, _("Finish"), GUI_SML, GOAL_DONE, 0);
- else if (lg->next_level != NULL)
- gui_state(jd, _("Next Level"), GUI_SML, GOAL_NEXT, 0);
- else if (mode != MODE_SINGLE)
- gui_label(jd, _("Next Level"), GUI_SML, GUI_ALL, gui_blk, gui_blk);
+
+ if (demo_saved())
+ gui_state(jd, _("Save Replay"), GUI_SML, GOAL_SAVE, 0);
}
- if (high)
- gui_state(id, _("Change Player Name"), GUI_SML, GOAL_NAME, 0);
+ if (!resume)
+ gui_pulse(gid, 1.2f);
gui_layout(id, 0, 0);
- if (gidp) *gidp = gid;
+
}
- set_most_coins(&level->coin_score, lg->coin_rank);
- if (mode == MODE_CHALLENGE || mode == MODE_NORMAL)
- set_best_times(&level->goal_score, lg->goal_rank, 1);
- else
- set_best_times(&level->time_score, lg->time_rank, 0);
+ set_score_board(&l->score.most_coins, progress_coin_rank(),
+ &l->score.best_times, progress_time_rank(),
+ &l->score.unlock_goal, progress_goal_rank());
- config_clr_grab();
+ audio_music_fade_out(2.0f);
- return id;
-}
+ config_clr_grab();
-static int goal_enter(void)
-{
- int gid;
- int r;
-
- r = goal_init(&gid);
-
- gui_pulse(gid, 1.2f);
- audio_music_fade_out(2.0f);
- return r;
-}
+ /* Reset hack. */
+ resume = 0;
-static int goal_bis_enter(void)
-{
- level_update_player_name();
- return goal_init(NULL);
+ return id;
}
static void goal_timer(int id, float dt)
{
- static float DT = 0.0f;
+ static float t = 0.0f;
float g[3] = { 0.0f, 9.8f, 0.0f };
- DT += dt;
+ t += dt;
if (time_state() < 1.f)
- game_step(g, dt, NULL);
- else if (DT > 0.05f && curr_lg()->mode == MODE_CHALLENGE)
{
- int coins = gui_value(coins_id);
+ demo_play_step();
+ game_step(g, dt, 0);
+ }
+ else if (t > 0.05f && coins_id)
+ {
+ int coins = gui_value(coins_id);
+
if (coins > 0)
{
- int score = gui_value(score_id);
- int balls = gui_value(balls_id);
-
- gui_set_count(coins_id, coins - 1);
- gui_pulse(coins_id, 1.1f);
-
- gui_set_count(score_id, score + 1);
- gui_pulse(score_id, 1.1f);
- if ((score+1) % 100 == 0)
- {
+ int score = gui_value(score_id);
+ int balls = gui_value(balls_id);
+
+ gui_set_count(coins_id, coins - 1);
+ gui_pulse(coins_id, 1.1f);
+
+ gui_set_count(score_id, score + 1);
+ gui_pulse(score_id, 1.1f);
+
+ if (progress_reward_ball(score + 1))
+ {
gui_set_count(balls_id, balls + 1);
gui_pulse(balls_id, 2.0f);
- audio_play(AUD_BALL, 1.0f);
- }
+ audio_play(AUD_BALL, 1.0f);
+ }
}
-
- DT = 0.0f;
+ t = 0.0f;
}
gui_timer(id, dt);
- audio_timer(dt);
+}
+
+static int goal_keybd(int c, int d)
+{
+ if (d)
+ {
+ if (config_tst_d(CONFIG_KEY_SCORE_NEXT, c))
+ return goal_action(gui_score_next(gui_score_get()));
+ if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
+ return goal_action(GOAL_SAME);
+ }
+
+ return 1;
}
static int goal_buttn(int b, int d)
if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
return goal_action(gui_token(gui_click()));
if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
- return goal_action(GOAL_BACK);
+ return goal_action(GOAL_BACK);
}
return 1;
}
+static void goal_leave(int id)
+{
+ /* HACK: don't run animation if only "visiting" a state. */
+ st_goal.timer = resume ? shared_timer : goal_timer;
+
+ gui_delete(id);
+}
+
/*---------------------------------------------------------------------------*/
struct state st_goal = {
goal_enter,
- shared_leave,
+ goal_leave,
shared_paint,
goal_timer,
shared_point,
shared_stick,
+ shared_angle,
shared_click,
- NULL,
+ goal_keybd,
goal_buttn,
1, 0
};
-struct state st_goal_bis = {
- goal_bis_enter,
- shared_leave,
- shared_paint,
- shared_timer,
- shared_point,
- shared_stick,
- shared_click,
- NULL,
- goal_buttn,
- 1, 0
-};