rnd-19981204-2
[rocksndiamonds.git] / src / main.c
index eed5609420106a9984b6cbec570c84d38565a414..a0483461e302bf798c45bba8f6c3ae446f9a1f53 100644 (file)
@@ -1,31 +1,37 @@
 /***********************************************************
 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
 *----------------------------------------------------------*
-*  ©1995 Artsoft Development                               *
-*        Holger Schemel                                    *
-*        33659 Bielefeld-Senne                             *
-*        Telefon: (0521) 493245                            *
-*        eMail: aeglos@valinor.owl.de                      *
-*               aeglos@uni-paderborn.de                    *
-*               q99492@pbhrzx.uni-paderborn.de             *
+*  (c) 1995-98 Artsoft Entertainment                       *
+*              Holger Schemel                              *
+*              Oststrasse 11a                              *
+*              33604 Bielefeld                             *
+*              phone: ++49 +521 290471                     *
+*              email: aeglos@valinor.owl.de                *
 *----------------------------------------------------------*
 *  main.c                                                  *
 ***********************************************************/
 
 #include "main.h"
 #include "init.h"
+#include "game.h"
 #include "events.h"
 #include "sound.h"
 #include "joystick.h"
+#include "misc.h"
+
+#ifdef MSDOS
+#include <fcntl.h>
+#endif
 
 Display        *display;
+Visual        *visual;
 int            screen;
 Window         window;
-GC             gc, clip_gc[NUM_PIXMAPS];
+GC             gc, clip_gc[NUM_PIXMAPS], tile_clip_gc;
 Pixmap         pix[NUM_PIXMAPS];
-Pixmap         clipmask[NUM_PIXMAPS];
+Pixmap         clipmask[NUM_PIXMAPS], tile_clipmask[NUM_TILES];
 
-#ifdef XPM_INCLUDE_FILE
+#ifdef USE_XPM_LIBRARY
 XpmAttributes  xpm_att[NUM_PICTURES];
 #endif
 
@@ -36,78 +42,73 @@ int         sound_pipe[2];
 int            sound_device;
 char          *sound_device_name = SOUND_DEVICE;
 int            joystick_device = 0;
-char          *joystick_device_name[2] = { DEV_JOYSTICK_0, DEV_JOYSTICK_1 };
-char          *level_directory = LEVEL_PATH;
-int            width, height;
-unsigned long  pen_fg, pen_bg;
+char          *joystick_device_name[MAX_PLAYERS] =
+{
+  DEV_JOYSTICK_0,
+  DEV_JOYSTICK_1,
+  DEV_JOYSTICK_2,
+  DEV_JOYSTICK_3
+};
+
+char          *program_name = NULL;
 
 int            game_status = MAINMENU;
-int            game_emulation = EMU_NONE;
-int            button_status = MB_NOT_PRESSED, motion_status = FALSE;
+boolean                network_playing = FALSE;
+int            button_status = MB_NOT_PRESSED;
+boolean                motion_status = FALSE;
 int            key_joystick_mapping = 0;
 int            global_joystick_status = JOYSTICK_STATUS;
 int            joystick_status = JOYSTICK_STATUS;
-int            sound_status = SOUND_STATUS, sound_on = TRUE;
-int            sound_loops_allowed = FALSE, sound_loops_on = FALSE;
-int            sound_music_on = FALSE;
-int            sound_simple_on = FALSE;
-int            toons_on = TRUE;
-int            direct_draw_on = FALSE;
-int            scroll_delay_on = FALSE;
-int            soft_scrolling_on = TRUE;
-int            fading_on = FALSE;
-int            autorecord_on = FALSE;
-int            joystick_nr = 0;
-int            quick_doors = FALSE;
-
-BOOL           redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
+int            sound_status = SOUND_STATUS;
+boolean                sound_loops_allowed = FALSE;
+
+boolean                redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
 int            redraw_x1 = 0, redraw_y1 = 0;
 int            redraw_mask;
 int            redraw_tiles;
 
-int            Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
-int            AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
-long           Elementeigenschaften[MAX_ELEMENTS];
+short          Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          StorePlayer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+boolean                Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
+short          AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
+unsigned long  Elementeigenschaften[MAX_ELEMENTS];
 
 int            level_nr, leveldir_nr, num_leveldirs;
 int            lev_fieldx,lev_fieldy, scroll_x,scroll_y;
 
-int            FX = SX, FY = SY, ScreenMovPos = 0, ScrollStepSize = TILEX/8;
+int            FX = SX, FY = SY, ScrollStepSize = TILEX/8;
+int            ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0;
+int            ScreenGfxPos = 0;
+int            GameFrameDelay = GAME_FRAME_DELAY;
+int            FfwdFrameDelay = FFWD_FRAME_DELAY;
+int            MoveSpeed = 8;
 int            BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
-int            JX,JY, lastJX,lastJY, ZX,ZY, ExitX,ExitY;
-int            PlayerMovDir, PlayerMovPos, PlayerPushing;
-int            PlayerFrame, PlayerGfxPos;
-int            PlayerGone, LevelSolved, GameOver;
-int            FrameCounter, TimeFrames, TimeLeft, Score;
-int            Gems, SokobanFields, Lights, Friends;
-int            Dynamite, Key[4], MampferNr;
-int            DynaBombCount, DynaBombSize, DynaBombsLeft, DynaBombXL;
-int            SiebAktiv;
+int            ZX,ZY, ExitX,ExitY;
+int            AllPlayersGone;
+int            FrameCounter, TimeFrames, TimeLeft;
+int            MampferNr, SiebAktiv;
+
+boolean                network_player_action_received = FALSE;
 
 struct LevelDirInfo    leveldir[MAX_LEVDIR_ENTRIES];
 struct LevelInfo       level;
-struct PlayerInfo      player;
+struct PlayerInfo      stored_player[MAX_PLAYERS], *local_player = NULL;
 struct HiScore         highscore[MAX_SCORE_ENTRIES];
 struct SoundInfo       Sound[NUM_SOUNDS];
-struct RecordingInfo   tape;
-
-struct JoystickInfo joystick[2] =
-{
-  { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
-    JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE },
-  { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
-    JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE }
-};
+struct TapeInfo                tape;
+struct OptionInfo      options;
+struct SetupInfo       setup;
+struct SetupFileList   *setup_list = NULL;
+struct SetupFileList   *level_setup_list = NULL;
 
 /* data needed for playing sounds */
 char *sound_name[NUM_SOUNDS] =
@@ -179,18 +180,17 @@ int background_loop[] =
 };
 int num_bg_loops = sizeof(background_loop)/sizeof(int);
 
-char           *progname;
-
 int main(int argc, char *argv[])
 {
-  progname = argv[0];
+  program_name = (strrchr(argv[0],'/') ? strrchr(argv[0],'/') + 1 : argv[0]);
 
-  if (argc>1)
-    level_directory = argv[1];
+#ifdef MSDOS
+  _fmode = O_BINARY;
+#endif
 
+  GetOptions(argv);
   OpenAll(argc,argv);
   EventLoop();
-  CloseAll();
-
-  exit(0);
+  CloseAllAndExit(0);
+  exit(0);     /* to keep compilers happy */
 }