3
* An Idea and Atari version: LK Avalon, Janusz Pelc, 1989
4
* Linux Code: Arkadiusz Lipiec, 2002-2009
5
* <arkadiusz.lipiec@gmail.com>
7
* <thunorsif@hotmail.com>
9
* GNU Robbo is free software - you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License as published by
11
* the Free Software Foundation; either version 2, or (at your option)
14
* GNU Robbo is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the impled warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU General Public License
20
* along with GNU CC; see the file COPYING. If not, write to the
21
* Free Software Foundation, 59 Temple Place - Suite 330,
22
* Boston, MA 02111-1307, USA.
30
#define DEBUG_READ_RESOURCE_FILE
37
/* Function prototypes */
40
/***************************************************************************
41
* Read Resource File *
42
***************************************************************************/
43
/* Reads resource file data.
44
On entry: filename is the full path to the rc file
45
On exit: returns 0 if successful
46
returns 1 if file not found
47
returns 2 if rc data corrupt */
49
int read_resource_file(char *filename) {
52
int read_game_cycle_limit = UNDEFINED, read_game_cycle_delay = UNDEFINED;
53
int read_default_joystick = UNDEFINED, read_joystick_dead_zone = UNDEFINED;
54
char read_default_joystick_name[MAX_JOYSTICK_NAME_LENGTH];
55
int read_key_repeat_delay = UNDEFINED, read_key_repeat_interval = UNDEFINED;
56
char read_selected_skin[100], read_selected_locale[100];
57
int read_sensible_bears = UNDEFINED, read_sensible_questionmarks = UNDEFINED, read_sensible_solid_lasers = UNDEFINED;
58
struct pack read_level_packs[MAX_LEVEL_PACKS];
59
int read_pack_count = 0, count, count2, error_found = FALSE, found;
60
struct control read_user_controls[USER_CONTROLS];
61
char error_setting[50];
63
strcpy(read_default_joystick_name, "-1");
64
strcpy(read_selected_skin, "-1");
65
strcpy(read_selected_locale, "-1");
67
fprintf(stdout, "Reading from %s\n", filename);
68
if ((fp = fopen(filename, "r")) == NULL) {
69
fprintf(stdout, "%s not found\n", filename);
73
/* Reset read_level_packs so we can test for missing settings */
74
for (count = 0; count < MAX_LEVEL_PACKS; count++) {
75
strcpy(read_level_packs[count].filename, "-1");
76
read_level_packs[count].level_reached = UNDEFINED;
77
read_level_packs[count].level_selected = UNDEFINED;
78
read_level_packs[count].selected = UNDEFINED;
81
/* Reset read_user_controls so we can test for missing settings */
82
for (count = 0; count < USER_CONTROLS; count++) {
83
read_user_controls[count].device = UNDEFINED2; /* Note use of UNDEFINED2 (-2) as UNDEFINED (-1) is used */
84
read_user_controls[count].id = UNDEFINED2;
85
read_user_controls[count].mod = UNDEFINED2;
88
/* Read the rc data into read_level_packs */
89
while (fscanf(fp, "%s", line) == 1) {
90
if (!strncmp(line, "[game_cycle_limit]", 18)) {
91
fscanf(fp, "%i", &read_game_cycle_limit);
92
} else if (!strncmp(line, "[game_cycle_delay]", 18)) {
93
fscanf(fp, "%i", &read_game_cycle_delay);
94
} else if (!strncmp(line, "[default_joystick]", 18)) {
95
fscanf(fp, "%i", &read_default_joystick);
96
} else if (!strncmp(line, "[default_joystick_name]", 23)) {
97
/* Have to use fgets here although it isn't perfect either.
98
The problem is the name can have spaces in it and fgets
99
gets [CR]LFs too so we have to clean up the line end */
100
fgets(read_default_joystick_name, MAX_JOYSTICK_NAME_LENGTH, fp); /* Reads the [CR]LF at the end of the previous line */
101
fgets(read_default_joystick_name, MAX_JOYSTICK_NAME_LENGTH, fp); /* Reads the name + one or more [CR]LFs */
102
/* MacOSX and Unix is LF, Win and Mac is CRLF */
103
for (count = strlen(read_default_joystick_name) - 1; count >= 0; count--) if (read_default_joystick_name[count] == 13 || read_default_joystick_name[count] == 10) read_default_joystick_name[count] = 0;
104
} else if (!strncmp(line, "[joystick_dead_zone]", 20)) {
105
fscanf(fp, "%i", &read_joystick_dead_zone);
106
} else if (!strncmp(line, "[key_repeat_delay]", 18)) {
107
fscanf(fp, "%i", &read_key_repeat_delay);
108
} else if (!strncmp(line, "[key_repeat_interval]", 21)) {
109
fscanf(fp, "%i", &read_key_repeat_interval);
110
} else if (!strncmp(line, "[selected_skin]", 15)) {
111
fscanf(fp, "%s", read_selected_skin);
112
} else if (!strncmp(line, "[selected_locale]", 17)) {
113
fscanf(fp, "%s", read_selected_locale);
114
} else if (!strncmp(line, "[sensible_bears]", 16)) {
115
fscanf(fp, "%i", &read_sensible_bears);
116
} else if (!strncmp(line, "[sensible_questionmarks]", 24)) {
117
fscanf(fp, "%i", &read_sensible_questionmarks);
118
} else if (!strncmp(line, "[sensible_solid_lasers]", 23)) {
119
fscanf(fp, "%i", &read_sensible_solid_lasers);
120
} else if (!strncmp(line, "[filename]", 10)) {
121
fscanf(fp, "%s", read_level_packs[read_pack_count].filename);
122
} else if (!strncmp(line, "[level_reached]", 15)) {
123
fscanf(fp, "%i", &read_level_packs[read_pack_count].level_reached);
124
} else if (!strncmp(line, "[level_selected]", 16)) {
125
fscanf(fp, "%i", &read_level_packs[read_pack_count].level_selected);
126
} else if (!strncmp(line, "[selected]", 10)) {
127
fscanf(fp, "%i", &read_level_packs[read_pack_count].selected);
129
if (read_pack_count >= MAX_LEVEL_PACKS) break;
130
} else if (!strncmp(line, "[ACTION_UP.device]", 18)) {
131
fscanf(fp, "%i", &read_user_controls[ACTION_UP].device);
132
} else if (!strncmp(line, "[ACTION_UP.id]", 14)) {
133
fscanf(fp, "%i", &read_user_controls[ACTION_UP].id);
134
} else if (!strncmp(line, "[ACTION_UP.mod]", 15)) {
135
fscanf(fp, "%i", &read_user_controls[ACTION_UP].mod);
136
} else if (!strncmp(line, "[ACTION_DOWN.device]", 20)) {
137
fscanf(fp, "%i", &read_user_controls[ACTION_DOWN].device);
138
} else if (!strncmp(line, "[ACTION_DOWN.id]", 16)) {
139
fscanf(fp, "%i", &read_user_controls[ACTION_DOWN].id);
140
} else if (!strncmp(line, "[ACTION_DOWN.mod]", 17)) {
141
fscanf(fp, "%i", &read_user_controls[ACTION_DOWN].mod);
142
} else if (!strncmp(line, "[ACTION_LEFT.device]", 20)) {
143
fscanf(fp, "%i", &read_user_controls[ACTION_LEFT].device);
144
} else if (!strncmp(line, "[ACTION_LEFT.id]", 16)) {
145
fscanf(fp, "%i", &read_user_controls[ACTION_LEFT].id);
146
} else if (!strncmp(line, "[ACTION_LEFT.mod]", 17)) {
147
fscanf(fp, "%i", &read_user_controls[ACTION_LEFT].mod);
148
} else if (!strncmp(line, "[ACTION_RIGHT.device]", 21)) {
149
fscanf(fp, "%i", &read_user_controls[ACTION_RIGHT].device);
150
} else if (!strncmp(line, "[ACTION_RIGHT.id]", 17)) {
151
fscanf(fp, "%i", &read_user_controls[ACTION_RIGHT].id);
152
} else if (!strncmp(line, "[ACTION_RIGHT.mod]", 18)) {
153
fscanf(fp, "%i", &read_user_controls[ACTION_RIGHT].mod);
154
} else if (!strncmp(line, "[ACTION_SHOOT_UP.device]", 24)) {
155
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_UP].device);
156
} else if (!strncmp(line, "[ACTION_SHOOT_UP.id]", 20)) {
157
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_UP].id);
158
} else if (!strncmp(line, "[ACTION_SHOOT_UP.mod]", 21)) {
159
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_UP].mod);
160
} else if (!strncmp(line, "[ACTION_SHOOT_DOWN.device]", 26)) {
161
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_DOWN].device);
162
} else if (!strncmp(line, "[ACTION_SHOOT_DOWN.id]", 22)) {
163
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_DOWN].id);
164
} else if (!strncmp(line, "[ACTION_SHOOT_DOWN.mod]", 23)) {
165
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_DOWN].mod);
166
} else if (!strncmp(line, "[ACTION_SHOOT_LEFT.device]", 26)) {
167
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_LEFT].device);
168
} else if (!strncmp(line, "[ACTION_SHOOT_LEFT.id]", 22)) {
169
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_LEFT].id);
170
} else if (!strncmp(line, "[ACTION_SHOOT_LEFT.mod]", 23)) {
171
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_LEFT].mod);
172
} else if (!strncmp(line, "[ACTION_SHOOT_RIGHT.device]", 27)) {
173
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_RIGHT].device);
174
} else if (!strncmp(line, "[ACTION_SHOOT_RIGHT.id]", 23)) {
175
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_RIGHT].id);
176
} else if (!strncmp(line, "[ACTION_SHOOT_RIGHT.mod]", 24)) {
177
fscanf(fp, "%i", &read_user_controls[ACTION_SHOOT_RIGHT].mod);
178
} else if (!strncmp(line, "[ACTION_SELECT.device]", 22)) {
179
fscanf(fp, "%i", &read_user_controls[ACTION_SELECT].device);
180
} else if (!strncmp(line, "[ACTION_SELECT.id]", 18)) {
181
fscanf(fp, "%i", &read_user_controls[ACTION_SELECT].id);
182
} else if (!strncmp(line, "[ACTION_SELECT.mod]", 19)) {
183
fscanf(fp, "%i", &read_user_controls[ACTION_SELECT].mod);
184
} else if (!strncmp(line, "[ACTION_EXIT.device]", 20)) {
185
fscanf(fp, "%i", &read_user_controls[ACTION_EXIT].device);
186
} else if (!strncmp(line, "[ACTION_EXIT.id]", 16)) {
187
fscanf(fp, "%i", &read_user_controls[ACTION_EXIT].id);
188
} else if (!strncmp(line, "[ACTION_EXIT.mod]", 17)) {
189
fscanf(fp, "%i", &read_user_controls[ACTION_EXIT].mod);
190
} else if (!strncmp(line, "[ACTION_HELP.device]", 20)) {
191
fscanf(fp, "%i", &read_user_controls[ACTION_HELP].device);
192
} else if (!strncmp(line, "[ACTION_HELP.id]", 16)) {
193
fscanf(fp, "%i", &read_user_controls[ACTION_HELP].id);
194
} else if (!strncmp(line, "[ACTION_HELP.mod]", 17)) {
195
fscanf(fp, "%i", &read_user_controls[ACTION_HELP].mod);
196
} else if (!strncmp(line, "[ACTION_OPTIONS.device]", 23)) {
197
fscanf(fp, "%i", &read_user_controls[ACTION_OPTIONS].device);
198
} else if (!strncmp(line, "[ACTION_OPTIONS.id]", 19)) {
199
fscanf(fp, "%i", &read_user_controls[ACTION_OPTIONS].id);
200
} else if (!strncmp(line, "[ACTION_OPTIONS.mod]", 20)) {
201
fscanf(fp, "%i", &read_user_controls[ACTION_OPTIONS].mod);
202
} else if (!strncmp(line, "[ACTION_RESTART.device]", 23)) {
203
fscanf(fp, "%i", &read_user_controls[ACTION_RESTART].device);
204
} else if (!strncmp(line, "[ACTION_RESTART.id]", 19)) {
205
fscanf(fp, "%i", &read_user_controls[ACTION_RESTART].id);
206
} else if (!strncmp(line, "[ACTION_RESTART.mod]", 20)) {
207
fscanf(fp, "%i", &read_user_controls[ACTION_RESTART].mod);
208
} else if (!strncmp(line, "[ACTION_PREVIOUS_LEVEL.device]", 30)) {
209
fscanf(fp, "%i", &read_user_controls[ACTION_PREVIOUS_LEVEL].device);
210
} else if (!strncmp(line, "[ACTION_PREVIOUS_LEVEL.id]", 26)) {
211
fscanf(fp, "%i", &read_user_controls[ACTION_PREVIOUS_LEVEL].id);
212
} else if (!strncmp(line, "[ACTION_PREVIOUS_LEVEL.mod]", 27)) {
213
fscanf(fp, "%i", &read_user_controls[ACTION_PREVIOUS_LEVEL].mod);
214
} else if (!strncmp(line, "[ACTION_NEXT_LEVEL.device]", 26)) {
215
fscanf(fp, "%i", &read_user_controls[ACTION_NEXT_LEVEL].device);
216
} else if (!strncmp(line, "[ACTION_NEXT_LEVEL.id]", 22)) {
217
fscanf(fp, "%i", &read_user_controls[ACTION_NEXT_LEVEL].id);
218
} else if (!strncmp(line, "[ACTION_NEXT_LEVEL.mod]", 23)) {
219
fscanf(fp, "%i", &read_user_controls[ACTION_NEXT_LEVEL].mod);
220
} else if (!strncmp(line, "[ACTION_PREVIOUS_PACK.device]", 29)) {
221
fscanf(fp, "%i", &read_user_controls[ACTION_PREVIOUS_PACK].device);
222
} else if (!strncmp(line, "[ACTION_PREVIOUS_PACK.id]", 25)) {
223
fscanf(fp, "%i", &read_user_controls[ACTION_PREVIOUS_PACK].id);
224
} else if (!strncmp(line, "[ACTION_PREVIOUS_PACK.mod]", 26)) {
225
fscanf(fp, "%i", &read_user_controls[ACTION_PREVIOUS_PACK].mod);
226
} else if (!strncmp(line, "[ACTION_NEXT_PACK.device]", 25)) {
227
fscanf(fp, "%i", &read_user_controls[ACTION_NEXT_PACK].device);
228
} else if (!strncmp(line, "[ACTION_NEXT_PACK.id]", 21)) {
229
fscanf(fp, "%i", &read_user_controls[ACTION_NEXT_PACK].id);
230
} else if (!strncmp(line, "[ACTION_NEXT_PACK.mod]", 22)) {
231
fscanf(fp, "%i", &read_user_controls[ACTION_NEXT_PACK].mod);
232
} else if (!strncmp(line, "[ACTION_MODIFIER1.device]", 25)) {
233
fscanf(fp, "%i", &read_user_controls[ACTION_MODIFIER1].device);
234
} else if (!strncmp(line, "[ACTION_MODIFIER1.id]", 21)) {
235
fscanf(fp, "%i", &read_user_controls[ACTION_MODIFIER1].id);
236
} else if (!strncmp(line, "[ACTION_MODIFIER1.mod]", 22)) {
237
fscanf(fp, "%i", &read_user_controls[ACTION_MODIFIER1].mod);
238
} else if (!strncmp(line, "[ACTION_MODIFIER2.device]", 25)) {
239
fscanf(fp, "%i", &read_user_controls[ACTION_MODIFIER2].device);
240
} else if (!strncmp(line, "[ACTION_MODIFIER2.id]", 21)) {
241
fscanf(fp, "%i", &read_user_controls[ACTION_MODIFIER2].id);
242
} else if (!strncmp(line, "[ACTION_MODIFIER2.mod]", 22)) {
243
fscanf(fp, "%i", &read_user_controls[ACTION_MODIFIER2].mod);
244
} else if (!strncmp(line, "[ACTION_TOGGLE_FULLSCREEN.device]", 33)) {
245
fscanf(fp, "%i", &read_user_controls[ACTION_TOGGLE_FULLSCREEN].device);
246
} else if (!strncmp(line, "[ACTION_TOGGLE_FULLSCREEN.id]", 29)) {
247
fscanf(fp, "%i", &read_user_controls[ACTION_TOGGLE_FULLSCREEN].id);
248
} else if (!strncmp(line, "[ACTION_TOGGLE_FULLSCREEN.mod]", 30)) {
249
fscanf(fp, "%i", &read_user_controls[ACTION_TOGGLE_FULLSCREEN].mod);
250
} else if (!strncmp(line, "[ACTION_HOME.device]", 20)) {
251
fscanf(fp, "%i", &read_user_controls[ACTION_HOME].device);
252
} else if (!strncmp(line, "[ACTION_HOME.id]", 16)) {
253
fscanf(fp, "%i", &read_user_controls[ACTION_HOME].id);
254
} else if (!strncmp(line, "[ACTION_HOME.mod]", 17)) {
255
fscanf(fp, "%i", &read_user_controls[ACTION_HOME].mod);
256
} else if (!strncmp(line, "[ACTION_END.device]", 19)) {
257
fscanf(fp, "%i", &read_user_controls[ACTION_END].device);
258
} else if (!strncmp(line, "[ACTION_END.id]", 15)) {
259
fscanf(fp, "%i", &read_user_controls[ACTION_END].id);
260
} else if (!strncmp(line, "[ACTION_END.mod]", 16)) {
261
fscanf(fp, "%i", &read_user_controls[ACTION_END].mod);
262
} else if (!strncmp(line, "[ACTION_PAGEUP.device]", 22)) {
263
fscanf(fp, "%i", &read_user_controls[ACTION_PAGEUP].device);
264
} else if (!strncmp(line, "[ACTION_PAGEUP.id]", 18)) {
265
fscanf(fp, "%i", &read_user_controls[ACTION_PAGEUP].id);
266
} else if (!strncmp(line, "[ACTION_PAGEUP.mod]", 19)) {
267
fscanf(fp, "%i", &read_user_controls[ACTION_PAGEUP].mod);
268
} else if (!strncmp(line, "[ACTION_PAGEDOWN.device]", 24)) {
269
fscanf(fp, "%i", &read_user_controls[ACTION_PAGEDOWN].device);
270
} else if (!strncmp(line, "[ACTION_PAGEDOWN.id]", 20)) {
271
fscanf(fp, "%i", &read_user_controls[ACTION_PAGEDOWN].id);
272
} else if (!strncmp(line, "[ACTION_PAGEDOWN.mod]", 21)) {
273
fscanf(fp, "%i", &read_user_controls[ACTION_PAGEDOWN].mod);
274
} else if (!strncmp(line, "[ACTION_VOLUP.device]", 21)) {
275
fscanf(fp, "%i", &read_user_controls[ACTION_VOLUP].device);
276
} else if (!strncmp(line, "[ACTION_VOLUP.id]", 17)) {
277
fscanf(fp, "%i", &read_user_controls[ACTION_VOLUP].id);
278
} else if (!strncmp(line, "[ACTION_VOLUP.mod]", 18)) {
279
fscanf(fp, "%i", &read_user_controls[ACTION_VOLUP].mod);
280
} else if (!strncmp(line, "[ACTION_VOLDOWN.device]", 23)) {
281
fscanf(fp, "%i", &read_user_controls[ACTION_VOLDOWN].device);
282
} else if (!strncmp(line, "[ACTION_VOLDOWN.id]", 19)) {
283
fscanf(fp, "%i", &read_user_controls[ACTION_VOLDOWN].id);
284
} else if (!strncmp(line, "[ACTION_VOLDOWN.mod]", 20)) {
285
fscanf(fp, "%i", &read_user_controls[ACTION_VOLDOWN].mod);
291
#ifdef DEBUG_READ_RESOURCE_FILE
292
printf("*** Start %s ***\n", __func__);
293
printf("read_game_cycle_limit=%i\n", read_game_cycle_limit);
294
printf("read_game_cycle_delay=%i\n", read_game_cycle_delay);
295
printf("read_default_joystick=%i\n", read_default_joystick);
296
printf("read_default_joystick_name=%s\n", read_default_joystick_name);
297
printf("read_joystick_dead_zone=%i\n", read_joystick_dead_zone);
298
printf("read_key_repeat_delay=%i\n", read_key_repeat_delay);
299
printf("read_key_repeat_interval=%i\n", read_key_repeat_interval);
300
printf("read_selected_skin=%s\n", read_selected_skin);
301
printf("read_selected_locale=%s\n", read_selected_locale);
302
printf("read_sensible_bears=%i\n", read_sensible_bears);
303
printf("read_sensible_questionmarks=%i\n", read_sensible_questionmarks);
304
printf("read_sensible_solid_lasers=%i\n", read_sensible_solid_lasers);
305
for (count = 0; count < read_pack_count; count++) {
306
printf("read_level_packs[%i].filename=%s\n", count, read_level_packs[count].filename);
307
printf("read_level_packs[%i].level_reached=%i\n", count, read_level_packs[count].level_reached);
308
printf("read_level_packs[%i].level_selected=%i\n", count, read_level_packs[count].level_selected);
309
printf("read_level_packs[%i].selected=%i\n", count, read_level_packs[count].selected);
311
for (count = 0; count < USER_CONTROLS; count++) {
312
printf("read_user_controls[%i].device=%i\n", count, read_user_controls[count].device);
313
printf("read_user_controls[%i].id=%i\n", count, read_user_controls[count].id);
314
printf("read_user_controls[%i].mod=%i\n", count, read_user_controls[count].mod);
316
printf("*** Stop %s ***\n", __func__);
319
/* Now verify there are no FATAL missing settings */
320
/* Forcing the defaults here would erase historical data so we'll just get the user to fix it */
321
for (count = 0; count < read_pack_count; count++) {
322
if (strcmp(read_level_packs[count].filename, "-1") == 0) {
323
error_found = TRUE; strcpy(error_setting, "[filename]");
324
} else if (read_level_packs[count].level_reached == UNDEFINED) {
325
error_found = TRUE; strcpy(error_setting, "[level_reached]");
326
} else if (read_level_packs[count].level_selected == UNDEFINED) {
327
error_found = TRUE; strcpy(error_setting, "[level_selected]");
328
} else if (read_level_packs[count].selected == UNDEFINED) {
329
error_found = TRUE; strcpy(error_setting, "[selected]");
332
/* Missing setting found */
333
fprintf(stdout, "There is a missing %s setting in %s. ", error_setting, filename);
334
fprintf(stdout, "Please fix it or delete the file to have gnurobbo create a new one. ");
335
fprintf(stdout, "Deleting the file will reset all levels reached for all packs played!\n");
341
/* game_cycle_limit */
342
if (read_game_cycle_limit != UNDEFINED) game_cycle_limit = read_game_cycle_limit;
343
/* game_cycle_delay */
344
if (read_game_cycle_delay != UNDEFINED) game_cycle_delay = read_game_cycle_delay;
346
if (read_default_joystick != UNDEFINED) default_joystick = read_default_joystick;
347
if ((strcmp(read_default_joystick_name, "-1")) != 0) strcpy(default_joystick_name, read_default_joystick_name);
348
if (read_joystick_dead_zone != UNDEFINED) joystick_dead_zone = read_joystick_dead_zone;
350
if (read_key_repeat_delay != UNDEFINED) {
351
key_repeat_delay = read_key_repeat_delay;
352
for (count = 0; count < USER_CONTROLS; count++) user_controls[count].delay = KEY_REPEAT_DELAY;
354
if (read_key_repeat_interval != UNDEFINED) {
355
key_repeat_interval = read_key_repeat_interval;
356
for (count = 0; count < USER_CONTROLS; count++) user_controls[count].interval = KEY_REPEAT_INTERVAL;
359
if ((strcmp(read_selected_skin, "-1")) != 0) {
360
for (count = 0; count < skin_count; count++) {
361
if (!strcmp(skins[count].foldername, read_selected_skin)) {
362
selected_skin = count;
367
/* Selected locale */
368
if ((strcmp(read_selected_locale, "-1")) != 0) {
369
for (count = 0; count < locale_count; count++) {
370
if (!strcmp(locales[count].foldername, read_selected_locale)) {
371
selected_locale = count;
377
if (read_sensible_bears != UNDEFINED) game_mechanics.sensible_bears = read_sensible_bears;
378
if (read_sensible_questionmarks != UNDEFINED) game_mechanics.sensible_questionmarks = read_sensible_questionmarks;
379
if (read_sensible_solid_lasers != UNDEFINED) game_mechanics.sensible_solid_lasers = read_sensible_solid_lasers;
381
for (count = 0; count < USER_CONTROLS; count++) {
382
if (read_user_controls[count].device != UNDEFINED2) user_controls[count].device = read_user_controls[count].device;
383
if (read_user_controls[count].id != UNDEFINED2) user_controls[count].id = read_user_controls[count].id;
384
if (read_user_controls[count].mod != UNDEFINED2) user_controls[count].mod = read_user_controls[count].mod;
387
/* Now we need to match up the filenames with those already in the pack list
388
and amend the entries. Any that don't match will be historical entries i.e.
389
the user played a pack that's now been deleted and we don't want to lose these */
390
for (count = 0; count < read_pack_count; count++) {
392
for (count2 = 0; count2 < level_pack_count; count2++) {
393
if (strcmp(level_packs[count2].filename, read_level_packs[count].filename) == 0) {
394
/* A pack from the rc matches with one found so update the pack list */
395
level_packs[count2].level_reached = read_level_packs[count].level_reached;
396
level_packs[count2].level_selected = read_level_packs[count].level_selected;
397
level_packs[count2].selected = read_level_packs[count].selected;
401
if (!found && level_pack_count < MAX_LEVEL_PACKS) {
402
/* The pack from the rc hasn't been found so add it to the end of the pack list as an historical entry */
403
strcpy(level_packs[level_pack_count].filename, read_level_packs[count].filename);
404
strcpy(level_packs[level_pack_count].name, "-1");
405
level_packs[level_pack_count].last_level = UNDEFINED;
406
level_packs[level_pack_count].level_reached = read_level_packs[count].level_reached;
407
level_packs[level_pack_count].level_selected = read_level_packs[count].level_selected;
408
level_packs[level_pack_count].selected = read_level_packs[count].selected;
413
/* There may be more than one, none or a missing pack selected so we'll fix that here */
415
for (count = 0; count < level_pack_count; count++) {
416
/* If a missing pack is selected then deselect it */
417
if (level_packs[count].selected == TRUE && level_packs[count].last_level == UNDEFINED) {
418
level_packs[count].selected = FALSE;
419
} else if (level_packs[count].selected == TRUE) {
420
/* A found pack is selected so deselect all the others */
421
selected_pack = count;
422
for (count2 = 0; count2 < level_pack_count; count2++) {
423
/* Don't deselect the selected pack! */
424
if (count2 != count) level_packs[count2].selected = FALSE;
430
/* If no pack was found to be selected then select the default pack */
432
level_packs[0].selected = TRUE;
436
/* It's also possible that level_selected > level_reached or both are
437
greater than last_level for found packs so we'll fix that here */
438
for (count = 0; count < level_pack_count; count++) {
439
if (level_packs[count].last_level != UNDEFINED) {
440
if (level_packs[count].level_reached > level_packs[count].last_level) level_packs[count].level_reached = level_packs[count].last_level;
441
if (level_packs[count].level_selected > level_packs[count].level_reached) level_packs[count].level_selected = level_packs[count].level_reached;
448
/***************************************************************************
449
* Save Resource File *
450
***************************************************************************/
451
/* Saves resource file data.
453
On entry: filename is the full path to the rc file
454
On exit: returns 1 on error */
456
int save_resource_file(char *filename) {
460
if ((fp = fopen(filename, "w")) == NULL) {
461
fprintf(stdout, "Cannot write to file: %s\n", filename);
465
fprintf(stdout, "Writing to %s\n", filename);
467
fprintf(fp, "[game_cycle_limit]\n%i\n", game_cycle_limit);
468
fprintf(fp, "[game_cycle_delay]\n%i\n", game_cycle_delay);
470
fprintf(fp, "[default_joystick]\n%i\n", default_joystick);
471
if (default_joystick == UNDEFINED) {
472
fprintf(fp, "[default_joystick_name]\n%s\n", "-1");
474
fprintf(fp, "[default_joystick_name]\n%s\n", default_joystick_name);
476
fprintf(fp, "[joystick_dead_zone]\n%i\n", joystick_dead_zone);
478
fprintf(fp, "[key_repeat_delay]\n%i\n", key_repeat_delay);
479
fprintf(fp, "[key_repeat_interval]\n%i\n", key_repeat_interval);
481
fprintf(fp, "[selected_skin]\n%s\n", skins[selected_skin].foldername);
483
fprintf(fp, "[selected_locale]\n%s\n", locales[selected_locale].foldername);
485
fprintf(fp, "[sensible_bears]\n%i\n", game_mechanics.sensible_bears);
486
fprintf(fp, "[sensible_questionmarks]\n%i\n", game_mechanics.sensible_questionmarks);
487
fprintf(fp, "[sensible_solid_lasers]\n%i\n", game_mechanics.sensible_solid_lasers);
489
for (count = 0; count < level_pack_count; count++) {
490
fprintf(fp, "[filename]\n%s\n", level_packs[count].filename);
491
fprintf(fp, "[level_reached]\n%i\n", level_packs[count].level_reached);
492
fprintf(fp, "[level_selected]\n%i\n", level_packs[count].level_selected);
493
fprintf(fp, "[selected]\n%i\n", level_packs[count].selected);
496
fprintf(fp, "[ACTION_UP.device]\n%i\n", user_controls[ACTION_UP].device);
497
fprintf(fp, "[ACTION_UP.id]\n%i\n", user_controls[ACTION_UP].id);
498
fprintf(fp, "[ACTION_UP.mod]\n%i\n", user_controls[ACTION_UP].mod);
499
fprintf(fp, "[ACTION_DOWN.device]\n%i\n", user_controls[ACTION_DOWN].device);
500
fprintf(fp, "[ACTION_DOWN.id]\n%i\n", user_controls[ACTION_DOWN].id);
501
fprintf(fp, "[ACTION_DOWN.mod]\n%i\n", user_controls[ACTION_DOWN].mod);
502
fprintf(fp, "[ACTION_LEFT.device]\n%i\n", user_controls[ACTION_LEFT].device);
503
fprintf(fp, "[ACTION_LEFT.id]\n%i\n", user_controls[ACTION_LEFT].id);
504
fprintf(fp, "[ACTION_LEFT.mod]\n%i\n", user_controls[ACTION_LEFT].mod);
505
fprintf(fp, "[ACTION_RIGHT.device]\n%i\n", user_controls[ACTION_RIGHT].device);
506
fprintf(fp, "[ACTION_RIGHT.id]\n%i\n", user_controls[ACTION_RIGHT].id);
507
fprintf(fp, "[ACTION_RIGHT.mod]\n%i\n", user_controls[ACTION_RIGHT].mod);
508
fprintf(fp, "[ACTION_SHOOT_UP.device]\n%i\n", user_controls[ACTION_SHOOT_UP].device);
509
fprintf(fp, "[ACTION_SHOOT_UP.id]\n%i\n", user_controls[ACTION_SHOOT_UP].id);
510
fprintf(fp, "[ACTION_SHOOT_UP.mod]\n%i\n", user_controls[ACTION_SHOOT_UP].mod);
511
fprintf(fp, "[ACTION_SHOOT_DOWN.device]\n%i\n", user_controls[ACTION_SHOOT_DOWN].device);
512
fprintf(fp, "[ACTION_SHOOT_DOWN.id]\n%i\n", user_controls[ACTION_SHOOT_DOWN].id);
513
fprintf(fp, "[ACTION_SHOOT_DOWN.mod]\n%i\n", user_controls[ACTION_SHOOT_DOWN].mod);
514
fprintf(fp, "[ACTION_SHOOT_LEFT.device]\n%i\n", user_controls[ACTION_SHOOT_LEFT].device);
515
fprintf(fp, "[ACTION_SHOOT_LEFT.id]\n%i\n", user_controls[ACTION_SHOOT_LEFT].id);
516
fprintf(fp, "[ACTION_SHOOT_LEFT.mod]\n%i\n", user_controls[ACTION_SHOOT_LEFT].mod);
517
fprintf(fp, "[ACTION_SHOOT_RIGHT.device]\n%i\n", user_controls[ACTION_SHOOT_RIGHT].device);
518
fprintf(fp, "[ACTION_SHOOT_RIGHT.id]\n%i\n", user_controls[ACTION_SHOOT_RIGHT].id);
519
fprintf(fp, "[ACTION_SHOOT_RIGHT.mod]\n%i\n", user_controls[ACTION_SHOOT_RIGHT].mod);
520
fprintf(fp, "[ACTION_SELECT.device]\n%i\n", user_controls[ACTION_SELECT].device);
521
fprintf(fp, "[ACTION_SELECT.id]\n%i\n", user_controls[ACTION_SELECT].id);
522
fprintf(fp, "[ACTION_SELECT.mod]\n%i\n", user_controls[ACTION_SELECT].mod);
523
fprintf(fp, "[ACTION_EXIT.device]\n%i\n", user_controls[ACTION_EXIT].device);
524
fprintf(fp, "[ACTION_EXIT.id]\n%i\n", user_controls[ACTION_EXIT].id);
525
fprintf(fp, "[ACTION_EXIT.mod]\n%i\n", user_controls[ACTION_EXIT].mod);
526
fprintf(fp, "[ACTION_HELP.device]\n%i\n", user_controls[ACTION_HELP].device);
527
fprintf(fp, "[ACTION_HELP.id]\n%i\n", user_controls[ACTION_HELP].id);
528
fprintf(fp, "[ACTION_HELP.mod]\n%i\n", user_controls[ACTION_HELP].mod);
529
fprintf(fp, "[ACTION_OPTIONS.device]\n%i\n", user_controls[ACTION_OPTIONS].device);
530
fprintf(fp, "[ACTION_OPTIONS.id]\n%i\n", user_controls[ACTION_OPTIONS].id);
531
fprintf(fp, "[ACTION_OPTIONS.mod]\n%i\n", user_controls[ACTION_OPTIONS].mod);
532
fprintf(fp, "[ACTION_RESTART.device]\n%i\n", user_controls[ACTION_RESTART].device);
533
fprintf(fp, "[ACTION_RESTART.id]\n%i\n", user_controls[ACTION_RESTART].id);
534
fprintf(fp, "[ACTION_RESTART.mod]\n%i\n", user_controls[ACTION_RESTART].mod);
535
fprintf(fp, "[ACTION_PREVIOUS_LEVEL.device]\n%i\n", user_controls[ACTION_PREVIOUS_LEVEL].device);
536
fprintf(fp, "[ACTION_PREVIOUS_LEVEL.id]\n%i\n", user_controls[ACTION_PREVIOUS_LEVEL].id);
537
fprintf(fp, "[ACTION_PREVIOUS_LEVEL.mod]\n%i\n", user_controls[ACTION_PREVIOUS_LEVEL].mod);
538
fprintf(fp, "[ACTION_NEXT_LEVEL.device]\n%i\n", user_controls[ACTION_NEXT_LEVEL].device);
539
fprintf(fp, "[ACTION_NEXT_LEVEL.id]\n%i\n", user_controls[ACTION_NEXT_LEVEL].id);
540
fprintf(fp, "[ACTION_NEXT_LEVEL.mod]\n%i\n", user_controls[ACTION_NEXT_LEVEL].mod);
541
fprintf(fp, "[ACTION_PREVIOUS_PACK.device]\n%i\n", user_controls[ACTION_PREVIOUS_PACK].device);
542
fprintf(fp, "[ACTION_PREVIOUS_PACK.id]\n%i\n", user_controls[ACTION_PREVIOUS_PACK].id);
543
fprintf(fp, "[ACTION_PREVIOUS_PACK.mod]\n%i\n", user_controls[ACTION_PREVIOUS_PACK].mod);
544
fprintf(fp, "[ACTION_NEXT_PACK.device]\n%i\n", user_controls[ACTION_NEXT_PACK].device);
545
fprintf(fp, "[ACTION_NEXT_PACK.id]\n%i\n", user_controls[ACTION_NEXT_PACK].id);
546
fprintf(fp, "[ACTION_NEXT_PACK.mod]\n%i\n", user_controls[ACTION_NEXT_PACK].mod);
547
fprintf(fp, "[ACTION_MODIFIER1.device]\n%i\n", user_controls[ACTION_MODIFIER1].device);
548
fprintf(fp, "[ACTION_MODIFIER1.id]\n%i\n", user_controls[ACTION_MODIFIER1].id);
549
fprintf(fp, "[ACTION_MODIFIER1.mod]\n%i\n", user_controls[ACTION_MODIFIER1].mod);
550
fprintf(fp, "[ACTION_MODIFIER2.device]\n%i\n", user_controls[ACTION_MODIFIER2].device);
551
fprintf(fp, "[ACTION_MODIFIER2.id]\n%i\n", user_controls[ACTION_MODIFIER2].id);
552
fprintf(fp, "[ACTION_MODIFIER2.mod]\n%i\n", user_controls[ACTION_MODIFIER2].mod);
553
fprintf(fp, "[ACTION_TOGGLE_FULLSCREEN.device]\n%i\n", user_controls[ACTION_TOGGLE_FULLSCREEN].device);
554
fprintf(fp, "[ACTION_TOGGLE_FULLSCREEN.id]\n%i\n", user_controls[ACTION_TOGGLE_FULLSCREEN].id);
555
fprintf(fp, "[ACTION_TOGGLE_FULLSCREEN.mod]\n%i\n", user_controls[ACTION_TOGGLE_FULLSCREEN].mod);
556
fprintf(fp, "[ACTION_HOME.device]\n%i\n", user_controls[ACTION_HOME].device);
557
fprintf(fp, "[ACTION_HOME.id]\n%i\n", user_controls[ACTION_HOME].id);
558
fprintf(fp, "[ACTION_HOME.mod]\n%i\n", user_controls[ACTION_HOME].mod);
559
fprintf(fp, "[ACTION_END.device]\n%i\n", user_controls[ACTION_END].device);
560
fprintf(fp, "[ACTION_END.id]\n%i\n", user_controls[ACTION_END].id);
561
fprintf(fp, "[ACTION_END.mod]\n%i\n", user_controls[ACTION_END].mod);
562
fprintf(fp, "[ACTION_PAGEUP.device]\n%i\n", user_controls[ACTION_PAGEUP].device);
563
fprintf(fp, "[ACTION_PAGEUP.id]\n%i\n", user_controls[ACTION_PAGEUP].id);
564
fprintf(fp, "[ACTION_PAGEUP.mod]\n%i\n", user_controls[ACTION_PAGEUP].mod);
565
fprintf(fp, "[ACTION_PAGEDOWN.device]\n%i\n", user_controls[ACTION_PAGEDOWN].device);
566
fprintf(fp, "[ACTION_PAGEDOWN.id]\n%i\n", user_controls[ACTION_PAGEDOWN].id);
567
fprintf(fp, "[ACTION_PAGEDOWN.mod]\n%i\n", user_controls[ACTION_PAGEDOWN].mod);
568
fprintf(fp, "[ACTION_VOLUP.device]\n%i\n", user_controls[ACTION_VOLUP].device);
569
fprintf(fp, "[ACTION_VOLUP.id]\n%i\n", user_controls[ACTION_VOLUP].id);
570
fprintf(fp, "[ACTION_VOLUP.mod]\n%i\n", user_controls[ACTION_VOLUP].mod);
571
fprintf(fp, "[ACTION_VOLDOWN.device]\n%i\n", user_controls[ACTION_VOLDOWN].device);
572
fprintf(fp, "[ACTION_VOLDOWN.id]\n%i\n", user_controls[ACTION_VOLDOWN].id);
573
fprintf(fp, "[ACTION_VOLDOWN.mod]\n%i\n", user_controls[ACTION_VOLDOWN].mod);