rnd-19981121-2
[rocksndiamonds.git] / src / main.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  (c) 1995-98 Artsoft Entertainment                       *
5 *              Holger Schemel                              *
6 *              Oststrasse 11a                              *
7 *              33604 Bielefeld                             *
8 *              phone: ++49 +521 290471                     *
9 *              email: aeglos@valinor.owl.de                *
10 *----------------------------------------------------------*
11 *  main.c                                                  *
12 ***********************************************************/
13
14 #include "main.h"
15 #include "init.h"
16 #include "game.h"
17 #include "events.h"
18 #include "sound.h"
19 #include "joystick.h"
20 #include "misc.h"
21
22 #ifdef MSDOS
23 #include <fcntl.h>
24 #endif
25
26 Display        *display;
27 Visual         *visual;
28 int             screen;
29 Window          window;
30 GC              gc, clip_gc[NUM_PIXMAPS], tile_clip_gc;
31 Pixmap          pix[NUM_PIXMAPS];
32 Pixmap          clipmask[NUM_PIXMAPS], tile_clipmask[NUM_TILES];
33
34 #ifdef USE_XPM_LIBRARY
35 XpmAttributes   xpm_att[NUM_PICTURES];
36 #endif
37
38 Drawable        drawto, drawto_field, backbuffer, fieldbuffer;
39 Colormap        cmap;
40
41 int             sound_pipe[2];
42 int             sound_device;
43 char           *sound_device_name = SOUND_DEVICE;
44 int             joystick_device = 0;
45 char           *joystick_device_name[MAX_PLAYERS] =
46 {
47   DEV_JOYSTICK_0,
48   DEV_JOYSTICK_1,
49   DEV_JOYSTICK_2,
50   DEV_JOYSTICK_3
51 };
52
53 char           *program_name = NULL;
54
55 int             game_status = MAINMENU;
56 int             game_emulation = EMU_NONE;
57 boolean         network_playing = FALSE;
58 int             button_status = MB_NOT_PRESSED;
59 boolean         motion_status = FALSE;
60 int             key_joystick_mapping = 0;
61 int             global_joystick_status = JOYSTICK_STATUS;
62 int             joystick_status = JOYSTICK_STATUS;
63 int             sound_status = SOUND_STATUS;
64 boolean         sound_loops_allowed = FALSE;
65
66 boolean         redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
67 int             redraw_x1 = 0, redraw_y1 = 0;
68 int             redraw_mask;
69 int             redraw_tiles;
70
71 short           Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
72 short           Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
73 short           MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
74 short           MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
75 short           MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
76 short           Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
77 short           Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
78 short           StorePlayer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
79 short           Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
80 boolean         Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
81 short           JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
82 short           AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
83 short           AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
84 unsigned long   Elementeigenschaften[MAX_ELEMENTS];
85
86 int             level_nr, leveldir_nr, num_leveldirs;
87 int             lev_fieldx,lev_fieldy, scroll_x,scroll_y;
88
89 int             FX = SX, FY = SY, ScrollStepSize = TILEX/8;
90 int             ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0;
91 int             ScreenGfxPos = 0;
92 int             GameFrameDelay = GAME_FRAME_DELAY;
93 int             FfwdFrameDelay = FFWD_FRAME_DELAY;
94 int             MoveSpeed = 8;
95 int             BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
96 int             ZX,ZY, ExitX,ExitY;
97 int             AllPlayersGone;
98 int             FrameCounter, TimeFrames, TimeLeft;
99 int             MampferNr, SiebAktiv;
100
101 boolean         network_player_action_received = FALSE;
102 int             TestPlayer = 0;
103
104 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
105 struct LevelInfo        level;
106 struct PlayerInfo       stored_player[MAX_PLAYERS], *local_player = NULL;
107 struct HiScore          highscore[MAX_SCORE_ENTRIES];
108 struct SoundInfo        Sound[NUM_SOUNDS];
109 struct RecordingInfo    tape;
110 struct OptionInfo       options;
111 struct SetupInfo        setup;
112 struct SetupFileList    *setup_list = NULL;
113 struct SetupFileList    *level_setup_list = NULL;
114
115 /* data needed for playing sounds */
116 char *sound_name[NUM_SOUNDS] =
117 {
118   "alchemy",
119   "amoebe",
120   "antigrav",
121   "autsch",
122   "blurb",
123   "bong",
124   "buing",
125   "chase",
126   "czardasz",
127   "deng",
128   "fuel",
129   "gong",
130   "halloffame",
131   "holz",
132   "hui",
133   "kabumm",
134   "kink",
135   "klapper",
136   "kling",
137   "klopf",
138   "klumpf",
139   "knack",
140   "knurk",
141   "krach",
142   "lachen",
143   "laser",
144   "miep",
145   "network",
146   "njam",
147   "oeffnen",
148   "pling",
149   "pong",
150   "pusch",
151   "quiek",
152   "quirk",
153   "rhythmloop",
154   "roaaar",
155   "roehr",
156   "rumms",
157   "schlopp",
158   "schlurf",
159   "schrff",
160   "schwirr",
161   "sirr",
162   "slurp",
163   "sproing",
164   "twilight",
165   "tyger",
166   "voyager",
167   "warnton",
168   "whoosh",
169   "zisch"
170 };
171
172 /* background music */
173 int background_loop[] =
174 {
175   SND_ALCHEMY,
176   SND_CHASE,
177   SND_NETWORK,
178   SND_CZARDASZ,
179   SND_TYGER,
180   SND_VOYAGER,
181   SND_TWILIGHT
182 };
183 int num_bg_loops = sizeof(background_loop)/sizeof(int);
184
185 int main(int argc, char *argv[])
186 {
187   program_name = (strrchr(argv[0],'/') ? strrchr(argv[0],'/') + 1 : argv[0]);
188
189 #ifdef MSDOS
190   _fmode = O_BINARY;
191 #endif
192
193   GetOptions(argv);
194   OpenAll(argc,argv);
195   EventLoop();
196   CloseAllAndExit(0);
197   exit(0);      /* to keep compilers happy */
198 }