Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/games/alex4/files/patch-main.c
16461 views
1
--- main.c.orig 2019-02-04 06:12:31 UTC
2
+++ main.c
3
@@ -38,6 +38,7 @@
4
#include "main.h"
5
#include "edit.h"
6
#include "shooter.h"
7
+#include "unix.h"
8
9
#include "../data/data.h"
10
11
@@ -66,7 +67,6 @@ PALETTE org_pal;
12
Tscroller hscroll;
13
Thisc *hisc_table;
14
Thisc *hisc_table_space;
15
-char working_directory[1024];
16
17
// the map
18
Tmap *map = NULL;
19
@@ -126,6 +126,7 @@ int menu_choice = 1;
20
int playing_original_game = 1;
21
int init_ok = 0;
22
23
+static FILE* log_fp = NULL;
24
25
26
// // // // // // // // // // // // // // // // // // // // //
27
@@ -154,20 +155,18 @@ char *get_init_string() {
28
// loggs the text to the text file
29
void log2file(char *format, ...) {
30
va_list ptr; /* get an arg pointer */
31
- FILE *fp;
32
33
- fp = fopen("log.txt", "at");
34
- if (fp) {
35
+ if (log_fp) {
36
/* initialize ptr to point to the first argument after the format string */
37
va_start(ptr, format);
38
39
/* Write to logfile. */
40
- vfprintf(fp, format, ptr); // Write passed text.
41
- fprintf(fp, "\n"); // New line..
42
+ vfprintf(log_fp, format, ptr); // Write passed text.
43
+ fprintf(log_fp, "\n"); // New line..
44
45
va_end(ptr);
46
47
- fclose(fp);
48
+ fflush(log_fp);
49
}
50
51
}
52
@@ -618,6 +617,10 @@ int init_game(const char *map_file) {
53
BITMAP *bmp;
54
int i;
55
int w, h;
56
+#ifdef __unix__
57
+ char filename[512];
58
+ char *homedir = get_homedir();
59
+#endif
60
61
log2file("\nInit routines:");
62
63
@@ -625,7 +628,13 @@ int init_game(const char *map_file) {
64
log2file(" initializing allegro");
65
text_mode(-1);
66
garble_string(init_string, 53);
67
+#ifdef __unix__
68
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.ini",
69
+ homedir? homedir:".");
70
+ override_config_file(filename);
71
+#else
72
set_config_file("alex4.ini");
73
+#endif
74
set_window_close_button(FALSE);
75
76
// install timers
77
@@ -695,6 +704,7 @@ int init_game(const char *map_file) {
78
textout_centre(swap_screen, font, "loading...", 320, 200, 1);
79
blit_to_screen(swap_screen);
80
81
+#ifndef __unix__
82
// set switch modes and callbacks
83
if (set_display_switch_mode(SWITCH_PAUSE) < 0)
84
log2file(" * display switch mode failed");
85
@@ -702,6 +712,7 @@ int init_game(const char *map_file) {
86
log2file(" * display switch in failed");
87
if (set_display_switch_callback(SWITCH_OUT, display_switch_out) < 0)
88
log2file(" * display switch out failed");
89
+#endif
90
91
92
// set win title (no! really???)
93
@@ -718,7 +729,7 @@ int init_game(const char *map_file) {
94
// load data
95
log2file(" loading data");
96
packfile_password(init_string);
97
- data = load_datafile("data/data.dat");
98
+ data = load_datafile(DATADIR "data.dat");
99
packfile_password(NULL);
100
if (data == NULL) {
101
log2file(" *** failed");
102
@@ -728,7 +739,13 @@ int init_game(const char *map_file) {
103
104
// load options
105
log2file(" loading options");
106
+#ifdef __unix__
107
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
108
+ homedir? homedir:".");
109
+ pf = pack_fopen(filename, "rp");
110
+#else
111
pf = pack_fopen("alex4.sav", "rp");
112
+#endif
113
if (pf) {
114
load_options(&options, pf);
115
pack_fclose(pf);
116
@@ -740,7 +757,13 @@ int init_game(const char *map_file) {
117
118
// loading highscores
119
log2file(" loading hiscores");
120
+#ifdef __unix__
121
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
122
+ homedir? homedir:".");
123
+ pf = pack_fopen(filename, "rp");
124
+#else
125
pf = pack_fopen("alex4.hi", "rp");
126
+#endif
127
if (pf) {
128
load_hisc_table(hisc_table, pf);
129
load_hisc_table(hisc_table_space, pf);
130
@@ -776,7 +799,7 @@ int init_game(const char *map_file) {
131
log2file(" loading original maps");
132
packfile_password(init_string);
133
num_levels = -1; // skip end object when counting
134
- maps = load_datafile_callback("data/maps.dat", count_maps_callback);
135
+ maps = load_datafile_callback(DATADIR "maps.dat", count_maps_callback);
136
packfile_password(NULL);
137
if (maps == NULL) {
138
log2file(" *** failed");
139
@@ -835,11 +858,12 @@ int init_game(const char *map_file) {
140
// install sound
141
log2file(" installing sound");
142
set_volume_per_voice(0);
143
- switch(get_config_int("sound", "sound_device", 0)) {
144
+ switch(get_config_int("sound", "sound_device", 1)) {
145
case 1:
146
i = DIGI_AUTODETECT;
147
log2file(" DIGI_AUTODETECT selected (%d)", i);
148
break;
149
+#ifdef ALLEGRO_WINDOWS
150
case 2:
151
i = DIGI_DIRECTX(0);
152
log2file(" DIGI_DIRECTX(0) selected (%d)", i);
153
@@ -848,6 +872,20 @@ int init_game(const char *map_file) {
154
i = DIGI_DIRECTAMX(0);
155
log2file(" DIGI_DIRECTAMX(0) selected (%d)", i);
156
break;
157
+#elif defined ALLEGRO_UNIX
158
+#ifdef DIGI_OSS
159
+ case 2:
160
+ i = DIGI_OSS;
161
+ log2file(" DIGI_OSS selected (%d)", i);
162
+ break;
163
+#endif
164
+#ifdef DIGI_ALSA
165
+ case 3:
166
+ i = DIGI_ALSA;
167
+ log2file(" DIGI_ALSA selected (%d)", i);
168
+ break;
169
+#endif
170
+#endif
171
default:
172
i = -770405; // dummy number
173
got_sound = 0;
174
@@ -870,9 +908,9 @@ int init_game(const char *map_file) {
175
if (get_config_int("sound", "use_sound_datafile", 1)) {
176
log2file(" loading sound datafile");
177
packfile_password(init_string);
178
- sfx_data = load_datafile("data/sfx_44.dat");
179
+ sfx_data = load_datafile(DATADIR "sfx_44.dat");
180
if (sfx_data == NULL) {
181
- sfx_data = load_datafile("data/sfx_22.dat");
182
+ sfx_data = load_datafile(DATADIR "sfx_22.dat");
183
log2file(" sfx_44.dat not found");
184
s = 0;
185
}
186
@@ -971,6 +1009,10 @@ int init_game(const char *map_file) {
187
void uninit_game() {
188
int i;
189
PACKFILE *pf;
190
+#ifdef __unix__
191
+ char filename[512];
192
+ char *homedir = get_homedir();
193
+#endif
194
195
log2file("\nExit routines:");
196
197
@@ -989,14 +1031,26 @@ void uninit_game() {
198
// only save if everything was inited ok!
199
if (init_ok) {
200
log2file(" saving options");
201
+#ifdef __unix__
202
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
203
+ homedir? homedir:".");
204
+ pf = pack_fopen(filename, "wp");
205
+#else
206
pf = pack_fopen("alex4.sav", "wp");
207
+#endif
208
if (pf) {
209
save_options(&options, pf);
210
pack_fclose(pf);
211
}
212
213
log2file(" saving highscores");
214
+#ifdef __unix__
215
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
216
+ homedir? homedir:".");
217
+ pf = pack_fopen(filename, "wp");
218
+#else
219
pf = pack_fopen("alex4.hi", "wp");
220
+#endif
221
if (pf) {
222
save_hisc_table(hisc_table, pf);
223
save_hisc_table(hisc_table_space, pf);
224
@@ -1158,9 +1212,9 @@ void draw_custom_ending(BITMAP *bmp) {
225
226
blit(data[INTRO_BG].dat, bmp, 0, 0, 0, 0, 160, 120);
227
228
- r = 70 + fixtoi(20 * fcos(itofix(game_count >> 1)) + 20 * fsin(itofix((int)(game_count / 2.7))) );
229
+ r = 70 + fixtoi(20 * fixcos(itofix(game_count >> 1)) + 20 * fixsin(itofix((int)(game_count / 2.7))) );
230
for(i = 0; i < 256; i += 32)
231
- draw_sprite(bmp, head, 80 - head->w/2 + fixtoi(r * fcos(itofix(game_count + i))), 60 - head->h/2 + fixtoi(r * fsin(itofix(game_count + i))));
232
+ draw_sprite(bmp, head, 80 - head->w/2 + fixtoi(r * fixcos(itofix(game_count + i))), 60 - head->h/2 + fixtoi(r * fixsin(itofix(game_count + i))));
233
234
draw_sprite_h_flip(bmp, data[ALEX].dat, 60, 40);
235
draw_sprite(bmp, data[LOLA].dat, 84, 40);
236
@@ -1289,7 +1343,7 @@ void show_cutscene(int level) {
237
// poll music machine
238
if (got_sound) al_poll_duh(dp);
239
240
- if (mode == 1 && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl) ) || my_counter > 200) {
241
+ if (((mode == 1) && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl))) || (my_counter > 200)) {
242
mode = 2;
243
}
244
245
@@ -1343,7 +1397,7 @@ void show_scores(int space, Thisc *table) {
246
if (space) {
247
// get space bg
248
packfile_password(init_string);
249
- df = load_datafile_object("data/a45.dat", "BG1");
250
+ df = load_datafile_object(DATADIR "a45.dat", "BG1");
251
packfile_password(NULL);
252
if (df != NULL) {
253
bg = df->dat;
254
@@ -2149,7 +2203,7 @@ void check_alex_with_enemies() {
255
256
// calculates camera pos for map m considering player p
257
void calculate_camera_pos(Tplayer *p, Tmap *m) {
258
- static camera_type = 1;
259
+ static int camera_type = 1;
260
261
if (p->actor->status == AC_BALL) {
262
camera_type = 2;
263
@@ -2485,7 +2539,7 @@ void draw_title(BITMAP *bmp, int tick) {
264
textout(bmp, data[THE_FONT].dat, "QUIT", x+1, y+1, 1);
265
textout(bmp, data[THE_FONT].dat, "QUIT", x, y, 4);
266
267
- draw_sprite(bmp, data[POINTER].dat, x - 25 + fixtoi(3 * fcos(itofix(tick << 2))), 44 + menu_choice * step);
268
+ draw_sprite(bmp, data[POINTER].dat, x - 25 + fixtoi(3 * fixcos(itofix(tick << 2))), 44 + menu_choice * step);
269
}
270
271
272
@@ -2841,6 +2895,10 @@ int do_main_menu() {
273
}
274
else {
275
PACKFILE *pf;
276
+#ifdef __unix__
277
+ char filename[512];
278
+ char *homedir = get_homedir();
279
+#endif
280
log2file(" level complete");
281
if (got_sound) stop_music();
282
if (level < MAX_LEVELS && playing_original_game) {
283
@@ -2875,7 +2933,14 @@ int do_main_menu() {
284
285
// save options
286
log2file(" saving options");
287
+#ifdef __unix__
288
+ snprintf(filename, sizeof(filename),
289
+ "%s/.alex4/alex4.sav",
290
+ homedir? homedir:".");
291
+ pf = pack_fopen(filename, "wp");
292
+#else
293
pf = pack_fopen("alex4.sav", "wp");
294
+#endif
295
if (pf) {
296
save_options(&options, pf);
297
pack_fclose(pf);
298
@@ -2969,24 +3034,36 @@ int do_main_menu() {
299
300
// main
301
int main(int argc, char **argv) {
302
- FILE *fp;
303
int i;
304
char full_path[1024];
305
+#ifndef __unix__
306
+ char working_directory[1024];
307
+#else
308
+ char *homedir = get_homedir();
309
+#endif
310
311
// init allegro
312
allegro_init();
313
314
+#ifdef __unix__
315
+ // start logfile
316
+ snprintf(full_path, sizeof(full_path), "%s/.alex4",
317
+ homedir? homedir:".");
318
+ check_and_create_dir(full_path);
319
+ snprintf(full_path, sizeof(full_path), "%s/.alex4/log.txt",
320
+ homedir? homedir:".");
321
+ log_fp = fopen(full_path, "wt");
322
+#else
323
// get working directory
324
get_executable_name(full_path, 1024);
325
replace_filename(working_directory, full_path, "", 1024);
326
chdir(working_directory);
327
328
-
329
// start logfile
330
- fp = fopen("log.txt", "wt");
331
- if (fp) {
332
- fprintf(fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
333
- fclose(fp);
334
+ log_fp = fopen("log.txt", "wt");
335
+#endif
336
+ if (log_fp) {
337
+ fprintf(log_fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
338
}
339
340
// log program arguments
341
@@ -2994,7 +3071,9 @@ int main(int argc, char **argv) {
342
for(i = 0; i < argc; i ++) {
343
log2file(" %s", argv[i]);
344
}
345
+#ifndef __unix__
346
log2file("Working directory is:\n %s", working_directory);
347
+#endif
348
349
// test wether to play real game
350
// or custom levels
351
@@ -3022,6 +3101,8 @@ int main(int argc, char **argv) {
352
uninit_game();
353
allegro_exit();
354
log2file("\nDone...\n");
355
+ if (log_fp)
356
+ fclose(log_fp);
357
358
return 0;
359
} END_OF_MAIN();
360
361