Ctrl overrides jump drive safety protocols. Vipers can be legitimate
[newkind] / options.c
1 /*
2 * Elite - The New Kind.
3 *
4 * Reverse engineered from the BBC disk version of Elite.
5 * Additional material by C.J.Pinder.
6 *
7 * The original Elite code is (C) I.Bell & D.Braben 1984.
8 * This version re-engineered in C by C.J.Pinder 1999-2001.
9 *
10 * email: <christian@newkind.co.uk>
11 *
12 *
13 */
14
15 /*
16 * Options.c
17 */
18
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include "elite.h"
23 #include "config.h"
24 #include "gfx.h"
25 #include "options.h"
26 #include "main.h"
27 #include "docked.h"
28 #include "file.h"
29
30 static int hilite_item;
31
32 #define NUM_OPTIONS 4
33 #define NUM_SETTINGS 6
34
35 #define OPTION_BAR_WIDTH (400)
36 #define OPTION_BAR_HEIGHT (15)
37
38 struct option
39 {
40 char *text;
41 int docked_only;
42 };
43
44 static struct option option_list[NUM_OPTIONS] =
45 {
46 {"Save Commander", 1},
47 {"Load Commander", 1},
48 {"Game Settings", 0},
49 {"Quit", 0}
50 };
51
52 struct setting
53 {
54 char *name;
55 char *value[5];
56 };
57
58 static struct setting setting_list[NUM_SETTINGS] =
59 {
60 {"Graphics:", {"Solid", "Wireframe", "", "", ""}},
61 {"Anti Alias:", {"Off", "On", "", "", ""}},
62 {"Planet Style:", {"Wireframe", "Green", "SNES", "Fractal", ""}},
63 {"Planet Desc.:", {"BBC", "MSX", "", "", ""}},
64 {"Instant Dock:", {"Off", "On", "", "", ""}},
65 {"Save Settings", {"", "", "", "", ""}}
66 };
67
68
69 void quit_screen (void)
70 {
71 current_screen = SCR_QUIT;
72
73 gfx_clear_display();
74 gfx_display_centre_text (10, "GAME OPTIONS", 140, GFX_COL_GOLD);
75 gfx_draw_line (0, 36, 511, 36);
76
77 gfx_display_centre_text (175, "QUIT GAME (Y/N)?", 140, GFX_COL_GOLD);
78 }
79
80
81
82
83
84 void display_setting_item (int item)
85 {
86 int x,y;
87 int v;
88
89 if (item == (NUM_SETTINGS - 1))
90 {
91 y = ((NUM_SETTINGS + 1) / 2) * 30 + 96 + 32;
92 gfx_display_centre_text (y, setting_list[item].name, 120, GFX_COL_WHITE);
93 return;
94 }
95
96 switch (item)
97 {
98 case 0:
99 v = wireframe;
100 break;
101
102 case 1:
103 v = anti_alias_gfx;
104 break;
105
106 case 2:
107 v = planet_render_style;
108 break;
109
110 case 3:
111 v = hoopy_casinos;
112 break;
113
114 case 4:
115 v = instant_dock;
116 break;
117
118 default:
119 v = 0;
120 break;
121 }
122
123 x = (item & 1) * 250 + 32;
124 y = (item / 2) * 30 + 96;
125
126 gfx_display_colour_text (x, y, setting_list[item].name, GFX_COL_WHITE);
127 gfx_display_colour_text (x + 120, y, setting_list[item].value[v], GFX_COL_WHITE);
128 }
129
130
131 void highlight_setting (int item)
132 {
133 int x,y;
134 int width;
135
136 if ((hilite_item != -1) && (hilite_item != item))
137 {
138 if (hilite_item == (NUM_SETTINGS - 1))
139 {
140 x = GFX_X_CENTRE - (OPTION_BAR_WIDTH / 2);
141 y = ((NUM_SETTINGS + 1) / 2) * 30 + 96 + 32;
142 width = OPTION_BAR_WIDTH;
143 }
144 else
145 {
146 x = (hilite_item & 1) * 250 + 32 + 120;
147 y = (hilite_item / 2) * 30 + 96;
148 width = 100;
149 }
150
151 gfx_clear_area (x, y, x + width, y + OPTION_BAR_HEIGHT);
152 display_setting_item (hilite_item);
153 }
154
155 if (item == (NUM_SETTINGS - 1))
156 {
157 x = GFX_X_CENTRE - (OPTION_BAR_WIDTH / 2);
158 y = ((NUM_SETTINGS + 1) / 2) * 30 + 96 + 32;
159 width = OPTION_BAR_WIDTH;
160 }
161 else
162 {
163 x = (item & 1) * 250 + 32 + 120;
164 y = (item / 2) * 30 + 96;
165 width = 100;
166 }
167
168 gfx_draw_rectangle (x, y, x + width, y + OPTION_BAR_HEIGHT, GFX_COL_DARK_RED);
169 display_setting_item (item);
170 hilite_item = item;
171 }
172
173
174
175 void select_left_setting (void)
176 {
177 if ((hilite_item & 1) != 0)
178 highlight_setting (hilite_item - 1);
179 }
180
181 void select_right_setting (void)
182 {
183 if (((hilite_item & 1) == 0) && (hilite_item < (NUM_SETTINGS - 1)))
184 highlight_setting (hilite_item + 1);
185 }
186
187
188 void select_up_setting (void)
189 {
190 if (hilite_item == (NUM_SETTINGS - 1))
191 {
192 highlight_setting (NUM_SETTINGS - 2);
193 return;
194 }
195
196 if (hilite_item > 1)
197 highlight_setting (hilite_item - 2);
198 }
199
200
201 void select_down_setting (void)
202 {
203 if (hilite_item == (NUM_SETTINGS - 2))
204 {
205 highlight_setting (NUM_SETTINGS - 1);
206 return;
207 }
208
209 if (hilite_item < (NUM_SETTINGS - 2))
210 highlight_setting (hilite_item + 2);
211 }
212
213 void toggle_setting (void)
214 {
215 if (hilite_item == (NUM_SETTINGS - 1))
216 {
217 write_config_file();
218 display_options();
219 return;
220 }
221
222 switch (hilite_item)
223 {
224 case 0:
225 wireframe ^= 1;
226 break;
227
228 case 1:
229 anti_alias_gfx ^= 1;
230 break;
231
232 case 2:
233 planet_render_style = (planet_render_style + 1) % 4;
234 break;
235
236 case 3:
237 hoopy_casinos ^= 1;
238 break;
239
240 case 4:
241 instant_dock ^= 1;
242 break;
243 }
244
245 highlight_setting (hilite_item);
246 }
247
248
249 void game_settings_screen (void)
250 {
251 int i;
252
253 current_screen = SCR_SETTINGS;
254
255 gfx_clear_display();
256 gfx_display_centre_text (10, "GAME SETTINGS", 140, GFX_COL_GOLD);
257 gfx_draw_line (0, 36, 511, 36);
258
259 for (i = 0; i < NUM_SETTINGS; i++)
260 {
261 display_setting_item (i);
262 }
263
264 hilite_item = -1;
265 highlight_setting (0);
266 }
267
268
269 void display_option_item (int i)
270 {
271 int y;
272 int col;
273
274 y = (384 - (30 * NUM_OPTIONS)) / 2;
275 y += i * 30;
276 col = ((!docked) && option_list[i].docked_only) ? GFX_COL_GREY_1 : GFX_COL_WHITE;
277
278 gfx_display_centre_text (y, option_list[i].text, 120, col);
279 }
280
281
282 void highlight_option (int i)
283 {
284 int y;
285 int x;
286
287 if ((hilite_item != -1) && (hilite_item != i))
288 {
289 x = GFX_X_CENTRE - (OPTION_BAR_WIDTH / 2);
290 y = (384 - (30 * NUM_OPTIONS)) / 2;
291 y += hilite_item * 30;
292 gfx_clear_area (x, y, x + OPTION_BAR_WIDTH, y + OPTION_BAR_HEIGHT);
293 display_option_item (hilite_item);
294 }
295
296 x = GFX_X_CENTRE - (OPTION_BAR_WIDTH / 2);
297 y = (384 - (30 * NUM_OPTIONS)) / 2;
298 y += i * 30;
299
300 gfx_draw_rectangle (x, y, x + OPTION_BAR_WIDTH, y + OPTION_BAR_HEIGHT,
301 GFX_COL_DARK_RED);
302 display_option_item (i);
303
304 hilite_item = i;
305 }
306
307 void select_previous_option (void)
308 {
309 if (hilite_item > 0)
310 highlight_option (hilite_item - 1);
311 }
312
313 void select_next_option (void)
314 {
315 if (hilite_item < (NUM_OPTIONS - 1))
316 highlight_option (hilite_item + 1);
317 }
318
319
320 void do_option (void)
321 {
322 if ((!docked) && option_list[hilite_item].docked_only)
323 return;
324
325 switch (hilite_item)
326 {
327 case 0:
328 save_commander_screen();
329 break;
330
331 case 1:
332 load_commander_screen();
333 display_commander_status();
334 break;
335
336 case 2:
337 game_settings_screen();
338 break;
339
340 case 3:
341 quit_screen();
342 break;
343 }
344 }
345
346
347 void display_options (void)
348 {
349 int i;
350
351 current_screen = SCR_OPTIONS;
352
353 gfx_clear_display();
354 gfx_display_centre_text (10, "GAME OPTIONS", 140, GFX_COL_GOLD);
355 gfx_draw_line (0, 36, 511, 36);
356 gfx_display_centre_text (300, "Version: Release 1.0", 120, GFX_COL_WHITE);
357 gfx_display_centre_text (320, "www.newkind.co.uk", 120, GFX_COL_WHITE);
358 gfx_display_centre_text (340, "Written by Christian Pinder 1999-2001", 120, GFX_COL_WHITE);
359 gfx_display_centre_text (360, "Based on original code by Ian Bell & David Braben", 120, GFX_COL_WHITE);
360
361 for (i = 0; i < NUM_OPTIONS; i++)
362 display_option_item (i);
363
364 hilite_item = -1;
365 highlight_option (0);
366 }