From e557b2b5d9951a4e692fd4e32a5cf45c84252c64 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Sat, 3 Oct 1998 00:34:36 +0200 Subject: [PATCH] rnd-19981003-1 --- src/editor.c | 6 +- src/events.c | 2 +- src/files.c | 40 +++++------ src/game.c | 91 ++++++++++++++++++++----- src/init.c | 67 +++++++----------- src/init.h | 2 +- src/joystick.c | 10 --- src/main.c | 164 ++------------------------------------------ src/main.h | 24 +++++-- src/misc.c | 182 ++++++++++++++++++++++++++++++++++++++----------- src/misc.h | 4 +- src/tools.c | 32 ++++++--- src/tools.h | 1 + 13 files changed, 312 insertions(+), 313 deletions(-) diff --git a/src/editor.c b/src/editor.c index 3434b4c2..fc81ebe0 100644 --- a/src/editor.c +++ b/src/editor.c @@ -206,9 +206,9 @@ int editor_element[] = EL_DRACHE, EL_SONDE, - EL_LEERRAUM, - EL_LEERRAUM, - EL_LEERRAUM, + EL_MAUER_X, + EL_MAUER_Y, + EL_MAUER_XY, EL_CHAR_A + ('S' - 'A'), EL_CHAR_A + ('O' - 'A'), diff --git a/src/events.c b/src/events.c index 505e7457..f3a720de 100644 --- a/src/events.c +++ b/src/events.c @@ -245,7 +245,7 @@ void HandleClientMessageEvent(XClientMessageEvent *event) { if ((event->window == window) && (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE))) - CloseAll(); + game_status = EXITGAME; } void HandleButton(int mx, int my, int button) diff --git a/src/files.c b/src/files.c index 9030319d..41fe210b 100644 --- a/src/files.c +++ b/src/files.c @@ -20,7 +20,7 @@ BOOL CreateNewScoreFile() { int i,j,k; - char filename[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; char empty_alias[MAX_NAMELEN]; FILE *file; @@ -53,7 +53,7 @@ BOOL CreateNewScoreFile() BOOL CreateNewNamesFile(int mode) { - char filename[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; FILE *file; if (mode==PLAYER_LEVEL) @@ -75,8 +75,8 @@ BOOL CreateNewNamesFile(int mode) BOOL LoadLevelInfo() { int i; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; sprintf(filename,"%s/%s",level_directory,LEVDIR_FILENAME); @@ -121,19 +121,15 @@ BOOL LoadLevelInfo() void LoadLevel(int level_nr) { int i,x,y; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; sprintf(filename,"%s/%s/%d", level_directory,leveldir[leveldir_nr].filename,level_nr); if (!(file = fopen(filename,"r"))) - { -/* - Error(ERR_RETURN, "cannot load level '%s'", filename); -*/ - } + Error(ERR_RETURN, "cannot load level '%s' - creating new level", filename); else { fgets(cookie,LEVEL_COOKIE_LEN,file); @@ -215,8 +211,8 @@ void LoadLevel(int level_nr) void LoadLevelTape(int level_nr) { int i; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; BOOL levelrec_10 = FALSE; @@ -294,8 +290,8 @@ void LoadLevelTape(int level_nr) void LoadScore(int level_nr) { int i,j; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; sprintf(filename,"%s/%s/%s", @@ -346,8 +342,8 @@ void LoadScore(int level_nr) void LoadPlayerInfo(int mode) { int i; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; char *login_name = GetLoginName(); struct PlayerInfo default_player, new_player; @@ -469,7 +465,7 @@ void LoadPlayerInfo(int mode) void SaveLevel(int level_nr) { int i,x,y; - char filename[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; FILE *file; sprintf(filename,"%s/%s/%d", @@ -519,7 +515,7 @@ void SaveLevel(int level_nr) void SaveLevelTape(int level_nr) { int i; - char filename[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; FILE *file; BOOL new_tape = TRUE; @@ -588,7 +584,7 @@ void SaveLevelTape(int level_nr) void SaveScore(int level_nr) { int i,j; - char filename[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; FILE *file; sprintf(filename,"%s/%s/%s", @@ -616,8 +612,8 @@ void SaveScore(int level_nr) void SavePlayerInfo(int mode) { int i; - char filename[MAX_FILENAME]; - char cookie[MAX_FILENAME]; + char filename[MAX_FILENAME_LEN]; + char cookie[MAX_FILENAME_LEN]; FILE *file; struct PlayerInfo default_player; int version_10_file = FALSE; diff --git a/src/game.c b/src/game.c index e339e9d3..67db98a9 100644 --- a/src/game.c +++ b/src/game.c @@ -2592,23 +2592,37 @@ void MauerWaechst(int x, int y) phase = 2-MovDelay[x][y]/delay; if (!(MovDelay[x][y]%delay) && IN_SCR_FIELD(SCREENX(x),SCREENY(y))) DrawGraphic(SCREENX(x),SCREENY(y), - (Store[x][y]==MV_LEFT ? GFX_MAUER_L1 : GFX_MAUER_R1)+phase); + (MovDir[x][y] == MV_LEFT ? GFX_MAUER_LEFT : + MovDir[x][y] == MV_RIGHT ? GFX_MAUER_RIGHT : + MovDir[x][y] == MV_UP ? GFX_MAUER_UP : + GFX_MAUER_DOWN ) + phase); if (!MovDelay[x][y]) { - if (Store[x][y]==MV_LEFT) + if (MovDir[x][y] == MV_LEFT) { if (IN_LEV_FIELD(x-1,y) && IS_MAUER(Feld[x-1][y])) DrawLevelField(x-1,y); } - else + else if (MovDir[x][y] == MV_RIGHT) { if (IN_LEV_FIELD(x+1,y) && IS_MAUER(Feld[x+1][y])) DrawLevelField(x+1,y); } + else if (MovDir[x][y] == MV_UP) + { + if (IN_LEV_FIELD(x,y-1) && IS_MAUER(Feld[x][y-1])) + DrawLevelField(x,y-1); + } + else + { + if (IN_LEV_FIELD(x,y+1) && IS_MAUER(Feld[x][y+1])) + DrawLevelField(x,y+1); + } - Feld[x][y] = EL_MAUER_LEBT; + Feld[x][y] = Store[x][y]; Store[x][y] = 0; + MovDir[x][y] = MV_NO_MOVING; DrawLevelField(x,y); } } @@ -2616,7 +2630,10 @@ void MauerWaechst(int x, int y) void MauerAbleger(int ax, int ay) { + int element = Feld[ax][ay]; + BOOL oben_frei = FALSE, unten_frei = FALSE; BOOL links_frei = FALSE, rechts_frei = FALSE; + BOOL oben_massiv = FALSE, unten_massiv = FALSE; BOOL links_massiv = FALSE, rechts_massiv = FALSE; if (!MovDelay[ax][ay]) /* neue Mauer / noch nicht gewartet */ @@ -2629,35 +2646,72 @@ void MauerAbleger(int ax, int ay) return; } + if (IN_LEV_FIELD(ax,ay-1) && IS_FREE(ax,ay-1)) + oben_frei = TRUE; + if (IN_LEV_FIELD(ax,ay+1) && IS_FREE(ax,ay+1)) + unten_frei = TRUE; if (IN_LEV_FIELD(ax-1,ay) && IS_FREE(ax-1,ay)) links_frei = TRUE; if (IN_LEV_FIELD(ax+1,ay) && IS_FREE(ax+1,ay)) rechts_frei = TRUE; - if (links_frei) + if (element == EL_MAUER_Y || element == EL_MAUER_XY) { - Feld[ax-1][ay] = EL_MAUERND; - Store[ax-1][ay] = MV_LEFT; - if (IN_SCR_FIELD(SCREENX(ax-1),SCREENY(ay))) - DrawGraphic(SCREENX(ax-1),SCREENY(ay),GFX_MAUER_L1); + if (oben_frei) + { + Feld[ax][ay-1] = EL_MAUERND; + Store[ax][ay-1] = element; + MovDir[ax][ay-1] = MV_UP; + if (IN_SCR_FIELD(SCREENX(ax),SCREENY(ay-1))) + DrawGraphic(SCREENX(ax),SCREENY(ay-1),GFX_MAUER_UP); + } + if (unten_frei) + { + Feld[ax][ay+1] = EL_MAUERND; + Store[ax][ay+1] = element; + MovDir[ax][ay+1] = MV_DOWN; + if (IN_SCR_FIELD(SCREENX(ax),SCREENY(ay+1))) + DrawGraphic(SCREENX(ax),SCREENY(ay+1),GFX_MAUER_DOWN); + } } - if (rechts_frei) + + if (element == EL_MAUER_X || element == EL_MAUER_XY || + element == EL_MAUER_LEBT) { - Feld[ax+1][ay] = EL_MAUERND; - Store[ax+1][ay] = MV_RIGHT; - if (IN_SCR_FIELD(SCREENX(ax+1),SCREENY(ay))) - DrawGraphic(SCREENX(ax+1),SCREENY(ay),GFX_MAUER_R1); + if (links_frei) + { + Feld[ax-1][ay] = EL_MAUERND; + Store[ax-1][ay] = element; + MovDir[ax-1][ay] = MV_LEFT; + if (IN_SCR_FIELD(SCREENX(ax-1),SCREENY(ay))) + DrawGraphic(SCREENX(ax-1),SCREENY(ay),GFX_MAUER_LEFT); + } + if (rechts_frei) + { + Feld[ax+1][ay] = EL_MAUERND; + Store[ax+1][ay] = element; + MovDir[ax+1][ay] = MV_RIGHT; + if (IN_SCR_FIELD(SCREENX(ax+1),SCREENY(ay))) + DrawGraphic(SCREENX(ax+1),SCREENY(ay),GFX_MAUER_RIGHT); + } } - if (links_frei || rechts_frei) + if (element == EL_MAUER_LEBT && (links_frei || rechts_frei)) DrawLevelField(ax,ay); + if (!IN_LEV_FIELD(ax,ay-1) || IS_MAUER(Feld[ax][ay-1])) + oben_massiv = TRUE; + if (!IN_LEV_FIELD(ax,ay+1) || IS_MAUER(Feld[ax][ay+1])) + unten_massiv = TRUE; if (!IN_LEV_FIELD(ax-1,ay) || IS_MAUER(Feld[ax-1][ay])) links_massiv = TRUE; if (!IN_LEV_FIELD(ax+1,ay) || IS_MAUER(Feld[ax+1][ay])) rechts_massiv = TRUE; - if (links_massiv && rechts_massiv) + if (((oben_massiv && unten_massiv) || + element == EL_MAUER_X || element == EL_MAUER_LEBT) && + ((links_massiv && rechts_massiv) || + element == EL_MAUER_Y)) Feld[ax][ay] = EL_MAUERWERK; } @@ -2914,7 +2968,10 @@ void GameActions(int player_action) AusgangstuerBlinken(x,y); else if (element==EL_MAUERND) MauerWaechst(x,y); - else if (element==EL_MAUER_LEBT) + else if (element==EL_MAUER_LEBT || + element==EL_MAUER_X || + element==EL_MAUER_Y || + element==EL_MAUER_XY) MauerAbleger(x,y); else if (element==EL_BURNING) CheckForDragon(x,y); diff --git a/src/init.c b/src/init.c index 7a6057a7..d466c7e5 100644 --- a/src/init.c +++ b/src/init.c @@ -65,8 +65,8 @@ void OpenAll(int argc, char *argv[]) InitJoystick(); InitRND(NEW_RANDOMIZE); - signal(SIGINT, CloseAll); - signal(SIGTERM, CloseAll); + signal(SIGINT, CloseAllAndExit); + signal(SIGTERM, CloseAllAndExit); InitDisplay(); InitWindow(argc, argv); @@ -85,7 +85,7 @@ void InitLevelAndPlayerInfo() local_player = &stored_player[0]; if (!LoadLevelInfo()) /* global level info */ - CloseAll(); + Error(ERR_EXIT, NULL); LoadPlayerInfo(PLAYER_SETUP); /* global setup info */ LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */ @@ -438,6 +438,7 @@ void InitGfx() { GFX_GEBLUBBER, 4 }, { GFX_DYNAMIT, 7 }, { GFX_DYNABOMB, 4 }, + { GFX_EXPLOSION, 8 }, { GFX_SOKOBAN_OBJEKT, 1 }, { GFX_FUNKELN_BLAU, 3 }, { GFX_FUNKELN_WEISS, 3 }, @@ -615,21 +616,13 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) switch(xpm_err) { case XpmOpenFailed: - fprintf(stderr,"Cannot open Xpm file '%s' !\n",filename); - CloseAll(); - exit(-1); + Error(ERR_EXIT, "cannot open XPM file '%s'", filename); case XpmFileInvalid: - fprintf(stderr,"Invalid Xpm file '%s'!\n",filename); - CloseAll(); - exit(-1); + Error(ERR_EXIT, "invalid XPM file '%s'", filename); case XpmNoMemory: - fprintf(stderr,"Not enough memory for Xpm file '%s'!\n",filename); - CloseAll(); - exit(1); + Error(ERR_EXIT, "not enough memory for XPM file '%s'", filename); case XpmColorFailed: - fprintf(stderr,"Can't get colors for Xpm file '%s'!\n",filename); - CloseAll(); - exit(-1); + Error(ERR_EXIT, "cannot get colors for XPM file '%s'", filename); default: break; } @@ -650,25 +643,15 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) case GIF_Success: break; case GIF_OpenFailed: - fprintf(stderr,"Cannot open GIF file '%s' !\n",filename); - CloseAll(); - exit(-1); + Error(ERR_EXIT, "cannot open GIF file '%s'", filename); case GIF_ReadFailed: - fprintf(stderr,"Cannot read GIF file '%s' !\n",filename); - CloseAll(); - exit(-1); + Error(ERR_EXIT, "cannot read GIF file '%s'", filename); case GIF_FileInvalid: - fprintf(stderr,"Invalid GIF file '%s'!\n",filename); - CloseAll(); - exit(-1); + Error(ERR_EXIT, "invalid GIF file '%s'", filename); case GIF_NoMemory: - fprintf(stderr,"Not enough memory for GIF file '%s'!\n",filename); - CloseAll(); - exit(1); + Error(ERR_EXIT, "not enough memory for GIF file '%s'", filename); case GIF_ColorFailed: - fprintf(stderr,"Can't get colors for GIF file '%s'!\n",filename); - CloseAll(); - exit(-1); + Error(ERR_EXIT, "cannot get colors for GIF file '%s'", filename); default: break; } @@ -707,19 +690,11 @@ void LoadGfx(int pos, struct PictureFileInfo *pic) case BitmapSuccess: break; case BitmapOpenFailed: - fprintf(stderr,"Bitmap file open failed on '%s' !\n",filename); - CloseAll(); - exit(-1); - break; + Error(ERR_EXIT, "cannot open XBM file '%s'", filename); case BitmapFileInvalid: - fprintf(stderr,"Bitmap file invalid: '%s' !\n",filename); - CloseAll(); - exit(-1); - break; + Error(ERR_EXIT, "invalid XBM file '%s'", filename); case BitmapNoMemory: - fprintf(stderr,"No memory for file '%s' !\n",filename); - CloseAll(); - exit(-1); + Error(ERR_EXIT, "not enough memory for XBM file '%s'", filename); break; default: break; @@ -788,6 +763,9 @@ void InitElementProperties() EL_BETON, EL_MAUERWERK, EL_MAUER_LEBT, + EL_MAUER_X, + EL_MAUER_Y, + EL_MAUER_XY, EL_FELSBODEN, EL_AUSGANG_ZU, EL_AUSGANG_ACT, @@ -889,6 +867,9 @@ void InitElementProperties() EL_MAUERWERK, EL_FELSBODEN, EL_MAUER_LEBT, + EL_MAUER_X, + EL_MAUER_Y, + EL_MAUER_XY, EL_MAUERND }; static int ep_mauer_num = sizeof(ep_mauer)/sizeof(int); @@ -1286,7 +1267,7 @@ void InitElementProperties() Elementeigenschaften[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE); } -void CloseAll() +void CloseAllAndExit(int exit_value) { int i; @@ -1326,5 +1307,5 @@ void CloseAll() XCloseDisplay(display); } - exit(0); + exit(exit_value); } diff --git a/src/init.h b/src/init.h index 2c435418..d2b052b7 100644 --- a/src/init.h +++ b/src/init.h @@ -17,7 +17,7 @@ #include "main.h" void OpenAll(int, char **); -void CloseAll(); +void CloseAllAndExit(int); void InitJoystick(void); #endif diff --git a/src/joystick.c b/src/joystick.c index 8392a8a1..86fabec7 100644 --- a/src/joystick.c +++ b/src/joystick.c @@ -18,16 +18,6 @@ #include "joystick.h" #include "misc.h" -/* -#include "tools.h" -#include "game.h" -#include "events.h" -#include "sound.h" -#include "misc.h" -#include "buttons.h" -#include -*/ - void CheckJoystickData() { int i; diff --git a/src/main.c b/src/main.c index 66f85d38..03d7e66e 100644 --- a/src/main.c +++ b/src/main.c @@ -46,6 +46,7 @@ char *joystick_device_name[2] = { DEV_JOYSTICK_0, DEV_JOYSTICK_1 }; char *level_directory = LEVEL_PATH; int width, height; +char *program_name = NULL; char *display_name = NULL; char *server_host = NULL; int server_port = 0; @@ -193,174 +194,17 @@ int background_loop[] = }; int num_bg_loops = sizeof(background_loop)/sizeof(int); -char *program_name; - -#define MAX_OPTION_LEN 1024 - -static void fatal_option() -{ - fprintf(stderr,"Try '%s --help' for more information.\n", - program_name); - exit(1); -} - -static void fatal_unrecognized_option(char *option) -{ - fprintf(stderr,"%s: unrecognized option '%s'\n", - program_name, option); - fatal_option(); -} - -static void fatal_option_requires_argument(char *option) -{ - fprintf(stderr,"%s: option '%s' requires an argument\n", - program_name, option); - fatal_option(); -} - -static void fatal_invalid_option_argument(char *option) -{ - fprintf(stderr,"%s: option '%s' has invalid argument\n", - program_name, option); - fatal_option(); -} - -static void fatal_too_many_arguments() -{ - fprintf(stderr,"%s: too many arguments\n", - program_name); - fatal_option(); -} - -extern void fatal(char *); - int main(int argc, char *argv[]) { - char **options_left = &argv[1]; - program_name = (strrchr(argv[0],'/') ? strrchr(argv[0],'/') + 1 : argv[0]); - while (*options_left) - { - char option_str[MAX_OPTION_LEN]; - char *option = options_left[0]; - char *next_option = options_left[1]; - char *option_arg = NULL; - int option_len = strlen(option); - - strcpy(option_str, option); /* copy argument into buffer */ - option = option_str; - - if (strcmp(option, "--") == 0) /* stop scanning arguments */ - break; - - if (option_len >= MAX_OPTION_LEN) - fatal_unrecognized_option(option); - - if (strncmp(option, "--", 2) == 0) /* treat '--' like '-' */ - option++; - - option_arg = strchr(option, '='); - if (option_arg == NULL) /* no '=' in option */ - option_arg = next_option; - else - { - *option_arg++ = '\0'; /* cut argument from option */ - if (*option_arg == '\0') /* no argument after '=' */ - fatal_invalid_option_argument(option); - } - - option_len = strlen(option); - - if (strcmp(option, "-") == 0) - fatal_unrecognized_option(option); - else if (strncmp(option, "-help", option_len) == 0) - { - printf("Usage: %s [options] [server.name [port]]\n" - "Options:\n" - " -d, --display machine:0 X server display\n" - " -l, --levels directory alternative level directory\n" - " -v, --verbose verbose mode\n", - program_name); - exit(0); - } - else if (strncmp(option, "-display", option_len) == 0) - { - if (option_arg == NULL) - fatal_option_requires_argument(option_str); - - display_name = option_arg; - if (option_arg == next_option) - options_left++; - - printf("--display == '%s'\n", display_name); - } - else if (strncmp(option, "-levels", option_len) == 0) - { - if (option_arg == NULL) - fatal_option_requires_argument(option_str); - - level_directory = option_arg; - if (option_arg == next_option) - options_left++; - - printf("--levels == '%s'\n", level_directory); - } - else if (strncmp(option, "-verbose", option_len) == 0) - { - printf("--verbose\n"); - - verbose = TRUE; - } - else if (*option == '-') - fatal_unrecognized_option(option_str); - else if (server_host == NULL) - { - server_host = *options_left; - - printf("server.name == '%s'\n", server_host); - } - else if (server_port == 0) - { - server_port = atoi(*options_left); - if (server_port < 1024) - fatal("Bad port number"); - - printf("port == %d\n", server_port); - } - else - fatal_too_many_arguments(); - - options_left++; - } - - /* - printf("All went fine -- exiting\n"); - exit(0); - */ - - /* - if (argc>1) - level_directory = argv[1]; - */ - - - /* - if (argc > 1) - server_host = argv[1]; - - if (argc > 2) - server_port = atoi(argv[2]); - */ - - #ifdef MSDOS _fmode = O_BINARY; #endif + GetOptions(argv); OpenAll(argc,argv); EventLoop(); - CloseAll(); - - exit(0); + CloseAllAndExit(0); + exit(0); /* to keep compilers happy */ } diff --git a/src/main.h b/src/main.h index c8d1a717..0d3bfe5e 100644 --- a/src/main.h +++ b/src/main.h @@ -200,7 +200,8 @@ typedef int BOOL; #define MAX_LEVDIR_ENTRIES 15 #define MAX_SCORE_ENTRIES 15 -#define MAX_FILENAME 256 +#define MAX_OPTION_LEN 256 +#define MAX_FILENAME_LEN 256 #define MAX_NUM_AMOEBA 100 #define MAX_ELEMENTS 512 @@ -321,6 +322,7 @@ extern char *joystick_device_name[2]; extern char *level_directory; extern int width, height; +extern char *program_name; extern char *display_name; extern char *server_host; extern int server_port; @@ -393,8 +395,6 @@ extern char *sound_name[]; extern int background_loop[]; extern int num_bg_loops; -extern char *program_name; - /* often used screen positions */ #define SX 8 @@ -616,7 +616,11 @@ extern char *program_name; #define EL_CHAR_COPY (EL_CHAR_ASCII0+94) #define EL_CHAR_END (EL_CHAR_START+79) -#define EL_UNUSED_200 200 +#define EL_MAUER_X 200 +#define EL_MAUER_Y 201 +#define EL_MAUER_XY 202 + +#define EL_UNUSED_200 203 /* ... */ #define EL_UNUSED_255 255 @@ -756,15 +760,20 @@ extern char *program_name; #define GFX_MAULWURF 145 #define GFX_SCHWEIN 146 #define GFX_DRACHE 147 +#define GFX_MAUER_XY 148 +#define GFX_MAUER_X 149 +#define GFX_MAUER_Y 150 #define GFX_EDELSTEIN_ROT 152 #define GFX_EDELSTEIN_LILA 154 #define GFX_DYNABOMB_XL 156 #define GFX_SONDE 159 /* Zeile 10 (160) */ #define GFX_EDELSTEIN_BD 163 -#define GFX_MAUER_R1 165 +#define GFX_MAUER_RIGHT 165 +#define GFX_MAUER_R1 GFX_MAUER_RIGHT #define GFX_MAUER_R 167 -#define GFX_MAUER_L1 168 +#define GFX_MAUER_LEFT 168 +#define GFX_MAUER_L1 GFX_MAUER_LEFT #define GFX_MAUER_L 170 #define GFX_MAUER_LEBT 171 #define GFX_SIEB2_LEER 172 @@ -824,6 +833,9 @@ extern char *program_name; #define GFX_SPIELER4_RIGHT (GFX_START_ROCKSHEROES +10*HEROES_PER_LINE + 4) #define GFX_SPIELER4_PUSH_RIGHT (GFX_START_ROCKSHEROES +11*HEROES_PER_LINE + 0) #define GFX_SPIELER4_PUSH_LEFT (GFX_START_ROCKSHEROES +11*HEROES_PER_LINE + 4) +#define GFX_MAUER_DOWN (GFX_START_ROCKSHEROES +12*HEROES_PER_LINE + 0) +#define GFX_MAUER_UP (GFX_START_ROCKSHEROES +12*HEROES_PER_LINE + 3) + #define GFX_SONDE_START (GFX_START_ROCKSHEROES + 9*HEROES_PER_LINE + 8) #define GFX_SCHWEIN_DOWN (GFX_START_ROCKSHEROES + 0*HEROES_PER_LINE + 8) #define GFX_SCHWEIN_UP (GFX_START_ROCKSHEROES + 0*HEROES_PER_LINE +12) diff --git a/src/misc.c b/src/misc.c index c4c0352d..6445ee28 100644 --- a/src/misc.c +++ b/src/misc.c @@ -189,58 +189,164 @@ void MarkTileDirty(int x, int y) } } -void Error(BOOL fatal_error, char *format_str, ...) +void GetOptions(char *argv[]) { - FILE *output_stream = stderr; - va_list ap; - char *format_ptr; - char *s_value; - int i_value; - double d_value; + char **options_left = &argv[1]; - va_start(ap, format_str); /* ap points to first unnamed argument */ + while (*options_left) + { + char option_str[MAX_OPTION_LEN]; + char *option = options_left[0]; + char *next_option = options_left[1]; + char *option_arg = NULL; + int option_len = strlen(option); - fprintf(output_stream, "%s: ", program_name); + strcpy(option_str, option); /* copy argument into buffer */ + option = option_str; - for(format_ptr=format_str; *format_ptr; format_ptr++) - { - if (*format_ptr != '%') + if (strcmp(option, "--") == 0) /* stop scanning arguments */ + break; + + if (option_len >= MAX_OPTION_LEN) + Error(ERR_EXITHELP, "unrecognized option '%s'", option); + + if (strncmp(option, "--", 2) == 0) /* treat '--' like '-' */ + option++; + + option_arg = strchr(option, '='); + if (option_arg == NULL) /* no '=' in option */ + option_arg = next_option; + else + { + *option_arg++ = '\0'; /* cut argument from option */ + if (*option_arg == '\0') /* no argument after '=' */ + Error(ERR_EXITHELP, "option '%s' has invalid argument", option_str); + } + + option_len = strlen(option); + + if (strcmp(option, "-") == 0) + Error(ERR_EXITHELP, "unrecognized option '%s'", option); + else if (strncmp(option, "-help", option_len) == 0) + { + printf("Usage: %s [options] [server.name [port]]\n" + "Options:\n" + " -d, --display machine:0 X server display\n" + " -l, --levels directory alternative level directory\n" + " -v, --verbose verbose mode\n", + program_name); + exit(0); + } + else if (strncmp(option, "-display", option_len) == 0) + { + if (option_arg == NULL) + Error(ERR_EXITHELP, "option '%s' requires an argument", option_str); + + display_name = option_arg; + if (option_arg == next_option) + options_left++; + + printf("--display == '%s'\n", display_name); + } + else if (strncmp(option, "-levels", option_len) == 0) + { + if (option_arg == NULL) + Error(ERR_EXITHELP, "option '%s' requires an argument", option_str); + + level_directory = option_arg; + if (option_arg == next_option) + options_left++; + + printf("--levels == '%s'\n", level_directory); + } + else if (strncmp(option, "-verbose", option_len) == 0) { - fprintf(output_stream, "%c", *format_ptr); - continue; + printf("--verbose\n"); + + verbose = TRUE; } + else if (*option == '-') + Error(ERR_EXITHELP, "unrecognized option '%s'", option_str); + else if (server_host == NULL) + { + server_host = *options_left; - switch(*++format_ptr) + printf("server.name == '%s'\n", server_host); + } + else if (server_port == 0) { - case 'd': - i_value = va_arg(ap, int); - fprintf(output_stream, "%d", i_value); - break; - - case 'f': - d_value = va_arg(ap, double); - fprintf(output_stream, "%f", d_value); - break; - - case 's': - s_value = va_arg(ap, char *); - fprintf(output_stream, "%s", s_value); - break; - - default: - fprintf(stderr, "\nfatal(): invalid format string: %s\n", format_str); - exit(-1); + server_port = atoi(*options_left); + if (server_port < 1024) + Error(ERR_EXITHELP, "bad port number '%d'", server_port); + + printf("port == %d\n", server_port); } + else + Error(ERR_EXITHELP, "too many arguments"); + + options_left++; } +} - va_end(ap); +void Error(int mode, char *format_str, ...) +{ + FILE *output_stream = stderr; + + if (format_str) + { + va_list ap; + char *format_ptr; + char *s_value; + int i_value; + double d_value; + + fprintf(output_stream, "%s: ", program_name); - fprintf(output_stream, "\n"); + va_start(ap, format_str); /* ap points to first unnamed argument */ + + for(format_ptr=format_str; *format_ptr; format_ptr++) + { + if (*format_ptr != '%') + { + fprintf(output_stream, "%c", *format_ptr); + continue; + } + + switch(*++format_ptr) + { + case 'd': + i_value = va_arg(ap, int); + fprintf(output_stream, "%d", i_value); + break; + + case 'f': + d_value = va_arg(ap, double); + fprintf(output_stream, "%f", d_value); + break; + + case 's': + s_value = va_arg(ap, char *); + fprintf(output_stream, "%s", s_value); + break; + + default: + fprintf(stderr, "\nError(): invalid format string: %s\n",format_str); + CloseAllAndExit(10); + } + } + + va_end(ap); + + fprintf(output_stream, "\n"); + } + + if (mode == ERR_EXITHELP) + fprintf(output_stream, "%s: Try option '--help' for more information.\n", + program_name); - if (fatal_error) + if (mode == ERR_EXIT || mode == ERR_EXITHELP) { fprintf(output_stream, "%s: aborting\n", program_name); - CloseAll(); - exit(1); + CloseAllAndExit(1); } } diff --git a/src/misc.h b/src/misc.h index b3f530e7..8b483c52 100644 --- a/src/misc.h +++ b/src/misc.h @@ -23,6 +23,7 @@ #define ERR_RETURN 0 #define ERR_EXIT 1 +#define ERR_EXITHELP 2 void InitCounter(void); unsigned long Counter(void); @@ -36,6 +37,7 @@ unsigned int RND(unsigned int); unsigned int InitRND(long); char *GetLoginName(void); void MarkTileDirty(int, int); -void Error(BOOL, char *, ...); +void GetOptions(char **); +void Error(int, char *, ...); #endif diff --git a/src/tools.c b/src/tools.c index 2aad13a9..a705df56 100644 --- a/src/tools.c +++ b/src/tools.c @@ -382,7 +382,7 @@ void DrawPlayer(struct PlayerInfo *player) if (Store[last_jx][last_jy]) { DrawLevelElement(last_jx,last_jy, Store[last_jx][last_jy]); - DrawLevelElementThruMask(last_jx,last_jy, Feld[last_jx][last_jy]); + DrawLevelFieldThruMask(last_jx,last_jy); } else if (Feld[last_jx][last_jy] == EL_DYNAMIT) DrawDynamite(last_jx,last_jy); @@ -483,6 +483,16 @@ void DrawPlayer(struct PlayerInfo *player) DrawGraphicThruMask(sx,sy, graphic + phase); } + if ((last_jx != jx || last_jy != jy) && Feld[last_jx][last_jy]==EL_EXPLODING) + { + int phase = Frame[last_jx][last_jy]; + int delay = 2; + + if (phase > 2) + DrawGraphicThruMask(SCREENX(last_jx),SCREENY(last_jy), + GFX_EXPLOSION + ((phase-1)/delay-1)); + } + if (direct_draw_on) { int dest_x = SX + SCREENX(MIN(jx,last_jx))*TILEX; @@ -946,6 +956,11 @@ void DrawLevelElementThruMask(int x, int y, int element) DrawLevelElementExt(x,y, 0,0, element, NO_CUTTING, USE_MASKING); } +void DrawLevelFieldThruMask(int x, int y) +{ + DrawLevelElementExt(x,y, 0,0, Feld[x][y], NO_CUTTING, USE_MASKING); +} + void ErdreichAnbroeckeln(int x, int y) { int i, width, height, cx,cy; @@ -1087,13 +1102,8 @@ void DrawScreenField(int x, int y) Store[ux][uy]==EL_AMOEBE_NASS) cut_mode = CUT_ABOVE; else if (Store[ux][uy]==EL_MORAST_VOLL || - -#if 0 - Store[ux][uy]==EL_SALZSAEURE || -#endif - - Store[ux][uy]==EL_SIEB_VOLL || - Store[ux][uy]==EL_SIEB2_VOLL) + Store[ux][uy]==EL_SIEB_VOLL || + Store[ux][uy]==EL_SIEB2_VOLL) cut_mode = CUT_BELOW; if (cut_mode==CUT_ABOVE) @@ -1106,11 +1116,8 @@ void DrawScreenField(int x, int y) else DrawScreenElementShifted(x,y, 0,MovPos[ux][uy], element, cut_mode); -#if 1 if (Store[ux][uy] == EL_SALZSAEURE) DrawLevelElementThruMask(ux,uy+1, EL_SALZSAEURE); -#endif - } else if (IS_BLOCKED(ux,uy)) { @@ -1736,6 +1743,9 @@ int el2gfx(int element) case EL_ZEIT_VOLL: return(GFX_ZEIT_VOLL); case EL_ZEIT_LEER: return(GFX_ZEIT_LEER); case EL_MAUER_LEBT: return(GFX_MAUER_LEBT); + case EL_MAUER_X: return(GFX_MAUER_X); + case EL_MAUER_Y: return(GFX_MAUER_Y); + case EL_MAUER_XY: return(GFX_MAUER_XY); case EL_EDELSTEIN_BD: return(GFX_EDELSTEIN_BD); case EL_EDELSTEIN_GELB: return(GFX_EDELSTEIN_GELB); case EL_EDELSTEIN_ROT: return(GFX_EDELSTEIN_ROT); diff --git a/src/tools.h b/src/tools.h index 9ee53aa1..d4679614 100644 --- a/src/tools.h +++ b/src/tools.h @@ -80,6 +80,7 @@ void DrawScreenElementShifted(int, int, int, int, int, int); void DrawLevelElementShifted(int, int, int, int, int, int); void DrawScreenElementThruMask(int, int, int); void DrawLevelElementThruMask(int, int, int); +void DrawLevelFieldThruMask(int, int); void ErdreichAnbroeckeln(int, int); void DrawScreenElement(int, int, int); void DrawLevelElement(int, int, int); -- 2.34.1