Add a catch-all state for exiting the level
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Thu, 25 Nov 2010 14:01:44 +0000 (14:01 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Thu, 25 Nov 2010 14:01:44 +0000 (14:01 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@3373 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/st_done.c
ball/st_fail.c
ball/st_goal.c
ball/st_level.c
ball/st_level.h
ball/st_over.c
ball/st_pause.c
ball/st_play.c
ball/st_start.c

index 85b36b7..845165a 100644 (file)
@@ -25,7 +25,7 @@
 #include "game_common.h"
 
 #include "st_done.h"
-#include "st_start.h"
+#include "st_level.h"
 #include "st_name.h"
 #include "st_shared.h"
 
@@ -42,7 +42,7 @@ static int done_action(int i)
     switch (i)
     {
     case DONE_OK:
-        return goto_state(&st_start);
+        return goto_state(&st_exit);
 
     case GUI_NAME:
         return goto_name(&st_done, &st_done, 0);
index c8f3f53..2548f51 100644 (file)
@@ -24,8 +24,6 @@
 #include "game_server.h"
 #include "game_client.h"
 
-#include "st_over.h"
-#include "st_start.h"
 #include "st_save.h"
 #include "st_fail.h"
 #include "st_level.h"
@@ -54,7 +52,7 @@ static int fail_action(int i)
 
     case FAIL_OVER:
         progress_stop();
-        return goto_state(&st_over);
+        return goto_state(&st_exit);
 
     case FAIL_SAVE:
         progress_stop();
index 3f532cd..fadfe0b 100644 (file)
@@ -28,9 +28,6 @@
 
 #include "st_goal.h"
 #include "st_save.h"
-#include "st_over.h"
-#include "st_done.h"
-#include "st_start.h"
 #include "st_level.h"
 #include "st_name.h"
 #include "st_shared.h"
@@ -62,7 +59,7 @@ static int goal_action(int i)
 
     case GOAL_OVER:
         progress_stop();
-        return goto_state(&st_over);
+        return goto_state(&st_exit);
 
     case GOAL_SAVE:
         progress_stop();
@@ -75,11 +72,11 @@ static int goal_action(int i)
     case GOAL_DONE:
         progress_stop();
         progress_exit();
-        return goto_state(&st_done);
+        return goto_state(&st_exit);
 
     case GOAL_LAST:
         progress_stop();
-        return goto_state(&st_start);
+        return goto_state(&st_exit);
 
     case GUI_SCORE_COIN:
     case GUI_SCORE_TIME:
index 79476c0..26f134c 100644 (file)
@@ -28,6 +28,7 @@
 #include "st_play.h"
 #include "st_start.h"
 #include "st_over.h"
+#include "st_done.h"
 #include "st_shared.h"
 
 /*---------------------------------------------------------------------------*/
@@ -123,7 +124,7 @@ static int level_buttn(int b, int d)
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
         {
             progress_stop();
-            return goto_state(&st_over);
+            return goto_state(&st_exit);
         }
     }
     return 1;
@@ -190,6 +191,27 @@ static int nodemo_buttn(int b, int d)
     return 1;
 }
 
+
+/*---------------------------------------------------------------------------*/
+
+static int exit_enter(struct state *st, struct state *prev)
+{
+    struct state *dst;
+
+    if (progress_done())
+        dst = &st_done;
+    else if (curr_mode() == MODE_CHALLENGE)
+        dst = &st_over;
+    else
+        dst = &st_start;
+
+    /* Visit the auxilliary screen or exit to level selection. */
+
+    goto_state(dst != prev ? dst : &st_start);
+
+    return 0;
+}
+
 /*---------------------------------------------------------------------------*/
 
 struct state st_level = {
@@ -233,3 +255,17 @@ struct state st_nodemo = {
     nodemo_buttn,
     1, 0
 };
+
+struct state st_exit = {
+    exit_enter,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    1, 0
+};
index 1e24eca..633b4e4 100644 (file)
@@ -4,6 +4,7 @@
 #include "state.h"
 
 extern struct state st_level;
+extern struct state st_exit;
 extern struct state st_poser;
 extern struct state st_nodemo;
 
index ad1e3d6..22c1cb4 100644 (file)
@@ -23,7 +23,7 @@
 #include "game_common.h"
 
 #include "st_over.h"
-#include "st_start.h"
+#include "st_level.h"
 #include "st_shared.h"
 
 /*---------------------------------------------------------------------------*/
@@ -43,9 +43,6 @@ static int over_gui(void)
 
 static int over_enter(struct state *st, struct state *prev)
 {
-    if (curr_mode() != MODE_CHALLENGE)
-        return 0;
-
     audio_music_fade_out(2.0f);
     audio_play(AUD_OVER, 1.f);
 
@@ -56,15 +53,15 @@ static int over_enter(struct state *st, struct state *prev)
 
 static void over_timer(int id, float dt)
 {
-    if (curr_mode() != MODE_CHALLENGE || time_state() > 3.f)
-        goto_state(&st_start);
+    if (time_state() > 3.f)
+        goto_state(&st_exit);
 
     gui_timer(id, dt);
 }
 
 static int over_click(int b, int d)
 {
-    return (b == SDL_BUTTON_LEFT && d == 1) ? goto_state(&st_start) : 1;
+    return (b == SDL_BUTTON_LEFT && d == 1) ? goto_state(&st_exit) : 1;
 }
 
 static int over_buttn(int b, int d)
@@ -73,7 +70,7 @@ static int over_buttn(int b, int d)
     {
         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b) ||
             config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-            return goto_state(&st_start);
+            return goto_state(&st_exit);
     }
     return 1;
 }
index 5765a28..c740a0a 100644 (file)
@@ -23,7 +23,7 @@
 #include "game_common.h"
 
 #include "st_play.h"
-#include "st_over.h"
+#include "st_level.h"
 #include "st_pause.h"
 #include "st_shared.h"
 
@@ -60,7 +60,7 @@ static int pause_action(int i)
         progress_stop();
         SDL_PauseAudio(0);
         audio_music_stop();
-        return goto_state(&st_over);
+        return goto_state(&st_exit);
     }
 
     return 1;
index 3edc95f..8f1d878 100644 (file)
@@ -29,7 +29,6 @@
 #include "st_play.h"
 #include "st_goal.h"
 #include "st_fail.h"
-#include "st_over.h"
 #include "st_pause.h"
 #include "st_level.h"
 #include "st_shared.h"
@@ -49,7 +48,7 @@ static int pause_or_exit(void)
 
         video_clr_grab();
 
-        return goto_state(&st_over);
+        return goto_state(&st_exit);
     }
 }
 
index 57eb159..9122c15 100644 (file)
@@ -23,7 +23,6 @@
 #include "game_common.h"
 
 #include "st_set.h"
-#include "st_over.h"
 #include "st_level.h"
 #include "st_start.h"
 #include "st_title.h"