0 | |
Hans de Goede's patch for Fedora.
|
1 | |
|
2 | |
Index: alex4-1.1/src/main.c
|
3 | |
===================================================================
|
4 | |
--- alex4-1.1.orig/src/main.c 2008-01-26 21:33:48.000000000 +0100
|
5 | |
+++ alex4-1.1/src/main.c 2008-01-26 21:34:05.000000000 +0100
|
6 | |
@@ -38,6 +38,7 @@
|
7 | |
#include "main.h"
|
8 | |
#include "edit.h"
|
9 | |
#include "shooter.h"
|
10 | |
+#include "unix.h"
|
11 | |
|
12 | |
#include "../data/data.h"
|
13 | |
|
14 | |
@@ -66,7 +67,6 @@
|
15 | |
Tscroller hscroll;
|
16 | |
Thisc *hisc_table;
|
17 | |
Thisc *hisc_table_space;
|
18 | |
-char working_directory[1024];
|
19 | |
|
20 | |
// the map
|
21 | |
Tmap *map = NULL;
|
22 | |
@@ -126,6 +126,7 @@
|
23 | |
int playing_original_game = 1;
|
24 | |
int init_ok = 0;
|
25 | |
|
26 | |
+static FILE* log_fp = NULL;
|
27 | |
|
28 | |
|
29 | |
// // // // // // // // // // // // // // // // // // // // //
|
30 | |
@@ -154,20 +155,18 @@
|
31 | |
// loggs the text to the text file
|
32 | |
void log2file(char *format, ...) {
|
33 | |
va_list ptr; /* get an arg pointer */
|
34 | |
- FILE *fp;
|
35 | |
|
36 | |
- fp = fopen("log.txt", "at");
|
37 | |
- if (fp) {
|
38 | |
+ if (log_fp) {
|
39 | |
/* initialize ptr to point to the first argument after the format string */
|
40 | |
va_start(ptr, format);
|
41 | |
|
42 | |
/* Write to logfile. */
|
43 | |
- vfprintf(fp, format, ptr); // Write passed text.
|
44 | |
- fprintf(fp, "\n"); // New line..
|
45 | |
+ vfprintf(log_fp, format, ptr); // Write passed text.
|
46 | |
+ fprintf(log_fp, "\n"); // New line..
|
47 | |
|
48 | |
va_end(ptr);
|
49 | |
|
50 | |
- fclose(fp);
|
51 | |
+ fflush(log_fp);
|
52 | |
}
|
53 | |
|
54 | |
}
|
55 | |
@@ -618,6 +617,10 @@
|
56 | |
BITMAP *bmp;
|
57 | |
int i;
|
58 | |
int w, h;
|
59 | |
+#ifdef __unix__
|
60 | |
+ char filename[512];
|
61 | |
+ char *homedir = get_homedir();
|
62 | |
+#endif
|
63 | |
|
64 | |
log2file("\nInit routines:");
|
65 | |
|
66 | |
@@ -625,7 +628,13 @@
|
67 | |
log2file(" initializing allegro");
|
68 | |
text_mode(-1);
|
69 | |
garble_string(init_string, 53);
|
70 | |
+#ifdef __unix__
|
71 | |
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.ini",
|
72 | |
+ homedir? homedir:".");
|
73 | |
+ override_config_file(filename);
|
74 | |
+#else
|
75 | |
set_config_file("alex4.ini");
|
76 | |
+#endif
|
77 | |
set_window_close_button(FALSE);
|
78 | |
|
79 | |
// install timers
|
80 | |
@@ -695,6 +704,7 @@
|
81 | |
textout_centre(swap_screen, font, "loading...", 320, 200, 1);
|
82 | |
blit_to_screen(swap_screen);
|
83 | |
|
84 | |
+#ifndef __unix__
|
85 | |
// set switch modes and callbacks
|
86 | |
if (set_display_switch_mode(SWITCH_PAUSE) < 0)
|
87 | |
log2file(" * display switch mode failed");
|
88 | |
@@ -702,6 +712,7 @@
|
89 | |
log2file(" * display switch in failed");
|
90 | |
if (set_display_switch_callback(SWITCH_OUT, display_switch_out) < 0)
|
91 | |
log2file(" * display switch out failed");
|
92 | |
+#endif
|
93 | |
|
94 | |
|
95 | |
// set win title (no! really???)
|
96 | |
@@ -718,7 +729,7 @@
|
97 | |
// load data
|
98 | |
log2file(" loading data");
|
99 | |
packfile_password(init_string);
|
100 | |
- data = load_datafile("data/data.dat");
|
101 | |
+ data = load_datafile(DATADIR "data.dat");
|
102 | |
packfile_password(NULL);
|
103 | |
if (data == NULL) {
|
104 | |
log2file(" *** failed");
|
105 | |
@@ -728,7 +739,13 @@
|
106 | |
|
107 | |
// load options
|
108 | |
log2file(" loading options");
|
109 | |
+#ifdef __unix__
|
110 | |
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
|
111 | |
+ homedir? homedir:".");
|
112 | |
+ pf = pack_fopen(filename, "rp");
|
113 | |
+#else
|
114 | |
pf = pack_fopen("alex4.sav", "rp");
|
115 | |
+#endif
|
116 | |
if (pf) {
|
117 | |
load_options(&options, pf);
|
118 | |
pack_fclose(pf);
|
119 | |
@@ -740,7 +757,13 @@
|
120 | |
|
121 | |
// loading highscores
|
122 | |
log2file(" loading hiscores");
|
123 | |
+#ifdef __unix__
|
124 | |
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
|
125 | |
+ homedir? homedir:".");
|
126 | |
+ pf = pack_fopen(filename, "rp");
|
127 | |
+#else
|
128 | |
pf = pack_fopen("alex4.hi", "rp");
|
129 | |
+#endif
|
130 | |
if (pf) {
|
131 | |
load_hisc_table(hisc_table, pf);
|
132 | |
load_hisc_table(hisc_table_space, pf);
|
133 | |
@@ -776,7 +799,7 @@
|
134 | |
log2file(" loading original maps");
|
135 | |
packfile_password(init_string);
|
136 | |
num_levels = -1; // skip end object when counting
|
137 | |
- maps = load_datafile_callback("data/maps.dat", count_maps_callback);
|
138 | |
+ maps = load_datafile_callback(DATADIR "maps.dat", count_maps_callback);
|
139 | |
packfile_password(NULL);
|
140 | |
if (maps == NULL) {
|
141 | |
log2file(" *** failed");
|
142 | |
@@ -835,11 +858,12 @@
|
143 | |
// install sound
|
144 | |
log2file(" installing sound");
|
145 | |
set_volume_per_voice(0);
|
146 | |
- switch(get_config_int("sound", "sound_device", 0)) {
|
147 | |
+ switch(get_config_int("sound", "sound_device", 1)) {
|
148 | |
case 1:
|
149 | |
i = DIGI_AUTODETECT;
|
150 | |
log2file(" DIGI_AUTODETECT selected (%d)", i);
|
151 | |
break;
|
152 | |
+#ifdef ALLEGRO_WINDOWS
|
153 | |
case 2:
|
154 | |
i = DIGI_DIRECTX(0);
|
155 | |
log2file(" DIGI_DIRECTX(0) selected (%d)", i);
|
156 | |
@@ -848,6 +872,20 @@
|
157 | |
i = DIGI_DIRECTAMX(0);
|
158 | |
log2file(" DIGI_DIRECTAMX(0) selected (%d)", i);
|
159 | |
break;
|
160 | |
+#elif defined ALLEGRO_UNIX
|
161 | |
+#ifdef DIGI_OSS
|
162 | |
+ case 2:
|
163 | |
+ i = DIGI_OSS;
|
164 | |
+ log2file(" DIGI_OSS selected (%d)", i);
|
165 | |
+ break;
|
166 | |
+#endif
|
167 | |
+#ifdef DIGI_ALSA
|
168 | |
+ case 3:
|
169 | |
+ i = DIGI_ALSA;
|
170 | |
+ log2file(" DIGI_ALSA selected (%d)", i);
|
171 | |
+ break;
|
172 | |
+#endif
|
173 | |
+#endif
|
174 | |
default:
|
175 | |
i = -770405; // dummy number
|
176 | |
got_sound = 0;
|
177 | |
@@ -870,9 +908,9 @@
|
178 | |
if (get_config_int("sound", "use_sound_datafile", 1)) {
|
179 | |
log2file(" loading sound datafile");
|
180 | |
packfile_password(init_string);
|
181 | |
- sfx_data = load_datafile("data/sfx_44.dat");
|
182 | |
+ sfx_data = load_datafile(DATADIR "sfx_44.dat");
|
183 | |
if (sfx_data == NULL) {
|
184 | |
- sfx_data = load_datafile("data/sfx_22.dat");
|
185 | |
+ sfx_data = load_datafile(DATADIR "sfx_22.dat");
|
186 | |
log2file(" sfx_44.dat not found");
|
187 | |
s = 0;
|
188 | |
}
|
189 | |
@@ -971,6 +1009,10 @@
|
190 | |
void uninit_game() {
|
191 | |
int i;
|
192 | |
PACKFILE *pf;
|
193 | |
+#ifdef __unix__
|
194 | |
+ char filename[512];
|
195 | |
+ char *homedir = get_homedir();
|
196 | |
+#endif
|
197 | |
|
198 | |
log2file("\nExit routines:");
|
199 | |
|
200 | |
@@ -989,14 +1031,26 @@
|
201 | |
// only save if everything was inited ok!
|
202 | |
if (init_ok) {
|
203 | |
log2file(" saving options");
|
204 | |
+#ifdef __unix__
|
205 | |
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
|
206 | |
+ homedir? homedir:".");
|
207 | |
+ pf = pack_fopen(filename, "wp");
|
208 | |
+#else
|
209 | |
pf = pack_fopen("alex4.sav", "wp");
|
210 | |
+#endif
|
211 | |
if (pf) {
|
212 | |
save_options(&options, pf);
|
213 | |
pack_fclose(pf);
|
214 | |
}
|
215 | |
|
216 | |
log2file(" saving highscores");
|
217 | |
+#ifdef __unix__
|
218 | |
+ snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
|
219 | |
+ homedir? homedir:".");
|
220 | |
+ pf = pack_fopen(filename, "wp");
|
221 | |
+#else
|
222 | |
pf = pack_fopen("alex4.hi", "wp");
|
223 | |
+#endif
|
224 | |
if (pf) {
|
225 | |
save_hisc_table(hisc_table, pf);
|
226 | |
save_hisc_table(hisc_table_space, pf);
|
227 | |
@@ -1289,7 +1343,7 @@
|
228 | |
// poll music machine
|
229 | |
if (got_sound) al_poll_duh(dp);
|
230 | |
|
231 | |
- if (mode == 1 && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl) ) || my_counter > 200) {
|
232 | |
+ if (((mode == 1) && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl))) || (my_counter > 200)) {
|
233 | |
mode = 2;
|
234 | |
}
|
235 | |
|
236 | |
@@ -1343,7 +1397,7 @@
|
237 | |
if (space) {
|
238 | |
// get space bg
|
239 | |
packfile_password(init_string);
|
240 | |
- df = load_datafile_object("data/a45.dat", "BG1");
|
241 | |
+ df = load_datafile_object(DATADIR "a45.dat", "BG1");
|
242 | |
packfile_password(NULL);
|
243 | |
if (df != NULL) {
|
244 | |
bg = df->dat;
|
245 | |
@@ -2149,7 +2203,7 @@
|
246 | |
|
247 | |
// calculates camera pos for map m considering player p
|
248 | |
void calculate_camera_pos(Tplayer *p, Tmap *m) {
|
249 | |
- static camera_type = 1;
|
250 | |
+ static int camera_type = 1;
|
251 | |
|
252 | |
if (p->actor->status == AC_BALL) {
|
253 | |
camera_type = 2;
|
254 | |
@@ -2841,6 +2895,10 @@
|
255 | |
}
|
256 | |
else {
|
257 | |
PACKFILE *pf;
|
258 | |
+#ifdef __unix__
|
259 | |
+ char filename[512];
|
260 | |
+ char *homedir = get_homedir();
|
261 | |
+#endif
|
262 | |
log2file(" level complete");
|
263 | |
if (got_sound) stop_music();
|
264 | |
if (level < MAX_LEVELS && playing_original_game) {
|
265 | |
@@ -2875,7 +2933,14 @@
|
266 | |
|
267 | |
// save options
|
268 | |
log2file(" saving options");
|
269 | |
+#ifdef __unix__
|
270 | |
+ snprintf(filename, sizeof(filename),
|
271 | |
+ "%s/.alex4/alex4.sav",
|
272 | |
+ homedir? homedir:".");
|
273 | |
+ pf = pack_fopen(filename, "wp");
|
274 | |
+#else
|
275 | |
pf = pack_fopen("alex4.sav", "wp");
|
276 | |
+#endif
|
277 | |
if (pf) {
|
278 | |
save_options(&options, pf);
|
279 | |
pack_fclose(pf);
|
280 | |
@@ -2969,24 +3034,36 @@
|
281 | |
|
282 | |
// main
|
283 | |
int main(int argc, char **argv) {
|
284 | |
- FILE *fp;
|
285 | |
int i;
|
286 | |
char full_path[1024];
|
287 | |
+#ifndef __unix__
|
288 | |
+ char working_directory[1024];
|
289 | |
+#else
|
290 | |
+ char *homedir = get_homedir();
|
291 | |
+#endif
|
292 | |
|
293 | |
// init allegro
|
294 | |
allegro_init();
|
295 | |
|
296 | |
+#ifdef __unix__
|
297 | |
+ // start logfile
|
298 | |
+ snprintf(full_path, sizeof(full_path), "%s/.alex4",
|
299 | |
+ homedir? homedir:".");
|
300 | |
+ check_and_create_dir(full_path);
|
301 | |
+ snprintf(full_path, sizeof(full_path), "%s/.alex4/log.txt",
|
302 | |
+ homedir? homedir:".");
|
303 | |
+ log_fp = fopen(full_path, "wt");
|
304 | |
+#else
|
305 | |
// get working directory
|
306 | |
get_executable_name(full_path, 1024);
|
307 | |
replace_filename(working_directory, full_path, "", 1024);
|
308 | |
chdir(working_directory);
|
309 | |
|
310 | |
-
|
311 | |
// start logfile
|
312 | |
- fp = fopen("log.txt", "wt");
|
313 | |
- if (fp) {
|
314 | |
- fprintf(fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
|
315 | |
- fclose(fp);
|
316 | |
+ log_fp = fopen("log.txt", "wt");
|
317 | |
+#endif
|
318 | |
+ if (log_fp) {
|
319 | |
+ fprintf(log_fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
|
320 | |
}
|
321 | |
|
322 | |
// log program arguments
|
323 | |
@@ -2994,7 +3071,9 @@
|
324 | |
for(i = 0; i < argc; i ++) {
|
325 | |
log2file(" %s", argv[i]);
|
326 | |
}
|
327 | |
+#ifndef __unix__
|
328 | |
log2file("Working directory is:\n %s", working_directory);
|
329 | |
+#endif
|
330 | |
|
331 | |
// test wether to play real game
|
332 | |
// or custom levels
|
333 | |
@@ -3022,6 +3101,8 @@
|
334 | |
uninit_game();
|
335 | |
allegro_exit();
|
336 | |
log2file("\nDone...\n");
|
337 | |
+ if (log_fp)
|
338 | |
+ fclose(log_fp);
|
339 | |
|
340 | |
return 0;
|
341 | |
} END_OF_MAIN();
|
342 | |
Index: alex4-1.1/src/player.h
|
343 | |
===================================================================
|
344 | |
--- alex4-1.1.orig/src/player.h 2008-01-26 21:33:48.000000000 +0100
|
345 | |
+++ alex4-1.1/src/player.h 2008-01-26 21:34:05.000000000 +0100
|
346 | |
@@ -60,4 +60,4 @@
|
347 | |
void wound_player(Tplayer *p);
|
348 | |
void kill_player(Tplayer *p);
|
349 | |
|
350 | |
-#endif
|
351 | |
\ No newline at end of file
|
352 | |
+#endif
|
353 | |
Index: alex4-1.1/src/map.h
|
354 | |
===================================================================
|
355 | |
--- alex4-1.1.orig/src/map.h 2008-01-26 21:33:48.000000000 +0100
|
356 | |
+++ alex4-1.1/src/map.h 2008-01-26 21:34:05.000000000 +0100
|
357 | |
@@ -111,4 +111,4 @@
|
358 | |
|
359 | |
|
360 | |
|
361 | |
-#endif
|
362 | |
\ No newline at end of file
|
363 | |
+#endif
|
364 | |
Index: alex4-1.1/src/unix.c
|
365 | |
===================================================================
|
366 | |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
367 | |
+++ alex4-1.1/src/unix.c 2008-01-26 21:36:41.000000000 +0100
|
368 | |
@@ -0,0 +1,82 @@
|
369 | |
+#ifdef __unix__
|
370 | |
+#include <stdio.h>
|
371 | |
+#include <stdlib.h>
|
372 | |
+#include <unistd.h>
|
373 | |
+#include <pwd.h>
|
374 | |
+#include <errno.h>
|
375 | |
+#include <sys/types.h>
|
376 | |
+#include <sys/stat.h>
|
377 | |
+#if defined(__DECC) && defined(VMS)
|
378 | |
+#include <unixlib.h>
|
379 | |
+static char *vms_to_unix_buffer = NULL;
|
380 | |
+static int convert_vms_to_unix(char *vms_dir_name)
|
381 | |
+{
|
382 | |
+ vms_to_unix_buffer = vms_dir_name;
|
383 | |
+}
|
384 | |
+#endif
|
385 | |
+
|
386 | |
+char *get_homedir(void)
|
387 | |
+{
|
388 | |
+ struct passwd *pw;
|
389 | |
+
|
390 | |
+ if (!(pw = getpwuid(getuid())))
|
391 | |
+ {
|
392 | |
+ fprintf(stderr, "Who are you? Not found in passwd database!!\n");
|
393 | |
+ return getenv("HOME");
|
394 | |
+ }
|
395 | |
+
|
396 | |
+#if defined(__DECC) && defined(VMS)
|
397 | |
+ /* Convert The OpenVMS Formatted "$HOME" Directory Path Into Unix
|
398 | |
+ Format. */
|
399 | |
+ decc$from_vms(pw->pw_dir, convert_vms_to_unix, 1);
|
400 | |
+ return vms_to_unix_buffer;
|
401 | |
+#else
|
402 | |
+ return pw->pw_dir;
|
403 | |
+#endif
|
404 | |
+}
|
405 | |
+//-----------------------------------------------------------------------------
|
406 | |
+int check_and_create_dir(const char *name)
|
407 | |
+{
|
408 | |
+ struct stat stat_buffer;
|
409 | |
+
|
410 | |
+ if (stat(name, &stat_buffer))
|
411 | |
+ {
|
412 | |
+ /* error check if it doesn't exist or something else is wrong */
|
413 | |
+ if (errno == ENOENT)
|
414 | |
+ {
|
415 | |
+ /* doesn't exist letts create it ;) */
|
416 | |
+#ifdef BSD43
|
417 | |
+ if (mkdir(name, 0775))
|
418 | |
+#else
|
419 | |
+ if (mkdir(name, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH))
|
420 | |
+#endif
|
421 | |
+ {
|
422 | |
+ fprintf(stderr, "Error creating dir %s", name);
|
423 | |
+ perror(" ");
|
424 | |
+ return -1;
|
425 | |
+ }
|
426 | |
+ }
|
427 | |
+ else
|
428 | |
+ {
|
429 | |
+ /* something else went wrong yell about it */
|
430 | |
+ fprintf(stderr, "Error opening %s", name);
|
431 | |
+ perror(" ");
|
432 | |
+ return -1;
|
433 | |
+ }
|
434 | |
+ }
|
435 | |
+ else
|
436 | |
+ {
|
437 | |
+ /* file exists check it's a dir otherwise yell about it */
|
438 | |
+#ifdef BSD43
|
439 | |
+ if (!(S_IFDIR & stat_buffer.st_mode))
|
440 | |
+#else
|
441 | |
+ if (!S_ISDIR(stat_buffer.st_mode))
|
442 | |
+#endif
|
443 | |
+ {
|
444 | |
+ fprintf(stderr,"Error %s exists but isn't a dir\n", name);
|
445 | |
+ return -1;
|
446 | |
+ }
|
447 | |
+ }
|
448 | |
+ return 0;
|
449 | |
+}
|
450 | |
+#endif
|
451 | |
Index: alex4-1.1/src/Makefile
|
452 | |
===================================================================
|
453 | |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
454 | |
+++ alex4-1.1/src/Makefile 2008-01-26 21:36:26.000000000 +0100
|
455 | |
@@ -0,0 +1,24 @@
|
456 | |
+PREFIX = /usr/local
|
457 | |
+DATADIR = $(PREFIX)/share/$(TARGET)
|
458 | |
+CFLAGS = -g -Wall -Wno-deprecated-declarations -O2
|
459 | |
+LDFLAGS = `allegro-config --libs` -laldmb -ldumb
|
460 | |
+DEFINES = -DDATADIR=\"$(DATADIR)/\"
|
461 | |
+OBJS = actor.o edit.o map.o player.o shooter.o unix.o \
|
462 | |
+ bullet.o hisc.o options.o script.o timer.o \
|
463 | |
+ control.o main.o particle.o scroller.o token.o
|
464 | |
+TARGET = alex4
|
465 | |
+
|
466 | |
+$(TARGET): $(OBJS)
|
467 | |
+ $(CC) $(LDFLAGS) -o $@ $^
|
468 | |
+
|
469 | |
+%.o: %.c
|
470 | |
+ $(CC) $(CFLAGS) $(DEFINES) -o $@ -c $<
|
471 | |
+
|
472 | |
+install: $(TARGET)
|
473 | |
+ mkdir -p $(PREFIX)/bin
|
474 | |
+ mkdir -p $(DATADIR)
|
475 | |
+ install -p -m 755 $(TARGET) $(PREFIX)/bin
|
476 | |
+ install -p -m 644 ../data/*.dat $(DATADIR)
|
477 | |
+
|
478 | |
+clean:
|
479 | |
+ rm -f $(OBJS) $(TARGET) *~
|
480 | |
Index: alex4-1.1/src/token.h
|
481 | |
===================================================================
|
482 | |
--- alex4-1.1.orig/src/token.h 2008-01-26 21:33:48.000000000 +0100
|
483 | |
+++ alex4-1.1/src/token.h 2008-01-26 21:34:05.000000000 +0100
|
484 | |
@@ -41,4 +41,4 @@
|
485 | |
Ttoken *tokenize(char *str);
|
486 | |
|
487 | |
|
488 | |
-#endif
|
489 | |
\ No newline at end of file
|
490 | |
+#endif
|
491 | |
Index: alex4-1.1/src/shooter.c
|
492 | |
===================================================================
|
493 | |
--- alex4-1.1.orig/src/shooter.c 2008-01-26 21:33:49.000000000 +0100
|
494 | |
+++ alex4-1.1/src/shooter.c 2008-01-26 21:34:05.000000000 +0100
|
495 | |
@@ -1372,7 +1372,7 @@
|
496 | |
// load data
|
497 | |
log2file(" loading shooter data");
|
498 | |
packfile_password(get_init_string());
|
499 | |
- s_data = load_datafile("data/a45.dat");
|
500 | |
+ s_data = load_datafile(DATADIR "a45.dat");
|
501 | |
if (!s_data) {
|
502 | |
log2file(" *** failed");
|
503 | |
return -1;
|
504 | |
Index: alex4-1.1/src/particle.h
|
505 | |
===================================================================
|
506 | |
--- alex4-1.1.orig/src/particle.h 2008-01-26 21:33:49.000000000 +0100
|
507 | |
+++ alex4-1.1/src/particle.h 2008-01-26 21:34:05.000000000 +0100
|
508 | |
@@ -54,4 +54,4 @@
|
509 | |
void update_particle_with_map(Tparticle *p, Tmap *m);
|
510 | |
void create_burst(Tparticle *ps, int x, int y, int spread, int num, int life, int bmp);
|
511 | |
|
512 | |
-#endif
|
513 | |
\ No newline at end of file
|
514 | |
+#endif
|
515 | |
Index: alex4-1.1/src/unix.h
|
516 | |
===================================================================
|
517 | |
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
|
518 | |
+++ alex4-1.1/src/unix.h 2008-01-26 21:34:05.000000000 +0100
|
519 | |
@@ -0,0 +1,6 @@
|
520 | |
+#ifdef __unix__
|
521 | |
+
|
522 | |
+char *get_homedir();
|
523 | |
+int check_and_create_dir(const char *name);
|
524 | |
+
|
525 | |
+#endif
|
526 | |
Index: alex4-1.1/src/scroller.h
|
527 | |
===================================================================
|
528 | |
--- alex4-1.1.orig/src/scroller.h 2008-01-26 21:33:49.000000000 +0100
|
529 | |
+++ alex4-1.1/src/scroller.h 2008-01-26 21:34:05.000000000 +0100
|
530 | |
@@ -51,4 +51,4 @@
|
531 | |
|
532 | |
|
533 | |
|
534 | |
-#endif
|
535 | |
\ No newline at end of file
|
536 | |
+#endif
|
537 | |
Index: alex4-1.1/src/map.c
|
538 | |
===================================================================
|
539 | |
--- alex4-1.1.orig/src/map.c 2008-01-26 21:33:49.000000000 +0100
|
540 | |
+++ alex4-1.1/src/map.c 2008-01-26 21:34:05.000000000 +0100
|
541 | |
@@ -24,6 +24,7 @@
|
542 | |
#include <stdlib.h>
|
543 | |
#include <stdio.h>
|
544 | |
#include <string.h>
|
545 | |
+#include <endian.h>
|
546 | |
#include "allegro.h"
|
547 | |
#include "map.h"
|
548 | |
#include "timer.h"
|
549 | |
@@ -64,7 +65,41 @@
|
550 | |
|
551 | |
return m;
|
552 | |
}
|
553 | |
-
|
554 | |
+
|
555 | |
+static void mem_to_int(int *dest, unsigned char *mem)
|
556 | |
+{
|
557 | |
+#if __BYTE_ORDER == __LITTLE_ENDIAN
|
558 | |
+ memcpy(dest, mem, 4);
|
559 | |
+#else
|
560 | |
+ *dest = mem[0] | (((int)mem[1]) << 8) | (((int)mem[2]) << 16) |
|
561 | |
+ (((int)mem[3]) << 24);
|
562 | |
+#endif
|
563 | |
+}
|
564 | |
+
|
565 | |
+static void fread_int(int *dest, FILE *fp)
|
566 | |
+{
|
567 | |
+#if __BYTE_ORDER == __LITTLE_ENDIAN
|
568 | |
+ fread(dest, 4, 1, fp);
|
569 | |
+#else
|
570 | |
+ unsigned char buf[4];
|
571 | |
+ fread(buf, 1, 4, fp);
|
572 | |
+ mem_to_int(dest, buf);
|
573 | |
+#endif
|
574 | |
+}
|
575 | |
+
|
576 | |
+static void fwrite_int(const int *src, FILE *fp)
|
577 | |
+{
|
578 | |
+#if __BYTE_ORDER == __LITTLE_ENDIAN
|
579 | |
+ fwrite(src, 4, 1, fp);
|
580 | |
+#else
|
581 | |
+ unsigned char buf[4];
|
582 | |
+ buf[0] = *src;
|
583 | |
+ buf[1] = *src >> 8;
|
584 | |
+ buf[2] = *src >> 16;
|
585 | |
+ buf[3] = *src >> 24;
|
586 | |
+ fwrite(buf, 1, 4, fp);
|
587 | |
+#endif
|
588 | |
+}
|
589 | |
|
590 | |
// loads one splendind map from disk
|
591 | |
Tmap *load_map(char *fname) {
|
592 | |
@@ -93,7 +128,19 @@
|
593 | |
}
|
594 | |
|
595 | |
// read datastruct
|
596 | |
- fread(m, sizeof(Tmap), 1, fp);
|
597 | |
+ // a mapfile contain a raw dump of the Tmap struct made on an i386
|
598 | |
+ // the code below reads these struct dumps in an arch neutral manner
|
599 | |
+ // Note this dumps contains pointers, these are not used because these
|
600 | |
+ // ofcourse point to some no longer valid address.
|
601 | |
+ fread(m, 64, 1, fp); // first 64 bytes data
|
602 | |
+ fread_int(&(m->width), fp);
|
603 | |
+ fread_int(&(m->height), fp);
|
604 | |
+ fread(header, 4, 1, fp); // skip the first pointer
|
605 | |
+ fread_int(&(m->offset_x), fp);
|
606 | |
+ fread_int(&(m->offset_y), fp);
|
607 | |
+ fread(header, 4, 1, fp); // skip the second pointer
|
608 | |
+ fread_int(&(m->start_x), fp);
|
609 | |
+ fread_int(&(m->start_y), fp);
|
610 | |
|
611 | |
// read map data
|
612 | |
m->dat = malloc(m->width * m->height * sizeof(Tmappos));
|
613 | |
@@ -116,8 +163,8 @@
|
614 | |
// loads one splendind map from memory
|
615 | |
Tmap *load_map_from_memory(void *mem) {
|
616 | |
Tmap *m;
|
617 | |
- char header[6];
|
618 | |
- char *c = (char *)mem;
|
619 | |
+ unsigned char header[6];
|
620 | |
+ unsigned char *c = (unsigned char *)mem;
|
621 | |
|
622 | |
|
623 | |
// does the header match?
|
624 | |
@@ -137,9 +184,19 @@
|
625 | |
}
|
626 | |
|
627 | |
// read datastruct
|
628 | |
- // fread(m, sizeof(Tmap), 1, fp);
|
629 | |
- memcpy(m, c, sizeof(Tmap));
|
630 | |
- c += sizeof(Tmap);
|
631 | |
+ // a mapfile contain a raw dump of the Tmap struct made on an i386
|
632 | |
+ // the code below reads these struct dumps in an arch neutral manner
|
633 | |
+ // Note this dumps contains pointers, these are not used because these
|
634 | |
+ // ofcourse point to some no longer valid address.
|
635 | |
+ memcpy(m, c, 64); c += 64; // first 64 bytes data
|
636 | |
+ mem_to_int(&(m->width), c); c += 4;
|
637 | |
+ mem_to_int(&(m->height), c); c += 4;
|
638 | |
+ c += 4; // skip the first pointer
|
639 | |
+ mem_to_int(&(m->offset_x), c); c += 4;
|
640 | |
+ mem_to_int(&(m->offset_y), c); c += 4;
|
641 | |
+ c += 4; // skip the second pointer
|
642 | |
+ mem_to_int(&(m->start_x), c); c+= 4;
|
643 | |
+ mem_to_int(&(m->start_y), c); c+= 4;
|
644 | |
|
645 | |
// read map data
|
646 | |
m->dat = malloc(m->width * m->height * sizeof(Tmappos));
|
647 | |
@@ -174,7 +231,18 @@
|
648 | |
fwrite(header, 6, 1, fp);
|
649 | |
|
650 | |
// write datastruct
|
651 | |
- fwrite(m, sizeof(Tmap), 1, fp);
|
652 | |
+ // a mapfile should contain a raw dump of the Tmap struct as made on an
|
653 | |
+ // i386 the code below writes a struct dump as an i386 in an arch
|
654 | |
+ // neutral manner
|
655 | |
+ fwrite(m, 64, 1, fp); // first 64 bytes data
|
656 | |
+ fwrite_int(&(m->width), fp);
|
657 | |
+ fwrite_int(&(m->height), fp);
|
658 | |
+ fwrite(header, 4, 1, fp); // skip the first pointer
|
659 | |
+ fwrite_int(&(m->offset_x), fp);
|
660 | |
+ fwrite_int(&(m->offset_y), fp);
|
661 | |
+ fwrite(header, 4, 1, fp); // skip the second pointer
|
662 | |
+ fwrite_int(&(m->start_x), fp);
|
663 | |
+ fwrite_int(&(m->start_y), fp);
|
664 | |
|
665 | |
// write map data
|
666 | |
fwrite(m->dat, sizeof(Tmappos), m->width * m->height, fp);
|
667 | |
@@ -409,7 +477,7 @@
|
668 | |
}
|
669 | |
|
670 | |
if (mask == 5 && oy > 31 - ox) return mask; // 45 degree slope /
|
671 | |
- if (mask == 6 && oy > ox) return mask; // 45 degree slope \
|
672 | |
+ if (mask == 6 && oy > ox) return mask; // 45 degree slope \ .
|
673 | |
|
674 | |
// the not so simple ones
|
675 | |
if (mask == 3 && oy > 31 - ox / 2) return mask; // 22 degree slope / (low)
|
676 | |
Index: alex4-1.1/src/shooter.h
|
677 | |
===================================================================
|
678 | |
--- alex4-1.1.orig/src/shooter.h 2008-01-26 21:33:49.000000000 +0100
|
679 | |
+++ alex4-1.1/src/shooter.h 2008-01-26 21:34:05.000000000 +0100
|
680 | |
@@ -83,8 +83,8 @@
|
681 | |
int difficulty;
|
682 | |
|
683 | |
// player related
|
684 | |
- long unsigned int score;
|
685 | |
- long unsigned int show_score;
|
686 | |
+ unsigned int score;
|
687 | |
+ unsigned int show_score;
|
688 | |
int lives;
|
689 | |
int power_gauge;
|
690 | |
int power_level;
|
691 | |
@@ -118,4 +118,4 @@
|
692 | |
int start_shooter(Tcontrol *c, int with_sound);
|
693 | |
|
694 | |
|
695 | |
-#endif
|
696 | |
\ No newline at end of file
|
697 | |
+#endif
|
698 | |
Index: alex4-1.1/src/timer.h
|
699 | |
===================================================================
|
700 | |
--- alex4-1.1.orig/src/timer.h 2008-01-26 21:33:49.000000000 +0100
|
701 | |
+++ alex4-1.1/src/timer.h 2008-01-26 21:34:05.000000000 +0100
|
702 | |
@@ -37,4 +37,4 @@
|
703 | |
void fps_counter(void);
|
704 | |
void cycle_counter(void);
|
705 | |
|
706 | |
-#endif
|
707 | |
\ No newline at end of file
|
708 | |
+#endif
|
709 | |
Index: alex4-1.1/src/main.h
|
710 | |
===================================================================
|
711 | |
--- alex4-1.1.orig/src/main.h 2008-01-26 21:33:49.000000000 +0100
|
712 | |
+++ alex4-1.1/src/main.h 2008-01-26 21:34:05.000000000 +0100
|
713 | |
@@ -93,5 +93,8 @@
|
714 | |
#define check_bb_collision(x1,y1,w1,h1,x2,y2,w2,h2) (!( ((x1)>=(x2)+(w2)) || ((x2)>=(x1)+(w1)) || \
|
715 | |
((y1)>=(y2)+(h2)) || ((y2)>=(y1)+(h1)) ))
|
716 | |
|
717 | |
+#ifndef DATADIR
|
718 | |
+#define DATADIR "data/"
|
719 | |
+#endif
|
720 | |
|
721 | |
-#endif
|
722 | |
\ No newline at end of file
|
723 | |
+#endif
|
724 | |
Index: alex4-1.1/src/script.h
|
725 | |
===================================================================
|
726 | |
--- alex4-1.1.orig/src/script.h 2008-01-26 21:33:49.000000000 +0100
|
727 | |
+++ alex4-1.1/src/script.h 2008-01-26 21:34:05.000000000 +0100
|
728 | |
@@ -51,4 +51,4 @@
|
729 | |
|
730 | |
|
731 | |
|
732 | |
-#endif
|
733 | |
\ No newline at end of file
|
734 | |
+#endif
|
735 | |
Index: alex4-1.1/src/edit.h
|
736 | |
===================================================================
|
737 | |
--- alex4-1.1.orig/src/edit.h 2008-01-26 21:33:49.000000000 +0100
|
738 | |
+++ alex4-1.1/src/edit.h 2008-01-26 21:34:05.000000000 +0100
|
739 | |
@@ -37,4 +37,4 @@
|
740 | |
void draw_edit_mode(BITMAP *bmp, Tmap *map, int mx, int my);
|
741 | |
void update_edit_mode(Tmap *map, BITMAP *bmp, int mx, int my, int mb);
|
742 | |
|
743 | |
-#endif
|
744 | |
\ No newline at end of file
|
745 | |
+#endif
|
746 | |
Index: alex4-1.1/src/token.c
|
747 | |
===================================================================
|
748 | |
--- alex4-1.1.orig/src/token.c 2008-01-26 21:33:49.000000000 +0100
|
749 | |
+++ alex4-1.1/src/token.c 2008-01-26 21:34:05.000000000 +0100
|
750 | |
@@ -67,7 +67,7 @@
|
751 | |
|
752 | |
// tokenizes the string str
|
753 | |
Ttoken *tokenize(char *str) {
|
754 | |
- Ttoken *tok_list, *tok_tmp;
|
755 | |
+ Ttoken *tok_list, *tok_tmp = NULL;
|
756 | |
char word[256];
|
757 | |
int a, b, c;
|
758 | |
int i = 0;
|
759 | |
Index: alex4-1.1/src/hisc.h
|
760 | |
===================================================================
|
761 | |
--- alex4-1.1.orig/src/hisc.h 2008-01-26 21:33:49.000000000 +0100
|
762 | |
+++ alex4-1.1/src/hisc.h 2008-01-26 21:34:05.000000000 +0100
|
763 | |
@@ -48,4 +48,4 @@
|
764 | |
void draw_hisc_post(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
|
765 | |
void draw_hisc_table(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
|
766 | |
|
767 | |
-#endif
|
768 | |
\ No newline at end of file
|
769 | |
+#endif
|
770 | |
Index: alex4-1.1/src/options.h
|
771 | |
===================================================================
|
772 | |
--- alex4-1.1.orig/src/options.h 2008-01-26 21:33:49.000000000 +0100
|
773 | |
+++ alex4-1.1/src/options.h 2008-01-26 21:34:05.000000000 +0100
|
774 | |
@@ -43,4 +43,4 @@
|
775 | |
void load_options(Toptions *o, PACKFILE *fp);
|
776 | |
void reset_options(Toptions *o);
|
777 | |
|
778 | |
-#endif
|
779 | |
\ No newline at end of file
|
780 | |
+#endif
|
781 | |
Index: alex4-1.1/src/timer.c
|
782 | |
===================================================================
|
783 | |
--- alex4-1.1.orig/src/timer.c 2008-01-26 21:33:49.000000000 +0100
|
784 | |
+++ alex4-1.1/src/timer.c 2008-01-26 21:34:05.000000000 +0100
|
785 | |
@@ -60,4 +60,4 @@
|
786 | |
game_count ++;
|
787 | |
|
788 | |
return TRUE;
|
789 | |
-}
|
790 | |
\ No newline at end of file
|
791 | |
+}
|
792 | |
Index: alex4-1.1/src/actor.h
|
793 | |
===================================================================
|
794 | |
--- alex4-1.1.orig/src/actor.h 2008-01-26 21:33:49.000000000 +0100
|
795 | |
+++ alex4-1.1/src/actor.h 2008-01-26 21:34:05.000000000 +0100
|
796 | |
@@ -91,4 +91,4 @@
|
797 | |
void kill_actor(Tactor *a);
|
798 | |
|
799 | |
|
800 | |
-#endif
|
801 | |
\ No newline at end of file
|
802 | |
+#endif
|
803 | |
Index: alex4-1.1/src/bullet.h
|
804 | |
===================================================================
|
805 | |
--- alex4-1.1.orig/src/bullet.h 2008-01-26 21:33:49.000000000 +0100
|
806 | |
+++ alex4-1.1/src/bullet.h 2008-01-26 21:34:05.000000000 +0100
|
807 | |
@@ -52,4 +52,4 @@
|
808 | |
void update_bullet(Tbullet *b);
|
809 | |
void update_bullet_with_map(Tbullet *b, Tmap *m);
|
810 | |
|
811 | |
-#endif
|
812 | |
\ No newline at end of file
|
813 | |
+#endif
|