ball/set: clean up some excessive macro usage
[neverball] / ball / st_fall_out.c
index d68f110..7a887c9 100644 (file)
  */
 
 #include "gui.h"
-#include "game.h"
 #include "util.h"
-#include "levels.h"
+#include "progress.h"
 #include "audio.h"
 #include "config.h"
+#include "video.h"
 #include "demo.h"
 
+#include "game_common.h"
+#include "game_server.h"
+#include "game_client.h"
+
 #include "st_fall_out.h"
 #include "st_save.h"
 #include "st_over.h"
 #include "st_start.h"
 #include "st_level.h"
 #include "st_shared.h"
+#include "st_play.h"
 
 /*---------------------------------------------------------------------------*/
 
@@ -35,7 +40,7 @@
 #define FALL_OUT_BACK 4
 #define FALL_OUT_OVER 5
 
-static int be_back_soon;
+static int resume;
 
 static int fall_out_action(int i)
 {
@@ -47,22 +52,24 @@ static int fall_out_action(int i)
         /* Fall through. */
 
     case FALL_OUT_OVER:
-        level_stop();
+        progress_stop();
         return goto_state(&st_over);
 
     case FALL_OUT_SAVE:
-        be_back_soon = 1;
+        resume = 1;
 
-        level_stop();
+        progress_stop();
         return goto_save(&st_fall_out, &st_fall_out);
 
     case FALL_OUT_NEXT:
-        level_next();
-        return goto_state(&st_level);
+        if (progress_next())
+            return goto_state(&st_level);
+        break;
 
     case FALL_OUT_SAME:
-        level_same();
-        return goto_state(&st_level);
+        if (progress_same())
+            return goto_state(&st_level);
+        break;
     }
 
     return 1;
@@ -72,10 +79,8 @@ static int fall_out_enter(void)
 {
     int id, jd, kd;
 
-    const struct level_game *lg = curr_lg();
-
     /* Reset hack. */
-    be_back_soon = 0;
+    resume = 0;
 
     if ((id = gui_vstack(0)))
     {
@@ -85,29 +90,17 @@ static int fall_out_enter(void)
 
         if ((jd = gui_harray(id)))
         {
-            int next_id = 0, retry_id = 0;
-
-            next_id = gui_maybe(jd, _("Next Level"), FALL_OUT_NEXT,
-                                lg->next_level != NULL);
-
-            if (lg->dead)
-            {
-                gui_start(jd, _("Game Over"), GUI_SML, FALL_OUT_OVER, 0);
-            }
-            else
-            {
-                retry_id = gui_state(jd, _("Retry Level"), GUI_SML,
-                                     FALL_OUT_SAME, 0);
-            }
+            if (progress_dead())
+                gui_start(jd, _("Exit"), GUI_SML, FALL_OUT_OVER, 0);
 
-            gui_maybe(jd, _("Save Replay"), FALL_OUT_SAVE, demo_saved());
+            if (progress_next_avail())
+                gui_start(jd, _("Next Level"),  GUI_SML, FALL_OUT_NEXT, 0);
 
-            /* Default is next if the next level is newly unlocked. */
+            if (progress_same_avail())
+                gui_start(jd, _("Retry Level"), GUI_SML, FALL_OUT_SAME, 0);
 
-            if (next_id && lg->unlock)
-                gui_focus(next_id);
-            else if (retry_id)
-                gui_focus(retry_id);
+            if (demo_saved())
+                gui_state(jd, _("Save Replay"), GUI_SML, FALL_OUT_SAVE, 0);
         }
 
         gui_space(id);
@@ -119,24 +112,35 @@ static int fall_out_enter(void)
     audio_music_fade_out(2.0f);
     /* audio_play(AUD_FALL, 1.0f); */
 
-    config_clr_grab();
+    video_clr_grab();
 
     return id;
 }
 
 static void fall_out_timer(int id, float dt)
 {
-    float g[3] = { 0.0f, -9.8f, 0.0f };
-
     if (time_state() < 2.f)
     {
-        demo_play_step();
-        game_step(g, dt, 0);
+        game_server_step(dt);
+        game_client_step(demo_file());
     }
 
     gui_timer(id, dt);
 }
 
+static int fall_out_keybd(int c, int d)
+{
+    if (d)
+    {
+        if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
+        {
+            if (progress_same())
+                goto_state(&st_play_ready);
+        }
+    }
+    return 1;
+}
+
 static int fall_out_buttn(int b, int d)
 {
     if (d)
@@ -152,7 +156,7 @@ static int fall_out_buttn(int b, int d)
 static void fall_out_leave(int id)
 {
     /* HACK:  don't run animation if only "visiting" a state. */
-    st_fall_out.timer = be_back_soon ? shared_timer : fall_out_timer;
+    st_fall_out.timer = resume ? shared_timer : fall_out_timer;
 
     gui_delete(id);
 }
@@ -168,7 +172,7 @@ struct state st_fall_out = {
     shared_stick,
     NULL,
     shared_click,
-    NULL,
+    fall_out_keybd,
     fall_out_buttn,
     1, 0
 };