Assume map compatibility by default if client's map version is 1
[neverball] / ball / st_time_out.c
1 /*
2  * Copyright (C) 2007 Robert Kooima
3  *
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.
8  *
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.
13  */
14
15 #include "util.h"
16 #include "progress.h"
17 #include "demo.h"
18 #include "audio.h"
19 #include "gui.h"
20 #include "config.h"
21 #include "video.h"
22
23 #include "game_common.h"
24
25 #include "st_over.h"
26 #include "st_start.h"
27 #include "st_save.h"
28 #include "st_time_out.h"
29 #include "st_level.h"
30 #include "st_shared.h"
31 #include "st_play.h"
32
33 /*---------------------------------------------------------------------------*/
34
35 #define TIME_OUT_NEXT 1
36 #define TIME_OUT_SAME 2
37 #define TIME_OUT_SAVE 3
38 #define TIME_OUT_BACK 4
39 #define TIME_OUT_OVER 5
40
41 static int time_out_action(int i)
42 {
43     audio_play(AUD_MENU, 1.0f);
44
45     switch (i)
46     {
47     case TIME_OUT_BACK:
48         /* Fall through. */
49
50     case TIME_OUT_OVER:
51         progress_stop();
52         return goto_state(&st_over);
53
54     case TIME_OUT_SAVE:
55         progress_stop();
56         return goto_save(&st_time_out, &st_time_out);
57
58     case TIME_OUT_NEXT:
59         if (progress_next())
60             return goto_state(&st_level);
61         break;
62
63     case TIME_OUT_SAME:
64         if (progress_same())
65             return goto_state(&st_level);
66         break;
67     }
68
69     return 1;
70 }
71
72 static int time_out_enter(void)
73 {
74     int id, jd, kd;
75
76     if ((id = gui_vstack(0)))
77     {
78         kd = gui_label(id, _("Time's Up!"), GUI_LRG, GUI_ALL, gui_gry, gui_red);
79
80         gui_space(id);
81
82         if ((jd = gui_harray(id)))
83         {
84             if (progress_dead())
85                 gui_start(jd, _("Exit"), GUI_SML, TIME_OUT_OVER, 0);
86
87             if (progress_next_avail())
88                 gui_start(jd, _("Next Level"), GUI_SML, TIME_OUT_NEXT, 0);
89
90             if (progress_same_avail())
91                 gui_start(jd, _("Retry Level"), GUI_SML, TIME_OUT_SAME, 0);
92
93             if (demo_saved())
94                 gui_state(jd, _("Save Replay"), GUI_SML, TIME_OUT_SAVE, 0);
95         }
96         gui_space(id);
97
98         gui_pulse(kd, 1.2f);
99         gui_layout(id, 0, 0);
100     }
101
102     audio_music_fade_out(2.0f);
103     /* audio_play(AUD_TIME, 1.0f); */
104
105     video_clr_grab();
106
107     return id;
108 }
109
110 static int time_out_keybd(int c, int d)
111 {
112     if (d)
113     {
114         if (config_tst_d(CONFIG_KEY_RESTART, c) && progress_same_avail())
115         {
116             if (progress_same())
117                 goto_state(&st_play_ready);
118         }
119     }
120     return 1;
121 }
122
123 static int time_out_buttn(int b, int d)
124 {
125     if (d)
126     {
127         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
128             return time_out_action(gui_token(gui_click()));
129         if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
130             return time_out_action(TIME_OUT_BACK);
131     }
132     return 1;
133 }
134
135 /*---------------------------------------------------------------------------*/
136
137 struct state st_time_out = {
138     time_out_enter,
139     shared_leave,
140     shared_paint,
141     shared_timer,
142     shared_point,
143     shared_stick,
144     shared_angle,
145     shared_click,
146     time_out_keybd,
147     time_out_buttn,
148     1, 0
149 };
150