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 ***********************************************************/
30 GC gc, clip_gc[NUM_PIXMAPS], tile_clip_gc;
31 Pixmap pix[NUM_PIXMAPS];
32 Pixmap clipmask[NUM_PIXMAPS], tile_clipmask[NUM_TILES];
34 #ifdef XPM_INCLUDE_FILE
35 XpmAttributes xpm_att[NUM_PICTURES];
38 Drawable drawto, drawto_field, backbuffer, fieldbuffer;
43 char *sound_device_name = SOUND_DEVICE;
44 int joystick_device = 0;
45 char *joystick_device_name[2] = { DEV_JOYSTICK_0, DEV_JOYSTICK_1 };
46 char *level_directory = LEVEL_PATH;
49 char *display_name = NULL;
50 char *server_host = NULL;
52 int networking = FALSE;
53 int standalone = TRUE;
56 int game_status = MAINMENU;
57 int game_emulation = EMU_NONE;
58 int button_status = MB_NOT_PRESSED, motion_status = FALSE;
59 int key_joystick_mapping = 0;
60 int global_joystick_status = JOYSTICK_STATUS;
61 int joystick_status = JOYSTICK_STATUS;
62 int sound_status = SOUND_STATUS, sound_on = TRUE;
63 int sound_loops_allowed = FALSE, sound_loops_on = FALSE;
64 int sound_music_on = FALSE;
65 int sound_simple_on = FALSE;
67 int direct_draw_on = FALSE;
68 int scroll_delay_on = FALSE;
69 int soft_scrolling_on = TRUE;
70 int fading_on = FALSE;
71 int autorecord_on = FALSE;
73 int quick_doors = FALSE;
75 BOOL redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
76 int redraw_x1 = 0, redraw_y1 = 0;
80 int Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
81 int Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
82 int MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
83 int MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
84 int MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
85 int Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
86 int Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
87 int StorePlayer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
88 int Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
89 int Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
90 int JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
91 int AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
92 int AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
93 long Elementeigenschaften[MAX_ELEMENTS];
95 int level_nr, leveldir_nr, num_leveldirs;
96 int lev_fieldx,lev_fieldy, scroll_x,scroll_y;
98 int FX = SX, FY = SY, ScrollStepSize = TILEX/8;
99 int ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0;
100 int ScreenGfxPos = 0;
101 int GameFrameDelay = GAME_FRAME_DELAY, MoveSpeed = 8;
102 int BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
103 int ZX,ZY, ExitX,ExitY;
105 int FrameCounter, TimeFrames, TimeLeft;
106 int MampferNr, SiebAktiv;
110 struct LevelDirInfo leveldir[MAX_LEVDIR_ENTRIES];
111 struct LevelInfo level;
112 struct PlayerInfo stored_player[MAX_PLAYERS+1];
113 struct PlayerInfo *local_player;
114 struct HiScore highscore[MAX_SCORE_ENTRIES];
115 struct SoundInfo Sound[NUM_SOUNDS];
116 struct RecordingInfo tape;
118 struct JoystickInfo joystick[2] =
120 { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
121 JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE },
122 { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
123 JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE }
126 /* data needed for playing sounds */
127 char *sound_name[NUM_SOUNDS] =
183 /* background music */
184 int background_loop[] =
194 int num_bg_loops = sizeof(background_loop)/sizeof(int);
198 #define MAX_OPTION_LEN 1024
200 static void fatal_option()
202 fprintf(stderr,"Try '%s --help' for more information.\n",
207 static void fatal_unrecognized_option(char *option)
209 fprintf(stderr,"%s: unrecognized option '%s'\n",
210 program_name, option);
214 static void fatal_option_requires_argument(char *option)
216 fprintf(stderr,"%s: option '%s' requires an argument\n",
217 program_name, option);
221 static void fatal_invalid_option_argument(char *option)
223 fprintf(stderr,"%s: option '%s' has invalid argument\n",
224 program_name, option);
228 static void fatal_too_many_arguments()
230 fprintf(stderr,"%s: too many arguments\n",
235 extern void fatal(char *);
237 int main(int argc, char *argv[])
239 char **options_left = &argv[1];
241 program_name = (strrchr(argv[0],'/') ? strrchr(argv[0],'/') + 1 : argv[0]);
243 while (*options_left)
245 char option_str[MAX_OPTION_LEN];
246 char *option = options_left[0];
247 char *next_option = options_left[1];
248 char *option_arg = NULL;
249 int option_len = strlen(option);
251 strcpy(option_str, option); /* copy argument into buffer */
254 if (strcmp(option, "--") == 0) /* stop scanning arguments */
257 if (option_len >= MAX_OPTION_LEN)
258 fatal_unrecognized_option(option);
260 if (strncmp(option, "--", 2) == 0) /* treat '--' like '-' */
263 option_arg = strchr(option, '=');
264 if (option_arg == NULL) /* no '=' in option */
265 option_arg = next_option;
268 *option_arg++ = '\0'; /* cut argument from option */
269 if (*option_arg == '\0') /* no argument after '=' */
270 fatal_invalid_option_argument(option);
273 option_len = strlen(option);
275 if (strcmp(option, "-") == 0)
276 fatal_unrecognized_option(option);
277 else if (strncmp(option, "-help", option_len) == 0)
279 printf("Usage: %s [options] [server.name [port]]\n"
281 " -d, --display machine:0 X server display\n"
282 " -l, --levels directory alternative level directory\n"
283 " -v, --verbose verbose mode\n",
287 else if (strncmp(option, "-display", option_len) == 0)
289 if (option_arg == NULL)
290 fatal_option_requires_argument(option_str);
292 display_name = option_arg;
293 if (option_arg == next_option)
296 printf("--display == '%s'\n", display_name);
298 else if (strncmp(option, "-levels", option_len) == 0)
300 if (option_arg == NULL)
301 fatal_option_requires_argument(option_str);
303 level_directory = option_arg;
304 if (option_arg == next_option)
307 printf("--levels == '%s'\n", level_directory);
309 else if (strncmp(option, "-verbose", option_len) == 0)
311 printf("--verbose\n");
315 else if (*option == '-')
316 fatal_unrecognized_option(option_str);
317 else if (server_host == NULL)
319 server_host = *options_left;
321 printf("server.name == '%s'\n", server_host);
323 else if (server_port == 0)
325 server_port = atoi(*options_left);
326 if (server_port < 1024)
327 fatal("Bad port number");
329 printf("port == %d\n", server_port);
332 fatal_too_many_arguments();
338 printf("All went fine -- exiting\n");
344 level_directory = argv[1];
350 server_host = argv[1];
353 server_port = atoi(argv[2]);