1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
29 GC gc, clip_gc[NUM_PIXMAPS], tile_clip_gc;
30 Pixmap pix[NUM_PIXMAPS];
31 Pixmap clipmask[NUM_PIXMAPS], tile_clipmask[NUM_TILES];
33 #ifdef XPM_INCLUDE_FILE
34 XpmAttributes xpm_att[NUM_PICTURES];
37 Drawable drawto, drawto_field, backbuffer, fieldbuffer;
42 char *sound_device_name = SOUND_DEVICE;
43 int joystick_device = 0;
44 char *joystick_device_name[2] = { DEV_JOYSTICK_0, DEV_JOYSTICK_1 };
45 char *level_directory = LEVEL_PATH;
48 char *display_name = NULL;
49 char *server_host = NULL;
51 int networking = FALSE;
52 int standalone = TRUE;
55 int game_status = MAINMENU;
56 int game_emulation = EMU_NONE;
57 int button_status = MB_NOT_PRESSED, motion_status = FALSE;
58 int key_joystick_mapping = 0;
59 int global_joystick_status = JOYSTICK_STATUS;
60 int joystick_status = JOYSTICK_STATUS;
61 int sound_status = SOUND_STATUS, sound_on = TRUE;
62 int sound_loops_allowed = FALSE, sound_loops_on = FALSE;
63 int sound_music_on = FALSE;
64 int sound_simple_on = FALSE;
66 int direct_draw_on = FALSE;
67 int scroll_delay_on = FALSE;
68 int soft_scrolling_on = TRUE;
69 int fading_on = FALSE;
70 int autorecord_on = FALSE;
72 int quick_doors = FALSE;
74 BOOL redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
75 int redraw_x1 = 0, redraw_y1 = 0;
79 int Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
80 int Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
81 int MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
82 int MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
83 int MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
84 int Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
85 int Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
86 int StorePlayer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
87 int Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
88 int Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
89 int JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
90 int AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
91 int AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
92 long Elementeigenschaften[MAX_ELEMENTS];
94 int level_nr, leveldir_nr, num_leveldirs;
95 int lev_fieldx,lev_fieldy, scroll_x,scroll_y;
97 int FX = SX, FY = SY, ScrollStepSize = TILEX/8;
98 int ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0;
100 int GameFrameDelay = GAME_FRAME_DELAY, MoveSpeed = 8;
101 int BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
102 int ZX,ZY, ExitX,ExitY;
104 int FrameCounter, TimeFrames, TimeLeft;
105 int MampferNr, SiebAktiv;
109 struct LevelDirInfo leveldir[MAX_LEVDIR_ENTRIES];
110 struct LevelInfo level;
111 struct PlayerInfo stored_player[MAX_PLAYERS+1];
112 struct PlayerInfo *local_player;
113 struct HiScore highscore[MAX_SCORE_ENTRIES];
114 struct SoundInfo Sound[NUM_SOUNDS];
115 struct RecordingInfo tape;
117 struct JoystickInfo joystick[2] =
119 { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
120 JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE },
121 { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
122 JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE }
125 /* data needed for playing sounds */
126 char *sound_name[NUM_SOUNDS] =
182 /* background music */
183 int background_loop[] =
193 int num_bg_loops = sizeof(background_loop)/sizeof(int);
197 #define MAX_OPTION_LEN 1024
199 static void fatal_option()
201 fprintf(stderr,"Try '%s --help' for more information.\n",
206 static void fatal_unrecognized_option(char *option)
208 fprintf(stderr,"%s: unrecognized option '%s'\n",
213 static void fatal_option_requires_argument(char *option)
215 fprintf(stderr,"%s: option '%s' requires an argument\n",
220 static void fatal_invalid_argument(char *option)
222 fprintf(stderr,"%s: option '%s' has invalid argument\n",
227 static void fatal_too_many_arguments()
229 fprintf(stderr,"%s: too many arguments\n",
234 extern void fatal(char *);
236 int main(int argc, char *argv[])
238 char **options_left = &argv[1];
240 progname = &argv[0][strlen(argv[0])];
241 while (progname != argv[0])
242 if (*progname-- == '/')
247 char option_str[MAX_OPTION_LEN];
248 char *option = options_left[0];
249 char *next_option = options_left[1];
250 char *option_arg = NULL;
253 if (strcmp(option, "--") == 0) /* end of argument list */
256 if (strncmp(option, "--", 2)) /* treat '--' like '-' */
258 option_len = strlen(option);
260 if (option_len >= MAX_OPTION_LEN)
261 fatal_unrecognized_option(option);
263 strcpy(option_str, option);
266 option_arg = strchr(option, '=');
267 if (option_arg == NULL) /* no '=' in option */
268 option_arg = next_option;
271 *option_arg++ = '\0'; /* cut argument from option */
272 if (*option_arg == '\0') /* no argument after '=' */
273 fatal_invalid_argument(option);
276 if (strncmp(option, "-help", option_len) == 0)
278 printf("Usage: rocksndiamonds [options] [server.name [port]]\n"
280 " -d, --display machine:0 X server display\n"
281 " -l, --levels directory alternative level directory\n"
282 " -v, --verbose verbose mode\n");
285 else if (strncmp(option, "-display", option_len) == 0)
287 if (option_arg == NULL)
288 fatal_option_requires_argument(option);
290 display_name = option_arg;
291 if (option_arg == next_option)
294 else if (strncmp(option, "-levels", option_len) == 0)
296 if (option_arg == NULL)
297 fatal_option_requires_argument(option);
299 level_directory = option_arg;
300 if (option_arg == next_option)
303 else if (strncmp(option, "-verbose", option_len) == 0)
307 else if (*option == '-')
308 fatal_unrecognized_option(option);
309 else if (server_host == NULL)
310 server_host = *options_left;
311 else if (server_port == 0)
313 server_port = atoi(*options_left);
314 if (server_port < 1024)
315 fatal("Bad port number");
318 fatal_too_many_arguments();
327 level_directory = argv[1];
333 server_host = argv[1];
336 server_port = atoi(argv[2]);