From: Holger Schemel Date: Sun, 8 Nov 1998 14:56:25 +0000 (+0100) Subject: rnd-19981108-2 X-Git-Tag: 1.2.0^2~35 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=49dab46aa55cb43233c7f9a310593f8bd8debc29;p=rocksndiamonds.git rnd-19981108-2 --- diff --git a/src/Makefile b/src/Makefile index a4f45718..50502fa7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,32 +1,59 @@ -# -# Makefile fuer "Rocks'n'Diamonds -- McDuffin Strikes Back" -# +#=============================================================================# +# Makefile for Rocks'n'Diamonds 1.2 # +# (c) 1995-98 Holger Schemel, aeglos@valinor.owl.de # +#=============================================================================# -PROGNAME = rocksndiamonds -# SERVNAME = rnd_server +#-----------------------------------------------------------------------------# +# configuration section # +#-----------------------------------------------------------------------------# -RM = rm -f +# change this to your favorite ANSI C compiler CC = gcc -CPP = $(CC) -E -# CC = cc # for HP-UX and others -GAME_DIR = -DGAME_DIR=\".\" # path of the game and its data -# JOYSTICK = -DNO_JOYSTICK # no joystick -# SOUNDS = -DNO_SOUNDS # no sounds -# SCORE_ENTRIES = -DONE_PER_NAME # only one score entry per name -SCORE_ENTRIES = -DMANY_PER_NAME # many score entries per name +# on Solaris and similar systems, you'll need to uncomment this +# EXTRA_LIBS = -lnsl -lsocket + +# specify X11 library path on your system +XLIB_PATH = /usr/X11/lib + +# change this to the directory where you want to install game data like levels +GAME_DIR = . + +# uncomment this if your system has no joystick include file +# JOYSTICK = -DNO_JOYSTICK + +# uncomment this if your system has no sound +# SOUNDS = -DNO_SOUNDS + +# choose if you want to allow many global score file entries for one player +# when installing the game in a multi user environment, choose this +# SCORE_ENTRIES = ONE_PER_NAME +# when installing the game in a single user environment, choose this +SCORE_ENTRIES = MANY_PER_NAME # The XPM-Library is no longer needed to build this program, # but is used to load graphics if XPM_INCLUDE_FILE is defined, # because the GIF loading routines are still a bit beta. -# If you use the Xpm library, convert the GIF files to Xpm -# files (and the mask files ('*Maske.gif') to xbm files). +# If you want to use the Xpm library, convert the GIF files to Xpm +# files (and you need corresponding mask files in xbm format). # XPM_INCLUDE_FILE = -DXPM_INCLUDE_FILE="" # EXTRA_X11_LIBS = -lXpm -CONFIG = $(GAME_DIR) $(SOUNDS) $(JOYSTICK) \ - $(SCORE_ENTRIES) $(XPM_INCLUDE_FILE) +#-----------------------------------------------------------------------------# +# you shouldn't need to change anything below # +#-----------------------------------------------------------------------------# + +PROGNAME = rocksndiamonds + +RM = rm -f +CPP = $(CC) -E + +CONFIG_GAME_DIR = -DGAME_DIR="\"$(GAME_DIR)\"" +CONFIG_SCORE_ENTRIES = -D$(SCORE_ENTRIES) + +CONFIG = $(CONFIG_GAME_DIR) $(SOUNDS) $(JOYSTICK) \ + $(CONFIG_SCORE_ENTRIES) $(XPM_INCLUDE_FILE) # DEBUG = -DDEBUG -g -ansi -pedantic -Wall DEBUG = -DDEBUG -g -Wall @@ -44,7 +71,8 @@ DEBUG = -DDEBUG -g -Wall # LIBS = -L/usr/X11R6/lib -lXpm -lX11 -lm # LIBS = -L/usr/X11R6/lib -lX11 -lm -LIBS = -L/usr/X11R6/lib $(EXTRA_X11_LIBS) -lX11 -lm +# LIBS = -L/usr/X11R6/lib $(EXTRA_X11_LIBS) -lX11 -lm $(EXTRA_LIBS) +LIBS = -L$(XLIB_PATH) $(EXTRA_X11_LIBS) -lX11 -lm $(EXTRA_LIBS) # CFLAGS = -O2 $(CONFIG) $(SYSTEM) CFLAGS = $(DEBUG) $(CONFIG) $(SYSTEM) $(INCL) @@ -93,15 +121,11 @@ OBJS = main.o \ network.o \ netserv.o -# all: $(PROGNAME) $(SERVNAME) all: $(PROGNAME) $(PROGNAME): $(OBJS) $(CC) $(CFLAGS) $(OBJS) $(LIBS) -o $(PROGNAME) -# $(SERVNAME): $(SERVNAME).c -# $(CC) $(CFLAGS) $(SERVNAME).c $(LIBS) -o $(SERVNAME) - .c.o: $(CC) $(CFLAGS) -c $*.c diff --git a/src/files.c b/src/files.c index bdd8b543..fc7d7a94 100644 --- a/src/files.c +++ b/src/files.c @@ -19,7 +19,14 @@ #include "tape.h" #include "joystick.h" -static char *getUserdataDir() +#define MAX_LINE_LEN 1000 + +static char *getGlobalDataDir() +{ + return GAME_DIR; +} + +static char *getUserDataDir() { static char *userdata_dir = NULL; @@ -37,14 +44,14 @@ static char *getUserdataDir() static char *getSetupDir() { - return getUserdataDir(); + return getUserDataDir(); } static char *getTapeDir(char *level_subdir) { static char *tape_dir = NULL; - char *data_dir = getUserdataDir(); - char *tape_subdir = TAPEDATA_DIRECTORY; + char *data_dir = getUserDataDir(); + char *tape_subdir = TAPES_DIRECTORY; if (tape_dir) free(tape_dir); @@ -57,6 +64,23 @@ static char *getTapeDir(char *level_subdir) return tape_dir; } +static char *getScoreDir(char *level_subdir) +{ + static char *score_dir = NULL; + char *data_dir = getGlobalDataDir(); + char *score_subdir = SCORES_DIRECTORY; + + if (score_dir) + free(score_dir); + + score_dir = checked_malloc(strlen(data_dir) + strlen(score_subdir) + + strlen(level_subdir) + 3); + sprintf(score_dir, "%s/%s%s%s", data_dir, score_subdir, + (strlen(level_subdir) > 0 ? "/" : ""), level_subdir); + + return score_dir; +} + static void createDirectory(char *dir, char *text) { if (access(dir, F_OK) != 0) @@ -64,15 +88,21 @@ static void createDirectory(char *dir, char *text) Error(ERR_WARN, "cannot create %s directory '%s'", text, dir); } -void InitUserdataDirectory() +static void InitUserDataDirectory() { - createDirectory(getUserdataDir(), "user data"); + createDirectory(getUserDataDir(), "user data"); } static void InitTapeDirectory(char *level_subdir) { - createDirectory(getTapeDir(""), "main tape data"); - createDirectory(getTapeDir(level_subdir), "level tape data"); + createDirectory(getTapeDir(""), "main tape"); + createDirectory(getTapeDir(level_subdir), "level tape"); +} + +static void InitScoreDirectory(char *level_subdir) +{ + createDirectory(getScoreDir(""), "main score"); + createDirectory(getScoreDir(level_subdir), "level score"); } boolean LoadLevelInfo() @@ -82,16 +112,16 @@ boolean LoadLevelInfo() char cookie[MAX_FILENAME_LEN]; FILE *file; - sprintf(filename,"%s/%s",level_directory,LEVDIR_FILENAME); + sprintf(filename, "%s/%s", options.level_directory, LEVDIR_FILENAME); - if (!(file=fopen(filename,"r"))) + if (!(file = fopen(filename, "r"))) { Error(ERR_WARN, "cannot read level info '%s'", filename); return(FALSE); } - fscanf(file,"%s\n",cookie); - if (strcmp(cookie,LEVELDIR_COOKIE)) /* ungültiges Format? */ + fscanf(file, "%s\n", cookie); + if (strcmp(cookie, LEVELDIR_COOKIE)) { Error(ERR_WARN, "wrong format of level info file"); fclose(file); @@ -100,12 +130,12 @@ boolean LoadLevelInfo() num_leveldirs = 0; leveldir_nr = 0; - for(i=0;i= 0) diff --git a/src/init.c b/src/init.c index 52facada..8e60cfeb 100644 --- a/src/init.c +++ b/src/init.c @@ -65,7 +65,6 @@ void OpenAll(int argc, char *argv[]) exit(0); } - InitUserdataDirectory(); InitLevelAndPlayerInfo(); InitCounter(); @@ -357,14 +356,18 @@ void InitWindow(int argc, char *argv[]) XChangeProperty(display, window, proto_atom, XA_ATOM, 32, PropModePrepend, (unsigned char *) &delete_atom, 1); - sprintf(icon_filename,"%s/%s",GFX_PATH,icon_pic.picture_filename); + sprintf(icon_filename, "%s/%s/%s", + options.base_directory, GRAPHICS_DIRECTORY, + icon_pic.picture_filename); XReadBitmapFile(display,window,icon_filename, &icon_width,&icon_height, &icon_pixmap,&icon_hot_x,&icon_hot_y); if (!icon_pixmap) Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename); - sprintf(icon_filename,"%s/%s",GFX_PATH,icon_pic.picturemask_filename); + sprintf(icon_filename, "%s/%s/%s", + options.base_directory, GRAPHICS_DIRECTORY, + icon_pic.picturemask_filename); XReadBitmapFile(display,window,icon_filename, &icon_width,&icon_height, &iconmask_pixmap,&icon_hot_x,&icon_hot_y); @@ -649,9 +652,10 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) /* Grafik laden */ if (pic->picture_filename) { - sprintf(basefilename,"%s%s",pic->picture_filename,picture_ext); - DrawInitText(basefilename,150,FC_YELLOW); - sprintf(filename,"%s/%s",GFX_PATH,basefilename); + sprintf(basefilename, "%s%s", pic->picture_filename, picture_ext); + DrawInitText(basefilename, 150, FC_YELLOW); + sprintf(filename, "%s/%s/%s", + options.base_directory, GRAPHICS_DIRECTORY, basefilename); #ifdef MSDOS rest(100); @@ -729,9 +733,10 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) #ifdef XPM_INCLUDE_FILE - sprintf(basefilename,"%s%s",pic->picture_filename,picturemask_ext); - DrawInitText(basefilename,150,FC_YELLOW); - sprintf(filename,"%s/%s",GFX_PATH,basefilename); + sprintf(basefilename, "%s%s", pic->picture_filename, picturemask_ext); + DrawInitText(basefilename, 150, FC_YELLOW); + sprintf(filename, "%s/%s/%s", + options.base_directory, GRAPHICS_DIRECTORY, basefilename); #ifdef DEBUG_TIMING count1 = Counter(); diff --git a/src/main.c b/src/main.c index 8cd26a11..be179b53 100644 --- a/src/main.c +++ b/src/main.c @@ -50,7 +50,6 @@ char *joystick_device_name[MAX_PLAYERS] = DEV_JOYSTICK_3 }; -char *level_directory = LEVEL_PATH; int width, height; char *program_name = NULL; diff --git a/src/main.h b/src/main.h index d63a289f..d698ffdf 100644 --- a/src/main.h +++ b/src/main.h @@ -195,7 +195,7 @@ typedef unsigned char byte; #define MAX_LEVDIR_FILENAME (64+1) #define MAX_LEVDIR_NAME (16+1) #define MAX_LEVDIR_ENTRIES 15 -#define MAX_SCORE_ENTRIES 15 +#define MAX_SCORE_ENTRIES 100 #define MAX_OPTION_LEN 256 #define MAX_FILENAME_LEN 256 @@ -213,6 +213,8 @@ struct OptionInfo char *display_name; char *server_host; int server_port; + char *base_directory; + char *level_directory; boolean serveronly; boolean network; boolean verbose; @@ -379,7 +381,6 @@ extern int sound_device; extern char *sound_device_name; extern int joystick_device; extern char *joystick_device_name[]; -extern char *level_directory; extern int width, height; extern char *program_name; @@ -1068,58 +1069,34 @@ extern int num_bg_loops; #define EMU_BOULDERDASH 1 #define EMU_SOKOBAN 2 - #ifndef GAME_DIR #define GAME_DIR "." #endif -#ifndef GFX_PATH -#define GFX_PATH GAME_DIR "/graphics" -#endif -#ifndef SND_PATH -#define SND_PATH GAME_DIR "/sounds" -#endif -#ifndef LEVEL_PATH -#define LEVEL_PATH GAME_DIR "/levels" -#endif -#ifndef SCORE_PATH -#define SCORE_PATH LEVEL_PATH -#endif -#ifndef NAMES_PATH -#define NAMES_PATH LEVEL_PATH -#endif -#ifndef CONFIG_PATH -#define CONFIG_PATH GAME_DIR -#endif -#ifndef JOYDAT_PATH -#define JOYDAT_PATH GAME_DIR -#endif -#ifndef SETUP_PATH -#define SETUP_PATH GAME_DIR -#endif +#define BASE_PATH GAME_DIR + +#define GRAPHICS_DIRECTORY "graphics" +#define SOUNDS_DIRECTORY "sounds" +#define LEVELS_DIRECTORY "levels" +#define TAPES_DIRECTORY "tapes" +#define SCORES_DIRECTORY "scores" #ifndef MSDOS #define USERDATA_DIRECTORY ".rocksndiamonds" -#define TAPEDATA_DIRECTORY "tapes" -#define SCORE_FILENAME "ROCKS.score" #define LEVDIR_FILENAME "ROCKS.levelinfo" -#define JOYDAT_FILENAME "ROCKS.joystick" #define SETUP_FILENAME "setup" #define LEVELSETUP_FILENAME "setup.level" #define TAPEFILE_EXTENSION "tape" +#define SCOREFILE_EXTENSION "score" #else #define USERDATA_DIRECTORY "userdata" -#define TAPEDATA_DIRECTORY "tapes" -#define SCORE_FILENAME "ROCKS.sco" #define LEVDIR_FILENAME "ROCKS.lev" -#define JOYDAT_FILENAME "ROCKS.joy" #define SETUP_FILENAME "setup" #define LEVELSETUP_FILENAME "setup.lev" #define TAPEFILE_EXTENSION "rec" +#define SCOREFILE_EXTENSION "sco" #endif -#define JOYDAT_FILE JOYDAT_PATH "/" JOYDAT_FILENAME - #define MODE_R_ALL (S_IRUSR | S_IRGRP | S_IROTH) #define MODE_W_ALL (S_IWUSR | S_IWGRP | S_IWOTH) #define MODE_X_ALL (S_IXUSR | S_IXGRP | S_IXOTH) @@ -1133,12 +1110,10 @@ extern int num_bg_loops; #define SETUP_PERMS LEVEL_PERMS /* old cookies */ -#define NAMES_COOKIE_10 "ROCKSNDIAMONDS_NAMES_FILE_VERSION_1.0" #define LEVELREC_COOKIE_10 "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.0" #define LEVEL_COOKIE "ROCKSNDIAMONDS_LEVEL_FILE_VERSION_1.0" -#define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.0" -#define NAMES_COOKIE "ROCKSNDIAMONDS_NAMES_FILE_VERSION_1.1" +#define SCORE_COOKIE "ROCKSNDIAMONDS_SCORE_FILE_VERSION_1.2" #define LEVELDIR_COOKIE "ROCKSNDIAMONDS_LEVELDIR_FILE_VERSION_1.0" #define LEVELREC_COOKIE "ROCKSNDIAMONDS_LEVELREC_FILE_VERSION_1.2" #define JOYSTICK_COOKIE "ROCKSNDIAMONDS_JOYSTICK_FILE_VERSION_1.0" @@ -1146,7 +1121,6 @@ extern int num_bg_loops; #define LEVELSETUP_COOKIE "ROCKSNDIAMONDS_LEVELSETUP_FILE_VERSION_1.2" #define LEVEL_COOKIE_LEN (strlen(LEVEL_COOKIE)+1) #define SCORE_COOKIE_LEN (strlen(SCORE_COOKIE)+1) -#define NAMES_COOKIE_LEN (strlen(NAMES_COOKIE)+1) #define LEVELDIR_COOKIE_LEN (strlen(LEVELDIR_COOKIE)+1) #define LEVELREC_COOKIE_LEN (strlen(LEVELREC_COOKIE)+1) #define JOYSTICK_COOKIE_LEN (strlen(JOYSTICK_COOKIE)+1) diff --git a/src/misc.c b/src/misc.c index 7d0a7fde..c560ae4b 100644 --- a/src/misc.c +++ b/src/misc.c @@ -230,6 +230,8 @@ void GetOptions(char *argv[]) options.display_name = NULL; options.server_host = NULL; options.server_port = 0; + options.base_directory = BASE_PATH; + options.level_directory = BASE_PATH "/" LEVELS_DIRECTORY; options.serveronly = FALSE; options.network = FALSE; options.verbose = FALSE; @@ -273,6 +275,7 @@ void GetOptions(char *argv[]) printf("Usage: %s [options] [server.name [port]]\n" "Options:\n" " -d, --display machine:0 X server display\n" + " -b, --basepath directory alternative base directory\n" " -l, --levels directory alternative level directory\n" " -s, --serveronly only start network server\n" " -n, --network network multiplayer game\n" @@ -291,16 +294,33 @@ void GetOptions(char *argv[]) printf("--display == '%s'\n", options.display_name); } + else if (strncmp(option, "-basepath", option_len) == 0) + { + if (option_arg == NULL) + Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); + + options.base_directory = option_arg; + if (option_arg == next_option) + options_left++; + + printf("--basepath == '%s'\n", options.base_directory); + + /* adjust path for level directory accordingly */ + options.level_directory = checked_malloc(strlen(options.base_directory) + + strlen(LEVELS_DIRECTORY) + 2); + sprintf(options.level_directory, "%s/%s", + options.base_directory, LEVELS_DIRECTORY); + } else if (strncmp(option, "-levels", option_len) == 0) { if (option_arg == NULL) Error(ERR_EXIT_HELP, "option '%s' requires an argument", option_str); - level_directory = option_arg; + options.level_directory = option_arg; if (option_arg == next_option) options_left++; - printf("--levels == '%s'\n", level_directory); + printf("--levels == '%s'\n", options.level_directory); } else if (strncmp(option, "-network", option_len) == 0) { diff --git a/src/msdos.h b/src/msdos.h index b09c4ce4..f4f7a5ad 100644 --- a/src/msdos.h +++ b/src/msdos.h @@ -24,7 +24,13 @@ #include #include -// Allegro keyboard mapping +/* some file path definitions */ + +#define JOYDAT_PATH GAME_DIR +#define JOYDAT_FILENAME "ROCKS.joy" +#define JOYDAT_FILE JOYDAT_PATH "/" JOYDAT_FILENAME + +/* Allegro keyboard mapping */ #define OSD_KEY_ESC 1 /* keyboard scan codes */ #define OSD_KEY_1 2 /* (courtesy of allegro.h) */ @@ -136,7 +142,7 @@ #define OSD_MAX_KEY 115 -// X11 keyboard mapping +/* X11 keyboard mapping */ #define XK_KP_Enter OSD_KEY_ENTER_PAD #define XK_KP_0 OSD_KEY_0_PAD @@ -439,33 +445,33 @@ typedef union _XEvent { extern void XMapWindow(Display*, Window); -//extern void XFlush(Display*); +// extern void XFlush(Display*); extern Display *XOpenDisplay(char*); -//extern char *XDisplayName(char*); +// extern char *XDisplayName(char*); extern Window XCreateSimpleWindow(Display*, Window, int, int, unsigned int, unsigned int, unsigned int, unsigned long, unsigned long); extern int XReadBitmapFile(Display*, Drawable, char*, unsigned int*, unsigned int*, Pixmap*, int*, int*); extern Status XStringListToTextProperty(char**, int, XTextProperty*); -//extern void XSetWMProperties(Display*, Window, XTextProperty*, XTextProperty*, char**, int, XSizeHints*, XWMHints*, XClassHint*); +// extern void XSetWMProperties(Display*, Window, XTextProperty*, XTextProperty*, char**, int, XSizeHints*, XWMHints*, XClassHint*); extern void XFree(void*); -//extern void XSelectInput(Display*, Window, long); +// extern void XSelectInput(Display*, Window, long); extern GC XCreateGC(Display*, Drawable, unsigned long, XGCValues*); extern void XFillRectangle(Display*, Drawable, GC, int, int, unsigned int, unsigned int); extern Pixmap XCreatePixmap(Display*, Drawable, unsigned int, unsigned int, unsigned int); -//extern int XDefaultDepth(Display*, int); +// extern int XDefaultDepth(Display*, int); extern inline void XCopyArea(Display*, Drawable, Drawable, GC, int, int, unsigned int, unsigned int, int, int); extern int XpmReadFileToPixmap(Display*, Drawable, char*, Pixmap*, Pixmap*, XpmAttributes*); -//extern void XFreeColors(Display*, Colormap, unsigned long*, int, unsigned long); -//extern void XpmFreeAttributes(XpmAttributes*); +// extern void XFreeColors(Display*, Colormap, unsigned long*, int, unsigned long); +// extern void XpmFreeAttributes(XpmAttributes*); extern void XFreePixmap(Display*, Pixmap); extern void XFreeGC(Display*, GC); extern void XCloseDisplay(Display*); extern int XPending(Display*); extern void XNextEvent(Display*, XEvent*); -//extern void XSync(Display*, Bool); -//extern void XAutoRepeatOn(Display*); -//extern void XAutoRepeatOff(Display*); +// extern void XSync(Display*, Bool); +// extern void XAutoRepeatOn(Display*); +// extern void XAutoRepeatOff(Display*); extern KeySym XLookupKeysym(XKeyEvent*, int); -//extern void XSetClipOrigin(Display*, GC, int, int); -//extern XImage *XGetImage(Display*, Drawable, int, int, unsigned int, unsigned int, unsigned long, int); +// extern void XSetClipOrigin(Display*, GC, int, int); +// extern XImage *XGetImage(Display*, Drawable, int, int, unsigned int, unsigned int, unsigned long, int); BITMAP *load_gif(char *filename, RGB *pal); diff --git a/src/network.c b/src/network.c index 65d18691..890f405f 100644 --- a/src/network.c +++ b/src/network.c @@ -500,7 +500,7 @@ static void Handle_OP_START_PLAYING() level_nr = new_level_nr; TapeErase(); - LoadLevelTape(level_nr); + LoadTape(level_nr); /* GetPlayerConfig(); diff --git a/src/screens.c b/src/screens.c index a0a06dbc..139c6d9c 100644 --- a/src/screens.c +++ b/src/screens.c @@ -89,7 +89,7 @@ void DrawMainMenu() TapeStop(); if (TAPE_IS_EMPTY(tape)) - LoadLevelTape(level_nr); + LoadTape(level_nr); DrawCompleteVideoDisplay(); OpenDoor(DOOR_CLOSE_1 | DOOR_OPEN_2); @@ -168,7 +168,7 @@ void HandleMainMenu(int mx, int my, int dx, int dy, int button) DrawMicroLevel(MICROLEV_XPOS,MICROLEV_YPOS); TapeErase(); - LoadLevelTape(level_nr); + LoadTape(level_nr); DrawCompleteVideoDisplay(); /* needed because DrawMicroLevel() takes some time */ @@ -822,7 +822,7 @@ void HandleChooseLevel(int mx, int my, int dx, int dy, int button) SaveLevelSetup(); TapeErase(); - LoadLevelTape(level_nr); + LoadTape(level_nr); game_status = MAINMENU; DrawMainMenu(); @@ -849,7 +849,7 @@ void DrawHallOfFame(int pos) DrawText(SX+64,SY+10,"Hall Of Fame",FS_BIG,FC_YELLOW); sprintf(txt,"HighScores of Level %d",level_nr); DrawText(SX+256-strlen(txt)*7,SY+48,txt,FS_SMALL,FC_RED); - for(y=0;yname,sound_ext); + sprintf(filename, "%s/%s/%s.%s", + options.base_directory, SOUNDS_DIRECTORY, snd_info->name, sound_ext); #ifndef MSDOS if (!(file=fopen(filename,"r")))