X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Flibgame%2Fmisc.c;h=5814e8d17f9e42464e69c39f77fe6b67c58cb5f5;hb=ff56a43aa3799aa3357f4deca4d6482fc25a6a41;hp=bfc6d454d9652253e9766676960913783c469a9c;hpb=da14f69fd95c7bd5a0d70cdf4935af06f1f20a04;p=rocksndiamonds.git diff --git a/src/libgame/misc.c b/src/libgame/misc.c index bfc6d454..5814e8d1 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -1,34 +1,35 @@ /*********************************************************** -* Rocks'n'Diamonds -- McDuffin Strikes Back! * +* Artsoft Retro-Game Library * *----------------------------------------------------------* -* (c) 1995-98 Artsoft Entertainment * -* Holger Schemel * -* Oststrasse 11a * -* 33604 Bielefeld * -* phone: ++49 +521 290471 * -* email: aeglos@valinor.owl.de * +* (c) 1994-2000 Artsoft Entertainment * +* Holger Schemel * +* Detmolder Strasse 189 * +* 33604 Bielefeld * +* Germany * +* e-mail: info@artsoft.org * *----------------------------------------------------------* -* misc.c * +* misc.c * ***********************************************************/ #include #include #include +#include #include #include +#include +#include + +#include "platform.h" #if !defined(PLATFORM_WIN32) #include #include #endif -#include "libgame.h" - -#include "main_TMP.h" - #include "misc.h" +#include "random.h" -#include "joystick_TMP.h" #if defined(PLATFORM_MSDOS) volatile unsigned long counter = 0; @@ -413,37 +414,6 @@ char *getStringToLower(char *s) return s_copy; } -void MarkTileDirty(int x, int y) -{ - int xx = redraw_x1 + x; - int yy = redraw_y1 + y; - - if (!redraw[xx][yy]) - redraw_tiles++; - - redraw[xx][yy] = TRUE; - redraw_mask |= REDRAW_TILES; -} - -void SetBorderElement() -{ - int x, y; - - BorderElement = EL_LEERRAUM; - - for(y=0; y= '0' && c <= '9') - joystick_nr = (int)(c - '0'); - - if (joystick_nr < 0 || joystick_nr >= MAX_PLAYERS) - joystick_nr = 0; - - return joystick_nr; -} - /* ------------------------------------------------------------------------- */ /* some functions to handle lists of level directories */ /* ------------------------------------------------------------------------- */ @@ -1367,9 +1248,101 @@ inline void swap_number_pairs(int *x1, int *y1, int *x2, int *y2) } -/* ------------------------------------------------------------------------- */ +/* ========================================================================= */ +/* some stuff from "files.c" */ +/* ========================================================================= */ + +#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) +#define USERDATA_DIR_MODE (MODE_R_ALL | MODE_X_ALL | S_IWUSR) + +char *getUserDataDir(void) +{ + static char *userdata_dir = NULL; + + if (!userdata_dir) + { + char *home_dir = getHomeDir(); + char *data_dir = program.userdata_directory; + + userdata_dir = getPath2(home_dir, data_dir); + } + + return userdata_dir; +} + +void createDirectory(char *dir, char *text) +{ + if (access(dir, F_OK) != 0) +#if defined(PLATFORM_WIN32) + if (mkdir(dir) != 0) +#else + if (mkdir(dir, USERDATA_DIR_MODE) != 0) +#endif + Error(ERR_WARN, "cannot create %s directory '%s'", text, dir); +} + +void InitUserDataDirectory() +{ + createDirectory(getUserDataDir(), "user data"); +} + + +/* ========================================================================= */ +/* functions only needed for non-Unix (non-command-line) systems */ +/* ========================================================================= */ + +#if !defined(PLATFORM_UNIX) + +#define ERROR_FILENAME "error.out" + +void initErrorFile() +{ + char *filename; + + InitUserDataDirectory(); + + filename = getPath2(getUserDataDir(), ERROR_FILENAME); + unlink(filename); + free(filename); +} + +FILE *openErrorFile() +{ + char *filename; + FILE *error_file; + + filename = getPath2(getUserDataDir(), ERROR_FILENAME); + error_file = fopen(filename, "a"); + free(filename); + + return error_file; +} + +void dumpErrorFile() +{ + char *filename; + FILE *error_file; + + filename = getPath2(getUserDataDir(), ERROR_FILENAME); + error_file = fopen(filename, "r"); + free(filename); + + if (error_file != NULL) + { + while (!feof(error_file)) + fputc(fgetc(error_file), stderr); + + fclose(error_file); + } +} +#endif + + +/* ========================================================================= */ /* the following is only for debugging purpose and normally not used */ -/* ------------------------------------------------------------------------- */ +/* ========================================================================= */ #define DEBUG_NUM_TIMESTAMPS 3