89e6913
--- alex4src/src/main.c.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/main.c	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -38,6 +38,7 @@
89e6913
 #include "main.h"
89e6913
 #include "edit.h"
89e6913
 #include "shooter.h"
89e6913
+#include "unix.h"
89e6913
 
89e6913
 #include "../data/data.h"
89e6913
 
89e6913
@@ -66,7 +67,6 @@
89e6913
 Tscroller hscroll;
89e6913
 Thisc *hisc_table;
89e6913
 Thisc *hisc_table_space;
89e6913
-char working_directory[1024];
89e6913
 
89e6913
 // the map
89e6913
 Tmap *map = NULL;
89e6913
@@ -126,6 +126,7 @@
89e6913
 int playing_original_game = 1;
89e6913
 int init_ok = 0;
89e6913
 
89e6913
+static FILE* log_fp = NULL;
89e6913
 
89e6913
 
89e6913
 // // // // // // // // // // // // // // // // // // // // // 
89e6913
@@ -154,20 +155,18 @@
89e6913
 // loggs the text to the text file
89e6913
 void log2file(char *format, ...) {
89e6913
 	va_list ptr; /* get an arg pointer */
89e6913
- 	FILE *fp;
89e6913
 	
89e6913
-	fp = fopen("log.txt", "at");
89e6913
-	if (fp) {
89e6913
+	if (log_fp) {
89e6913
 		/* initialize ptr to point to the first argument after the format string */
89e6913
 		va_start(ptr, format);
89e6913
  
89e6913
 		/* Write to logfile. */
89e6913
-		vfprintf(fp, format, ptr); // Write passed text.
89e6913
-		fprintf(fp, "\n"); // New line..
89e6913
+		vfprintf(log_fp, format, ptr); // Write passed text.
89e6913
+		fprintf(log_fp, "\n"); // New line..
89e6913
  
89e6913
 		va_end(ptr);
89e6913
  
89e6913
-		fclose(fp);
89e6913
+		fflush(log_fp);
89e6913
 	}
89e6913
 
89e6913
 }
89e6913
@@ -618,6 +617,10 @@
89e6913
 	BITMAP *bmp;
89e6913
 	int i;
89e6913
 	int w, h;
89e6913
+#ifdef __unix__   
89e6913
+	char filename[512];
89e6913
+	char *homedir = get_homedir();
89e6913
+#endif 	
89e6913
 
89e6913
 	log2file("\nInit routines:");
89e6913
 
89e6913
@@ -625,7 +628,13 @@
89e6913
 	log2file(" initializing allegro");
89e6913
 	text_mode(-1);
89e6913
 	garble_string(init_string, 53);
89e6913
+#ifdef __unix__
89e6913
+	snprintf(filename, sizeof(filename), "%s/.alex4/alex4.ini",
89e6913
+		homedir? homedir:".");
89e6913
+	override_config_file(filename);
89e6913
+#else
89e6913
 	set_config_file("alex4.ini");
89e6913
+#endif
89e6913
 	set_window_close_button(FALSE);
89e6913
 	
89e6913
 	// install timers
89e6913
@@ -663,7 +672,7 @@
89e6913
 	
89e6913
 
89e6913
 	// init gfx
89e6913
-	if (get_config_int("graphics", "fullscreen", 0)) {
89e6913
+	if (get_config_int("graphics", "fullscreen", 1)) {
89e6913
 		w = get_config_int("graphics", "f_width", 640);
89e6913
 		h = get_config_int("graphics", "f_height", 480);
89e6913
 	}
4ada002
@@ -672,7 +681,7 @@
89e6913
 		h = get_config_int("graphics", "w_height", 480);
89e6913
 	}
89e6913
 
89e6913
-	log2file(" entering gfx mode set in alex4.ini (%dx%d %s)", w, h, (get_config_int("graphics", "fullscreen", 0) ? "full" : "win"));
89e6913
+	log2file(" entering gfx mode set in alex4.ini (%dx%d %s)", w, h, (get_config_int("graphics", "fullscreen", 1) ? "full" : "win"));
89e6913
 
89e6913
     if (set_gfx_mode(
4ada002
 		(get_config_int("graphics", "fullscreen", 0) ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED),
89e6913
@@ -695,6 +704,7 @@
89e6913
 	textout_centre(swap_screen, font, "loading...", 320, 200, 1);
89e6913
 	blit_to_screen(swap_screen);
89e6913
 
89e6913
+#ifndef __unix__
89e6913
 	// set switch modes and callbacks
89e6913
 	if (set_display_switch_mode(SWITCH_PAUSE) < 0)
89e6913
 		log2file("  * display switch mode failed");
89e6913
@@ -702,6 +712,7 @@
89e6913
 		log2file("  * display switch in failed");
89e6913
 	if (set_display_switch_callback(SWITCH_OUT, display_switch_out) < 0)
89e6913
 		log2file("  * display switch out failed");
89e6913
+#endif
89e6913
 
89e6913
 
89e6913
 	// set win title (no! really???)
89e6913
@@ -718,7 +729,7 @@
89e6913
 	// load data
89e6913
 	log2file(" loading data");
89e6913
 	packfile_password(init_string);
89e6913
-	data = load_datafile("data/data.dat");
89e6913
+	data = load_datafile(DATADIR "data.dat");
89e6913
 	packfile_password(NULL);
89e6913
 	if (data == NULL) {
89e6913
     	log2file("  *** failed");
89e6913
@@ -728,7 +739,13 @@
89e6913
 
89e6913
 	// load options
89e6913
 	log2file(" loading options");
89e6913
+#ifdef __unix__
89e6913
+	snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
89e6913
+		homedir? homedir:".");
89e6913
+	pf = pack_fopen(filename, "rp");
89e6913
+#else
89e6913
 	pf = pack_fopen("alex4.sav", "rp");
89e6913
+#endif
89e6913
 	if (pf) {
89e6913
 		load_options(&options, pf);
89e6913
 		pack_fclose(pf);
89e6913
@@ -740,7 +757,13 @@
89e6913
 
89e6913
 	// loading highscores
89e6913
 	log2file(" loading hiscores");
89e6913
+#ifdef __unix__
89e6913
+	snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
89e6913
+		homedir? homedir:".");
89e6913
+	pf = pack_fopen(filename, "rp");
89e6913
+#else
89e6913
 	pf = pack_fopen("alex4.hi", "rp");
89e6913
+#endif
89e6913
 	if (pf) {
89e6913
 		load_hisc_table(hisc_table, pf);
89e6913
 		load_hisc_table(hisc_table_space, pf);
89e6913
@@ -776,7 +799,7 @@
89e6913
 		log2file(" loading original maps");
89e6913
 		packfile_password(init_string);
89e6913
 		num_levels = -1;  // skip end object when counting
89e6913
-		maps = load_datafile_callback("data/maps.dat", count_maps_callback);
89e6913
+		maps = load_datafile_callback(DATADIR "maps.dat", count_maps_callback);
89e6913
 		packfile_password(NULL);
89e6913
 		if (maps == NULL) {
89e6913
 	    	log2file("  *** failed");
89e6913
@@ -835,11 +858,12 @@
89e6913
 	// install sound
89e6913
 	log2file(" installing sound");
89e6913
    	set_volume_per_voice(0);
89e6913
-	switch(get_config_int("sound", "sound_device", 0)) {
89e6913
+	switch(get_config_int("sound", "sound_device", 1)) {
89e6913
 		case 1:
89e6913
 			i = DIGI_AUTODETECT;
89e6913
 			log2file("  DIGI_AUTODETECT selected (%d)", i);
89e6913
 			break;
89e6913
+#ifdef ALLEGRO_WINDOWS
89e6913
 		case 2:
89e6913
 			i = DIGI_DIRECTX(0);
89e6913
 			log2file("  DIGI_DIRECTX(0) selected (%d)", i);
89e6913
@@ -848,6 +872,20 @@
89e6913
 			i = DIGI_DIRECTAMX(0);
89e6913
 			log2file("  DIGI_DIRECTAMX(0) selected (%d)", i);
89e6913
 			break;
89e6913
+#elif defined ALLEGRO_UNIX
89e6913
+#ifdef DIGI_OSS
89e6913
+		case 2:
89e6913
+			i = DIGI_OSS;
89e6913
+			log2file("  DIGI_OSS selected (%d)", i);
89e6913
+			break;
89e6913
+#endif
89e6913
+#ifdef DIGI_ALSA
89e6913
+		case 3:
89e6913
+			i = DIGI_ALSA;
89e6913
+			log2file("  DIGI_ALSA selected (%d)", i);
89e6913
+			break;
89e6913
+#endif
89e6913
+#endif
89e6913
 		default:
89e6913
 			i = -770405;	// dummy number
89e6913
 			got_sound = 0;
89e6913
@@ -870,9 +908,9 @@
89e6913
 		if (get_config_int("sound", "use_sound_datafile", 1)) {
89e6913
 			log2file(" loading sound datafile");
89e6913
 			packfile_password(init_string);
89e6913
-			sfx_data = load_datafile("data/sfx_44.dat");
89e6913
+			sfx_data = load_datafile(DATADIR "sfx_44.dat");
89e6913
 			if (sfx_data == NULL) {
89e6913
-				sfx_data = load_datafile("data/sfx_22.dat");
89e6913
+				sfx_data = load_datafile(DATADIR "sfx_22.dat");
89e6913
 				log2file("  sfx_44.dat not found");
89e6913
 				s = 0;
89e6913
 			}
89e6913
@@ -971,6 +1009,10 @@
89e6913
 void uninit_game() {
89e6913
 	int i;
89e6913
 	PACKFILE *pf;
89e6913
+#ifdef __unix__   
89e6913
+	char filename[512];
89e6913
+	char *homedir = get_homedir();
89e6913
+#endif 	
89e6913
 
89e6913
 	log2file("\nExit routines:");
89e6913
 
89e6913
@@ -989,14 +1031,26 @@
89e6913
 	// only save if everything was inited ok!
89e6913
 	if (init_ok) {
89e6913
 		log2file(" saving options");
89e6913
+#ifdef __unix__
89e6913
+		snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
89e6913
+			homedir? homedir:".");
89e6913
+		pf = pack_fopen(filename, "wp");
89e6913
+#else
89e6913
 		pf = pack_fopen("alex4.sav", "wp");
89e6913
+#endif
89e6913
 		if (pf) {
89e6913
 			save_options(&options, pf);
89e6913
 			pack_fclose(pf);
89e6913
 		}
89e6913
 		
89e6913
 		log2file(" saving highscores");
89e6913
+#ifdef __unix__
89e6913
+		snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
89e6913
+			homedir? homedir:".");
89e6913
+		pf = pack_fopen(filename, "wp");
89e6913
+#else
89e6913
 		pf = pack_fopen("alex4.hi", "wp");
89e6913
+#endif
89e6913
 		if (pf) {
89e6913
 			save_hisc_table(hisc_table, pf);
89e6913
 			save_hisc_table(hisc_table_space, pf);
89e6913
@@ -1289,7 +1343,7 @@
89e6913
 			// poll music machine
89e6913
 			if (got_sound) al_poll_duh(dp);
89e6913
 
89e6913
-			if (mode == 1 && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl) ) || my_counter > 200) {
89e6913
+			if (((mode == 1) && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl))) || (my_counter > 200)) {
89e6913
 				mode = 2;
89e6913
 			}
89e6913
 			
89e6913
@@ -1343,7 +1397,7 @@
89e6913
 	if (space) {
89e6913
 		// get space bg
89e6913
 		packfile_password(init_string);
89e6913
-		df = load_datafile_object("data/a45.dat", "BG1");
89e6913
+		df = load_datafile_object(DATADIR "a45.dat", "BG1");
89e6913
 		packfile_password(NULL);
89e6913
 		if (df != NULL)	{
89e6913
 			bg = df->dat;
89e6913
@@ -2149,7 +2203,7 @@
89e6913
 
89e6913
 // calculates camera pos for map m considering player p
89e6913
 void calculate_camera_pos(Tplayer *p, Tmap *m) {
89e6913
-	static camera_type = 1;
89e6913
+	static int camera_type = 1;
89e6913
 
89e6913
 	if (p->actor->status == AC_BALL) {
89e6913
 		camera_type = 2;
89e6913
@@ -2841,6 +2895,10 @@
89e6913
 			}
89e6913
 			else {
89e6913
 				PACKFILE *pf;
89e6913
+#ifdef __unix__   
89e6913
+				char filename[512];
89e6913
+				char *homedir = get_homedir();
89e6913
+#endif 	
89e6913
 				log2file(" level complete");
89e6913
 				if (got_sound) stop_music();
89e6913
 				if (level < MAX_LEVELS && playing_original_game) {
89e6913
@@ -2875,7 +2933,14 @@
89e6913
 
89e6913
 				// save options
89e6913
 				log2file(" saving options");
89e6913
+#ifdef __unix__
89e6913
+				snprintf(filename, sizeof(filename),
89e6913
+					"%s/.alex4/alex4.sav",
89e6913
+					homedir? homedir:".");
89e6913
+				pf = pack_fopen(filename, "wp");
89e6913
+#else
89e6913
 				pf = pack_fopen("alex4.sav", "wp");
89e6913
+#endif
89e6913
 				if (pf) {
89e6913
 					save_options(&options, pf);
89e6913
 					pack_fclose(pf);
89e6913
@@ -2969,24 +3034,36 @@
89e6913
 
89e6913
 // main
89e6913
 int main(int argc, char **argv) {   
89e6913
-	FILE *fp;
89e6913
 	int i;
89e6913
 	char full_path[1024];
89e6913
+#ifndef __unix__   
89e6913
+	char working_directory[1024];
89e6913
+#else
89e6913
+	char *homedir = get_homedir();
89e6913
+#endif
89e6913
 
89e6913
 	// init allegro
89e6913
 	allegro_init();
89e6913
 
89e6913
+#ifdef __unix__
89e6913
+	// start logfile
89e6913
+	snprintf(full_path, sizeof(full_path), "%s/.alex4",
89e6913
+		homedir? homedir:".");
89e6913
+	check_and_create_dir(full_path);
89e6913
+	snprintf(full_path, sizeof(full_path), "%s/.alex4/log.txt",
89e6913
+		homedir? homedir:".");
89e6913
+	log_fp = fopen(full_path, "wt");
89e6913
+#else
89e6913
 	// get working directory
89e6913
 	get_executable_name(full_path, 1024);
89e6913
 	replace_filename(working_directory, full_path, "", 1024);
89e6913
 	chdir(working_directory);
89e6913
 
89e6913
-
89e6913
 	// start logfile
89e6913
-	fp = fopen("log.txt", "wt");
89e6913
-	if (fp) {
89e6913
-		fprintf(fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
89e6913
-		fclose(fp);
89e6913
+	log_fp = fopen("log.txt", "wt");
89e6913
+#endif
89e6913
+	if (log_fp) {
89e6913
+		fprintf(log_fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
89e6913
 	}
89e6913
 
89e6913
 	// log program arguments
89e6913
@@ -2994,7 +3071,9 @@
89e6913
 	for(i = 0; i < argc; i ++) {
89e6913
 		log2file("   %s", argv[i]);
89e6913
 	}
89e6913
+#ifndef __unix__
89e6913
 	log2file("Working directory is:\n   %s", working_directory);
89e6913
+#endif
89e6913
 
89e6913
 	// test wether to play real game
89e6913
 	// or custom levels
89e6913
@@ -3022,6 +3101,8 @@
89e6913
 	uninit_game();
89e6913
 	allegro_exit();
89e6913
 	log2file("\nDone...\n");
89e6913
+	if (log_fp)
89e6913
+		fclose(log_fp);
89e6913
 
89e6913
 	return 0;
89e6913
 } END_OF_MAIN(); 
89e6913
--- alex4src/src/player.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/player.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -60,4 +60,4 @@
89e6913
 void wound_player(Tplayer *p);
89e6913
 void kill_player(Tplayer *p);
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/map.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/map.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -111,4 +111,4 @@
89e6913
 
89e6913
 
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- /dev/null	2006-11-03 08:26:09.036129000 +0100
89e6913
+++ alex4src/src/unix.c	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -0,0 +1,82 @@
89e6913
+#ifdef __unix__
89e6913
+#include <stdio.h>
89e6913
+#include <stdlib.h>
89e6913
+#include <unistd.h>
89e6913
+#include <pwd.h>
89e6913
+#include <errno.h>
89e6913
+#include <sys/types.h>
89e6913
+#include <sys/stat.h>
89e6913
+#if defined(__DECC) && defined(VMS)
89e6913
+#include <unixlib.h>
89e6913
+static char *vms_to_unix_buffer = NULL;
89e6913
+static int convert_vms_to_unix(char *vms_dir_name)
89e6913
+{
89e6913
+	vms_to_unix_buffer = vms_dir_name;
89e6913
+}
89e6913
+#endif
89e6913
+
89e6913
+char *get_homedir(void)
89e6913
+{
89e6913
+	struct passwd *pw;
89e6913
+
89e6913
+	if (!(pw = getpwuid(getuid())))
89e6913
+	{ 
89e6913
+		fprintf(stderr, "Who are you? Not found in passwd database!!\n");
89e6913
+		return getenv("HOME");
89e6913
+	}
89e6913
+
89e6913
+#if defined(__DECC) && defined(VMS)
89e6913
+	/* Convert The OpenVMS Formatted "$HOME" Directory Path Into Unix
89e6913
+	   Format. */
89e6913
+	decc$from_vms(pw->pw_dir, convert_vms_to_unix, 1);
89e6913
+	return vms_to_unix_buffer;
89e6913
+#else
89e6913
+	return pw->pw_dir;
89e6913
+#endif
89e6913
+}
89e6913
+//-----------------------------------------------------------------------------
89e6913
+int check_and_create_dir(const char *name)
89e6913
+{
89e6913
+	struct stat stat_buffer;
89e6913
+
89e6913
+	if (stat(name, &stat_buffer))
89e6913
+	{
89e6913
+		/* error check if it doesn't exist or something else is wrong */
89e6913
+		if (errno == ENOENT)
89e6913
+		{
89e6913
+			/* doesn't exist letts create it ;) */
89e6913
+#ifdef BSD43
89e6913
+			if (mkdir(name, 0775))
89e6913
+#else
89e6913
+				if (mkdir(name, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH))
89e6913
+#endif
89e6913
+				{
89e6913
+					fprintf(stderr, "Error creating dir %s", name);
89e6913
+					perror(" ");
89e6913
+					return -1;
89e6913
+				}
89e6913
+		}
89e6913
+		else
89e6913
+		{
89e6913
+			/* something else went wrong yell about it */
89e6913
+			fprintf(stderr, "Error opening %s", name);
89e6913
+			perror(" ");
89e6913
+			return -1;
89e6913
+		}
89e6913
+	}
89e6913
+	else
89e6913
+	{
89e6913
+		/* file exists check it's a dir otherwise yell about it */
89e6913
+#ifdef BSD43
89e6913
+		if (!(S_IFDIR & stat_buffer.st_mode))
89e6913
+#else
89e6913
+			if (!S_ISDIR(stat_buffer.st_mode))
89e6913
+#endif
89e6913
+			{
89e6913
+				fprintf(stderr,"Error %s exists but isn't a dir\n", name);
89e6913
+				return -1;
89e6913
+			}
89e6913
+	}
89e6913
+	return 0;
89e6913
+}
89e6913
+#endif
89e6913
--- /dev/null	2006-11-03 08:26:09.036129000 +0100
89e6913
+++ alex4src/src/Makefile	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -0,0 +1,24 @@
89e6913
+PREFIX  = /usr/local
89e6913
+DATADIR = $(PREFIX)/share/$(TARGET)
89e6913
+CFLAGS  = -g -Wall -Wno-deprecated-declarations -O2
89e6913
+LDFLAGS = `allegro-config --libs` -laldmb -ldumb
89e6913
+DEFINES = -DDATADIR=\"$(DATADIR)/\"
89e6913
+OBJS    =  actor.o    edit.o  map.o       player.o    shooter.o unix.o \
89e6913
+           bullet.o   hisc.o  options.o   script.o    timer.o          \
89e6913
+           control.o  main.o  particle.o  scroller.o  token.o
89e6913
+TARGET  = alex4
89e6913
+
89e6913
+$(TARGET): $(OBJS)
89e6913
+	$(CC) $(LDFLAGS) -o $@ $^
89e6913
+
89e6913
+%.o: %.c
89e6913
+	$(CC) $(CFLAGS) $(DEFINES) -o $@ -c $<
89e6913
+
89e6913
+install: $(TARGET)
89e6913
+	mkdir -p $(PREFIX)/bin
89e6913
+	mkdir -p $(DATADIR)
89e6913
+	install -p -m 755 $(TARGET) $(PREFIX)/bin
89e6913
+	install -p -m 644 ../data/*.dat $(DATADIR)
89e6913
+	
89e6913
+clean:
89e6913
+	rm -f $(OBJS) $(TARGET) *~
89e6913
--- alex4src/src/token.h.unix	2003-07-26 12:53:54.000000000 +0200
89e6913
+++ alex4src/src/token.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -41,4 +41,4 @@
89e6913
 Ttoken *tokenize(char *str);
89e6913
 
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/shooter.c.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/shooter.c	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -1372,7 +1372,7 @@
89e6913
 	// load data
89e6913
 	log2file(" loading shooter data");
89e6913
 	packfile_password(get_init_string());
89e6913
-	s_data = load_datafile("data/a45.dat");
89e6913
+	s_data = load_datafile(DATADIR "a45.dat");
89e6913
 	if (!s_data) {
89e6913
 		log2file(" *** failed");
89e6913
 		return -1;
89e6913
--- alex4src/src/particle.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/particle.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -54,4 +54,4 @@
89e6913
 void update_particle_with_map(Tparticle *p, Tmap *m);
89e6913
 void create_burst(Tparticle *ps, int x, int y, int spread, int num, int life, int bmp);
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- /dev/null	2006-11-03 08:26:09.036129000 +0100
89e6913
+++ alex4src/src/unix.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -0,0 +1,6 @@
89e6913
+#ifdef __unix__
89e6913
+
89e6913
+char *get_homedir();
89e6913
+int check_and_create_dir(const char *name);
89e6913
+
89e6913
+#endif
89e6913
--- alex4src/src/scroller.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/scroller.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -51,4 +51,4 @@
89e6913
 
89e6913
 
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/map.c.unix	2003-07-28 18:50:36.000000000 +0200
89e6913
+++ alex4src/src/map.c	2006-11-03 14:17:51.000000000 +0100
89e6913
@@ -24,6 +24,7 @@
89e6913
 #include <stdlib.h>
89e6913
 #include <stdio.h>
89e6913
 #include <string.h>
89e6913
+#include <endian.h>
89e6913
 #include "allegro.h"
89e6913
 #include "map.h"
89e6913
 #include "timer.h"
89e6913
@@ -64,7 +65,41 @@
89e6913
 
89e6913
 	return m;
89e6913
 }
89e6913
-	
89e6913
+
89e6913
+static void mem_to_int(int *dest, unsigned char *mem)
89e6913
+{
89e6913
+#if __BYTE_ORDER == __LITTLE_ENDIAN
89e6913
+	memcpy(dest, mem, 4);
89e6913
+#else
89e6913
+	*dest = mem[0] | (((int)mem[1]) << 8) | (((int)mem[2]) << 16) |
89e6913
+		(((int)mem[3]) << 24);
89e6913
+#endif
89e6913
+}
89e6913
+
89e6913
+static void fread_int(int *dest, FILE *fp)
89e6913
+{
89e6913
+#if __BYTE_ORDER == __LITTLE_ENDIAN
89e6913
+	fread(dest, 4, 1, fp);
89e6913
+#else
89e6913
+	unsigned char buf[4];
89e6913
+	fread(buf, 1, 4, fp);
89e6913
+	mem_to_int(dest, buf);
89e6913
+#endif
89e6913
+}
89e6913
+
89e6913
+static void fwrite_int(const int *src, FILE *fp)
89e6913
+{
89e6913
+#if __BYTE_ORDER == __LITTLE_ENDIAN
89e6913
+	fwrite(src, 4, 1, fp);
89e6913
+#else
89e6913
+	unsigned char buf[4];
89e6913
+	buf[0] = *src;
89e6913
+	buf[1] = *src >> 8;
89e6913
+	buf[2] = *src >> 16;
89e6913
+	buf[3] = *src >> 24;
89e6913
+	fwrite(buf, 1, 4, fp);
89e6913
+#endif
89e6913
+}
89e6913
 
89e6913
 // loads one splendind map from disk
89e6913
 Tmap *load_map(char *fname) {
89e6913
@@ -93,7 +128,19 @@
89e6913
 	}
89e6913
 	
89e6913
 	// read datastruct
89e6913
-	fread(m, sizeof(Tmap), 1, fp);
89e6913
+	// a mapfile contain a raw dump of the Tmap struct made on an i386
89e6913
+	// the code below reads these struct dumps in an arch neutral manner
89e6913
+	// Note this dumps contains pointers, these are not used because these
89e6913
+	// ofcourse point to some no longer valid address.
89e6913
+	fread(m, 64, 1, fp);             // first 64 bytes data
89e6913
+	fread_int(&(m->width), fp);
89e6913
+	fread_int(&(m->height), fp);
89e6913
+	fread(header, 4, 1, fp);         // skip the first pointer
89e6913
+	fread_int(&(m->offset_x), fp);
89e6913
+	fread_int(&(m->offset_y), fp);
89e6913
+	fread(header, 4, 1, fp);         // skip the second pointer
89e6913
+	fread_int(&(m->start_x), fp);
89e6913
+	fread_int(&(m->start_y), fp);
89e6913
 
89e6913
 	// read map data
89e6913
 	m->dat = malloc(m->width * m->height * sizeof(Tmappos));
89e6913
@@ -116,8 +163,8 @@
89e6913
 // loads one splendind map from memory
89e6913
 Tmap *load_map_from_memory(void *mem) {
89e6913
 	Tmap *m;
89e6913
-	char header[6];
89e6913
-    char *c = (char *)mem;
89e6913
+	unsigned char header[6];
89e6913
+	unsigned char *c = (unsigned char *)mem;
89e6913
 
89e6913
 	
89e6913
 	// does the header match?
89e6913
@@ -137,9 +184,19 @@
89e6913
 	}
89e6913
 	
89e6913
 	// read datastruct
89e6913
-	// fread(m, sizeof(Tmap), 1, fp);
89e6913
-	memcpy(m, c, sizeof(Tmap));
89e6913
-    c += sizeof(Tmap);
89e6913
+	// a mapfile contain a raw dump of the Tmap struct made on an i386
89e6913
+	// the code below reads these struct dumps in an arch neutral manner
89e6913
+	// Note this dumps contains pointers, these are not used because these
89e6913
+	// ofcourse point to some no longer valid address.
89e6913
+	memcpy(m, c, 64); c += 64;             // first 64 bytes data
89e6913
+	mem_to_int(&(m->width), c);  c += 4;
89e6913
+	mem_to_int(&(m->height), c); c += 4;
89e6913
+	c += 4;	                               // skip the first pointer
89e6913
+	mem_to_int(&(m->offset_x), c); c += 4;
89e6913
+	mem_to_int(&(m->offset_y), c); c += 4;
89e6913
+	c += 4;                                // skip the second pointer
89e6913
+	mem_to_int(&(m->start_x), c); c+= 4;
89e6913
+	mem_to_int(&(m->start_y), c); c+= 4;
89e6913
 
89e6913
 	// read map data
89e6913
 	m->dat = malloc(m->width * m->height * sizeof(Tmappos));
89e6913
@@ -174,7 +231,18 @@
89e6913
 	fwrite(header, 6, 1, fp);
89e6913
 
89e6913
 	// write datastruct
89e6913
-	fwrite(m, sizeof(Tmap), 1, fp);
89e6913
+	// a mapfile should contain a raw dump of the Tmap struct as made on an
89e6913
+	// i386 the code below writes a struct dump as an i386 in an arch
89e6913
+	// neutral manner
89e6913
+	fwrite(m, 64, 1, fp);             // first 64 bytes data
89e6913
+	fwrite_int(&(m->width), fp);
89e6913
+	fwrite_int(&(m->height), fp);
89e6913
+	fwrite(header, 4, 1, fp);         // skip the first pointer
89e6913
+	fwrite_int(&(m->offset_x), fp);
89e6913
+	fwrite_int(&(m->offset_y), fp);
89e6913
+	fwrite(header, 4, 1, fp);         // skip the second pointer
89e6913
+	fwrite_int(&(m->start_x), fp);
89e6913
+	fwrite_int(&(m->start_y), fp);
89e6913
 
89e6913
 	// write map data
89e6913
 	fwrite(m->dat, sizeof(Tmappos), m->width * m->height, fp);
89e6913
@@ -409,7 +477,7 @@
89e6913
 	}
89e6913
 
89e6913
 	if (mask == 5 && oy > 31 - ox) return mask; // 45 degree slope / 
89e6913
-	if (mask == 6 && oy > ox) return mask;		// 45 degree slope \
89e6913
+	if (mask == 6 && oy > ox) return mask;		// 45 degree slope \ .
89e6913
 
89e6913
 	// the not so simple ones
89e6913
 	if (mask == 3 && oy > 31 - ox / 2) return mask;	// 22 degree slope / (low)
89e6913
--- alex4src/src/shooter.h.unix	2003-07-26 12:53:54.000000000 +0200
89e6913
+++ alex4src/src/shooter.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -83,8 +83,8 @@
89e6913
 	int difficulty;
89e6913
 
89e6913
 	// player related
89e6913
-	long unsigned int score;
89e6913
-	long unsigned int show_score;
89e6913
+	unsigned int score;
89e6913
+	unsigned int show_score;
89e6913
 	int lives;
89e6913
 	int power_gauge;
89e6913
 	int power_level;
89e6913
@@ -118,4 +118,4 @@
89e6913
 int start_shooter(Tcontrol *c, int with_sound);
89e6913
 
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/timer.h.unix	2003-07-26 12:53:54.000000000 +0200
89e6913
+++ alex4src/src/timer.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -37,4 +37,4 @@
89e6913
 void fps_counter(void);
89e6913
 void cycle_counter(void);
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/main.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/main.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -93,5 +93,8 @@
89e6913
 #define check_bb_collision(x1,y1,w1,h1,x2,y2,w2,h2) (!( ((x1)>=(x2)+(w2)) || ((x2)>=(x1)+(w1)) || \
89e6913
                                                         ((y1)>=(y2)+(h2)) || ((y2)>=(y1)+(h1)) ))
89e6913
 
89e6913
+#ifndef DATADIR
89e6913
+#define DATADIR "data/"
89e6913
+#endif
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/script.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/script.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -51,4 +51,4 @@
89e6913
 
89e6913
 
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/edit.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/edit.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -37,4 +37,4 @@
89e6913
 void draw_edit_mode(BITMAP *bmp, Tmap *map, int mx, int my);
89e6913
 void update_edit_mode(Tmap *map, BITMAP *bmp, int mx, int my, int mb);
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/token.c.unix	2003-07-26 18:50:40.000000000 +0200
89e6913
+++ alex4src/src/token.c	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -67,7 +67,7 @@
89e6913
 
89e6913
 // tokenizes the string str
89e6913
 Ttoken *tokenize(char *str) {
89e6913
-    Ttoken *tok_list, *tok_tmp;
89e6913
+    Ttoken *tok_list, *tok_tmp = NULL;
89e6913
     char word[256];
89e6913
     int a, b, c;
89e6913
     int i = 0;
89e6913
--- alex4src/src/hisc.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/hisc.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -48,4 +48,4 @@
89e6913
 void draw_hisc_post(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
89e6913
 void draw_hisc_table(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/options.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/options.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -43,4 +43,4 @@
89e6913
 void load_options(Toptions *o, PACKFILE *fp);
89e6913
 void reset_options(Toptions *o);
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/timer.c.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/timer.c	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -60,4 +60,4 @@
89e6913
 	game_count ++;
89e6913
 
89e6913
 	return TRUE;
89e6913
-}
89e6913
\ No newline at end of file
89e6913
+}
89e6913
--- alex4src/src/actor.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/actor.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -91,4 +91,4 @@
89e6913
 void kill_actor(Tactor *a);
89e6913
 
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif
89e6913
--- alex4src/src/bullet.h.unix	2003-07-26 12:53:52.000000000 +0200
89e6913
+++ alex4src/src/bullet.h	2006-11-03 13:26:37.000000000 +0100
89e6913
@@ -52,4 +52,4 @@
89e6913
 void update_bullet(Tbullet *b);
89e6913
 void update_bullet_with_map(Tbullet *b, Tmap *m);
89e6913
 
89e6913
-#endif
89e6913
\ No newline at end of file
89e6913
+#endif