1 Description: Support Unix-like operating systems.
2 Based on Hans de Goede's patch for Fedora.
3 Author: Hans de Goede <hdegoede@redhat.com>
4 Peter de Wachter <pdewacht@gmail.com>,
5 Peter Pentchev <roam@ringlet.net>
7 Last-Update: 2011-03-09
17 #include "../data/data.h"
22 Thisc *hisc_table_space;
23 -char working_directory[1024];
28 int playing_original_game = 1;
31 +static FILE* log_fp = NULL;
34 // // // // // // // // // // // // // // // // // // // // //
36 // loggs the text to the text file
37 void log2file(char *format, ...) {
38 va_list ptr; /* get an arg pointer */
41 - fp = fopen("log.txt", "at");
44 /* initialize ptr to point to the first argument after the format string */
45 va_start(ptr, format);
47 /* Write to logfile. */
48 - vfprintf(fp, format, ptr); // Write passed text.
49 - fprintf(fp, "\n"); // New line..
50 + vfprintf(log_fp, format, ptr); // Write passed text.
51 + fprintf(log_fp, "\n"); // New line..
66 + char *homedir = get_homedir();
69 log2file("\nInit routines:");
72 log2file(" initializing allegro");
74 garble_string(init_string, 53);
76 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.ini",
77 + homedir? homedir:".");
78 + override_config_file(filename);
80 set_config_file("alex4.ini");
82 set_window_close_button(FALSE);
86 textout_centre(swap_screen, font, "loading...", 320, 200, 1);
87 blit_to_screen(swap_screen);
90 // set switch modes and callbacks
91 if (set_display_switch_mode(SWITCH_PAUSE) < 0)
92 log2file(" * display switch mode failed");
94 log2file(" * display switch in failed");
95 if (set_display_switch_callback(SWITCH_OUT, display_switch_out) < 0)
96 log2file(" * display switch out failed");
100 // set win title (no! really???)
103 log2file(" loading data");
104 packfile_password(init_string);
105 - data = load_datafile("data/data.dat");
106 + data = load_datafile(DATADIR "data.dat");
107 packfile_password(NULL);
109 log2file(" *** failed");
113 log2file(" loading options");
115 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
116 + homedir? homedir:".");
117 + pf = pack_fopen(filename, "rp");
119 pf = pack_fopen("alex4.sav", "rp");
122 load_options(&options, pf);
126 // loading highscores
127 log2file(" loading hiscores");
129 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
130 + homedir? homedir:".");
131 + pf = pack_fopen(filename, "rp");
133 pf = pack_fopen("alex4.hi", "rp");
136 load_hisc_table(hisc_table, pf);
137 load_hisc_table(hisc_table_space, pf);
139 log2file(" loading original maps");
140 packfile_password(init_string);
141 num_levels = -1; // skip end object when counting
142 - maps = load_datafile_callback("data/maps.dat", count_maps_callback);
143 + maps = load_datafile_callback(DATADIR "maps.dat", count_maps_callback);
144 packfile_password(NULL);
146 log2file(" *** failed");
147 @@ -835,11 +858,12 @@
149 log2file(" installing sound");
150 set_volume_per_voice(0);
151 - switch(get_config_int("sound", "sound_device", 0)) {
152 + switch(get_config_int("sound", "sound_device", 1)) {
155 log2file(" DIGI_AUTODETECT selected (%d)", i);
157 +#ifdef ALLEGRO_WINDOWS
160 log2file(" DIGI_DIRECTX(0) selected (%d)", i);
162 i = DIGI_DIRECTAMX(0);
163 log2file(" DIGI_DIRECTAMX(0) selected (%d)", i);
165 +#elif defined ALLEGRO_UNIX
169 + log2file(" DIGI_OSS selected (%d)", i);
175 + log2file(" DIGI_ALSA selected (%d)", i);
180 i = -770405; // dummy number
183 if (get_config_int("sound", "use_sound_datafile", 1)) {
184 log2file(" loading sound datafile");
185 packfile_password(init_string);
186 - sfx_data = load_datafile("data/sfx_44.dat");
187 + sfx_data = load_datafile(DATADIR "sfx_44.dat");
188 if (sfx_data == NULL) {
189 - sfx_data = load_datafile("data/sfx_22.dat");
190 + sfx_data = load_datafile(DATADIR "sfx_22.dat");
191 log2file(" sfx_44.dat not found");
194 @@ -971,6 +1009,10 @@
199 + char filename[512];
200 + char *homedir = get_homedir();
203 log2file("\nExit routines:");
205 @@ -989,14 +1031,26 @@
206 // only save if everything was inited ok!
208 log2file(" saving options");
210 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.sav",
211 + homedir? homedir:".");
212 + pf = pack_fopen(filename, "wp");
214 pf = pack_fopen("alex4.sav", "wp");
217 save_options(&options, pf);
221 log2file(" saving highscores");
223 + snprintf(filename, sizeof(filename), "%s/.alex4/alex4.hi",
224 + homedir? homedir:".");
225 + pf = pack_fopen(filename, "wp");
227 pf = pack_fopen("alex4.hi", "wp");
230 save_hisc_table(hisc_table, pf);
231 save_hisc_table(hisc_table_space, pf);
232 @@ -1289,7 +1343,7 @@
233 // poll music machine
234 if (got_sound) al_poll_duh(dp);
236 - if (mode == 1 && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl) ) || my_counter > 200) {
237 + if (((mode == 1) && (keypressed() || is_fire(&ctrl) || is_jump(&ctrl))) || (my_counter > 200)) {
241 @@ -1343,7 +1397,7 @@
244 packfile_password(init_string);
245 - df = load_datafile_object("data/a45.dat", "BG1");
246 + df = load_datafile_object(DATADIR "a45.dat", "BG1");
247 packfile_password(NULL);
250 @@ -2149,7 +2203,7 @@
252 // calculates camera pos for map m considering player p
253 void calculate_camera_pos(Tplayer *p, Tmap *m) {
254 - static camera_type = 1;
255 + static int camera_type = 1;
257 if (p->actor->status == AC_BALL) {
259 @@ -2841,6 +2895,10 @@
264 + char filename[512];
265 + char *homedir = get_homedir();
267 log2file(" level complete");
268 if (got_sound) stop_music();
269 if (level < MAX_LEVELS && playing_original_game) {
270 @@ -2875,7 +2933,14 @@
273 log2file(" saving options");
275 + snprintf(filename, sizeof(filename),
276 + "%s/.alex4/alex4.sav",
277 + homedir? homedir:".");
278 + pf = pack_fopen(filename, "wp");
280 pf = pack_fopen("alex4.sav", "wp");
283 save_options(&options, pf);
285 @@ -2969,24 +3034,36 @@
288 int main(int argc, char **argv) {
291 char full_path[1024];
293 + char working_directory[1024];
295 + char *homedir = get_homedir();
303 + snprintf(full_path, sizeof(full_path), "%s/.alex4",
304 + homedir? homedir:".");
305 + check_and_create_dir(full_path);
306 + snprintf(full_path, sizeof(full_path), "%s/.alex4/log.txt",
307 + homedir? homedir:".");
308 + log_fp = fopen(full_path, "wt");
310 // get working directory
311 get_executable_name(full_path, 1024);
312 replace_filename(working_directory, full_path, "", 1024);
313 chdir(working_directory);
317 - fp = fopen("log.txt", "wt");
319 - fprintf(fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
321 + log_fp = fopen("log.txt", "wt");
324 + fprintf(log_fp, "Alex 4 (%s) - log file\n-------------------\n", GAME_VERSION_STR);
327 // log program arguments
328 @@ -2994,7 +3071,9 @@
329 for(i = 0; i < argc; i ++) {
330 log2file(" %s", argv[i]);
333 log2file("Working directory is:\n %s", working_directory);
336 // test wether to play real game
338 @@ -3022,6 +3101,8 @@
341 log2file("\nDone...\n");
350 void wound_player(Tplayer *p);
351 void kill_player(Tplayer *p);
354 \ No newline at end of file
363 \ No newline at end of file
374 +#include <sys/types.h>
375 +#include <sys/stat.h>
376 +#if defined(__DECC) && defined(VMS)
377 +#include <unixlib.h>
378 +static char *vms_to_unix_buffer = NULL;
379 +static int convert_vms_to_unix(char *vms_dir_name)
381 + vms_to_unix_buffer = vms_dir_name;
385 +char *get_homedir(void)
390 + home = getenv("HOME");
394 + if (!(pw = getpwuid(getuid())))
396 + fprintf(stderr, "Who are you? Not found in passwd database!!\n");
400 +#if defined(__DECC) && defined(VMS)
401 + /* Convert The OpenVMS Formatted "$HOME" Directory Path Into Unix
403 + decc$from_vms(pw->pw_dir, convert_vms_to_unix, 1);
404 + return vms_to_unix_buffer;
409 +//-----------------------------------------------------------------------------
410 +int check_and_create_dir(const char *name)
412 + struct stat stat_buffer;
414 + if (stat(name, &stat_buffer))
416 + /* error check if it doesn't exist or something else is wrong */
417 + if (errno == ENOENT)
419 + /* doesn't exist letts create it ;) */
421 + if (mkdir(name, 0775))
423 + if (mkdir(name, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH))
426 + fprintf(stderr, "Error creating dir %s", name);
433 + /* something else went wrong yell about it */
434 + fprintf(stderr, "Error opening %s", name);
441 + /* file exists check it's a dir otherwise yell about it */
443 + if (!(S_IFDIR & stat_buffer.st_mode))
445 + if (!S_ISDIR(stat_buffer.st_mode))
448 + fprintf(stderr,"Error %s exists but isn't a dir\n", name);
459 +DATADIR = $(PREFIX)/share/$(TARGET)
460 +CFLAGS ?= -g -Wall -Wno-deprecated-declarations -O2
461 +LIBS = -laldmb -ldumb `allegro-config --libs`
462 +DEFINES = -DDATADIR=\"$(DATADIR)/\"
463 +OBJS = actor.o edit.o map.o player.o shooter.o unix.o \
464 + bullet.o hisc.o options.o script.o timer.o \
465 + control.o main.o particle.o scroller.o token.o
469 + $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
472 + $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -o $@ -c $<
475 + mkdir -p $(PREFIX)/bin
476 + mkdir -p $(DATADIR)
477 + install -p -m 755 $(TARGET) $(PREFIX)/bin
478 + install -p -m 644 ../data/*.dat $(DATADIR)
481 + rm -f $(OBJS) $(TARGET) *~
485 Ttoken *tokenize(char *str);
489 \ No newline at end of file
493 @@ -1372,7 +1372,7 @@
495 log2file(" loading shooter data");
496 packfile_password(get_init_string());
497 - s_data = load_datafile("data/a45.dat");
498 + s_data = load_datafile(DATADIR "a45.dat");
500 log2file(" *** failed");
505 void update_particle_with_map(Tparticle *p, Tmap *m);
506 void create_burst(Tparticle *ps, int x, int y, int spread, int num, int life, int bmp);
509 \ No newline at end of file
516 +char *get_homedir();
517 +int check_and_create_dir(const char *name);
527 \ No newline at end of file
545 +static void mem_to_int(int *dest, unsigned char *mem)
547 +#if __BYTE_ORDER == __LITTLE_ENDIAN
548 + memcpy(dest, mem, 4);
550 + *dest = mem[0] | (((int)mem[1]) << 8) | (((int)mem[2]) << 16) |
551 + (((int)mem[3]) << 24);
555 +static void fread_int(int *dest, FILE *fp)
557 +#if __BYTE_ORDER == __LITTLE_ENDIAN
558 + fread(dest, 4, 1, fp);
560 + unsigned char buf[4];
561 + fread(buf, 1, 4, fp);
562 + mem_to_int(dest, buf);
566 +static void fwrite_int(const int *src, FILE *fp)
568 +#if __BYTE_ORDER == __LITTLE_ENDIAN
569 + fwrite(src, 4, 1, fp);
571 + unsigned char buf[4];
573 + buf[1] = *src >> 8;
574 + buf[2] = *src >> 16;
575 + buf[3] = *src >> 24;
576 + fwrite(buf, 1, 4, fp);
580 // loads one splendind map from disk
581 Tmap *load_map(char *fname) {
586 - fread(m, sizeof(Tmap), 1, fp);
587 + // a mapfile contain a raw dump of the Tmap struct made on an i386
588 + // the code below reads these struct dumps in an arch neutral manner
589 + // Note this dumps contains pointers, these are not used because these
590 + // ofcourse point to some no longer valid address.
591 + fread(m, 64, 1, fp); // first 64 bytes data
592 + fread_int(&(m->width), fp);
593 + fread_int(&(m->height), fp);
594 + fread(header, 4, 1, fp); // skip the first pointer
595 + fread_int(&(m->offset_x), fp);
596 + fread_int(&(m->offset_y), fp);
597 + fread(header, 4, 1, fp); // skip the second pointer
598 + fread_int(&(m->start_x), fp);
599 + fread_int(&(m->start_y), fp);
602 m->dat = malloc(m->width * m->height * sizeof(Tmappos));
604 // loads one splendind map from memory
605 Tmap *load_map_from_memory(void *mem) {
608 - char *c = (char *)mem;
609 + unsigned char header[6];
610 + unsigned char *c = (unsigned char *)mem;
613 // does the header match?
618 - // fread(m, sizeof(Tmap), 1, fp);
619 - memcpy(m, c, sizeof(Tmap));
621 + // a mapfile contain a raw dump of the Tmap struct made on an i386
622 + // the code below reads these struct dumps in an arch neutral manner
623 + // Note this dumps contains pointers, these are not used because these
624 + // ofcourse point to some no longer valid address.
625 + memcpy(m, c, 64); c += 64; // first 64 bytes data
626 + mem_to_int(&(m->width), c); c += 4;
627 + mem_to_int(&(m->height), c); c += 4;
628 + c += 4; // skip the first pointer
629 + mem_to_int(&(m->offset_x), c); c += 4;
630 + mem_to_int(&(m->offset_y), c); c += 4;
631 + c += 4; // skip the second pointer
632 + mem_to_int(&(m->start_x), c); c+= 4;
633 + mem_to_int(&(m->start_y), c); c+= 4;
636 m->dat = malloc(m->width * m->height * sizeof(Tmappos));
638 fwrite(header, 6, 1, fp);
641 - fwrite(m, sizeof(Tmap), 1, fp);
642 + // a mapfile should contain a raw dump of the Tmap struct as made on an
643 + // i386 the code below writes a struct dump as an i386 in an arch
645 + fwrite(m, 64, 1, fp); // first 64 bytes data
646 + fwrite_int(&(m->width), fp);
647 + fwrite_int(&(m->height), fp);
648 + fwrite(header, 4, 1, fp); // skip the first pointer
649 + fwrite_int(&(m->offset_x), fp);
650 + fwrite_int(&(m->offset_y), fp);
651 + fwrite(header, 4, 1, fp); // skip the second pointer
652 + fwrite_int(&(m->start_x), fp);
653 + fwrite_int(&(m->start_y), fp);
656 fwrite(m->dat, sizeof(Tmappos), m->width * m->height, fp);
660 if (mask == 5 && oy > 31 - ox) return mask; // 45 degree slope /
661 - if (mask == 6 && oy > ox) return mask; // 45 degree slope \
662 + if (mask == 6 && oy > ox) return mask; // 45 degree slope \ .
664 // the not so simple ones
665 if (mask == 3 && oy > 31 - ox / 2) return mask; // 22 degree slope / (low)
672 - long unsigned int score;
673 - long unsigned int show_score;
674 + unsigned int score;
675 + unsigned int show_score;
680 int start_shooter(Tcontrol *c, int with_sound);
684 \ No newline at end of file
689 void fps_counter(void);
690 void cycle_counter(void);
693 \ No newline at end of file
698 #define check_bb_collision(x1,y1,w1,h1,x2,y2,w2,h2) (!( ((x1)>=(x2)+(w2)) || ((x2)>=(x1)+(w1)) || \
699 ((y1)>=(y2)+(h2)) || ((y2)>=(y1)+(h1)) ))
702 +#define DATADIR "data/"
706 \ No newline at end of file
715 \ No newline at end of file
720 void draw_edit_mode(BITMAP *bmp, Tmap *map, int mx, int my);
721 void update_edit_mode(Tmap *map, BITMAP *bmp, int mx, int my, int mb);
724 \ No newline at end of file
730 // tokenizes the string str
731 Ttoken *tokenize(char *str) {
732 - Ttoken *tok_list, *tok_tmp;
733 + Ttoken *tok_list, *tok_tmp = NULL;
740 void draw_hisc_post(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
741 void draw_hisc_table(Thisc *table, BITMAP *bmp, FONT *fnt, int x, int y, int color, int show_level);
744 \ No newline at end of file
749 void load_options(Toptions *o, PACKFILE *fp);
750 void reset_options(Toptions *o);
753 \ No newline at end of file
762 \ No newline at end of file
767 void kill_actor(Tactor *a);
771 \ No newline at end of file
776 void update_bullet(Tbullet *b);
777 void update_bullet_with_map(Tbullet *b, Tmap *m);
780 \ No newline at end of file