rnd-19980930-1
[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
21 #ifdef MSDOS
22 #include <fcntl.h>
23 #endif
24
25 Display        *display;
26 Visual         *visual;
27 int             screen;
28 Window          window;
29 GC              gc, clip_gc[NUM_PIXMAPS], tile_clip_gc;
30 Pixmap          pix[NUM_PIXMAPS];
31 Pixmap          clipmask[NUM_PIXMAPS], tile_clipmask[NUM_TILES];
32
33 #ifdef XPM_INCLUDE_FILE
34 XpmAttributes   xpm_att[NUM_PICTURES];
35 #endif
36
37 Drawable        drawto, drawto_field, backbuffer, fieldbuffer;
38 Colormap        cmap;
39
40 int             sound_pipe[2];
41 int             sound_device;
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;
46 int             width, height;
47
48 char           *server_host = NULL;
49 int             server_port = 0;
50
51 int             game_status = MAINMENU;
52 int             game_emulation = EMU_NONE;
53 int             button_status = MB_NOT_PRESSED, motion_status = FALSE;
54 int             key_joystick_mapping = 0;
55 int             global_joystick_status = JOYSTICK_STATUS;
56 int             joystick_status = JOYSTICK_STATUS;
57 int             sound_status = SOUND_STATUS, sound_on = TRUE;
58 int             sound_loops_allowed = FALSE, sound_loops_on = FALSE;
59 int             sound_music_on = FALSE;
60 int             sound_simple_on = FALSE;
61 int             toons_on = TRUE;
62 int             direct_draw_on = FALSE;
63 int             scroll_delay_on = FALSE;
64 int             soft_scrolling_on = TRUE;
65 int             fading_on = FALSE;
66 int             autorecord_on = FALSE;
67 int             joystick_nr = 0;
68 int             quick_doors = FALSE;
69 int             networking = FALSE;
70
71 BOOL            redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
72 int             redraw_x1 = 0, redraw_y1 = 0;
73 int             redraw_mask;
74 int             redraw_tiles;
75
76 int             Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
77 int             Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
78 int             MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
79 int             MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
80 int             MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
81 int             Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
82 int             Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
83 int             StorePlayer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
84 int             Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
85 int             Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
86 int             JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
87 int             AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
88 int             AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
89 long            Elementeigenschaften[MAX_ELEMENTS];
90
91 int             level_nr, leveldir_nr, num_leveldirs;
92 int             lev_fieldx,lev_fieldy, scroll_x,scroll_y;
93
94 int             FX = SX, FY = SY, ScrollStepSize = TILEX/8;
95 int             ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0;
96 int             ScreenGfxPos = 0;
97 int             GameFrameDelay = GAME_FRAME_DELAY, MoveSpeed = 8;
98 int             BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
99 int             ZX,ZY, ExitX,ExitY;
100 int             AllPlayersGone;
101 int             FrameCounter, TimeFrames, TimeLeft;
102 int             MampferNr, SiebAktiv;
103
104 int             TestPlayer = 0;
105
106 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
107 struct LevelInfo        level;
108 struct PlayerInfo       stored_player[MAX_PLAYERS+1];
109 struct PlayerInfo      *local_player;
110 struct HiScore          highscore[MAX_SCORE_ENTRIES];
111 struct SoundInfo        Sound[NUM_SOUNDS];
112 struct RecordingInfo    tape;
113
114 struct JoystickInfo joystick[2] =
115 {
116   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
117     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE },
118   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
119     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE }
120 };
121
122 /* data needed for playing sounds */
123 char *sound_name[NUM_SOUNDS] =
124 {
125   "alchemy",
126   "amoebe",
127   "antigrav",
128   "autsch",
129   "blurb",
130   "bong",
131   "buing",
132   "chase",
133   "czardasz",
134   "deng",
135   "fuel",
136   "gong",
137   "halloffame",
138   "holz",
139   "hui",
140   "kabumm",
141   "kink",
142   "klapper",
143   "kling",
144   "klopf",
145   "klumpf",
146   "knack",
147   "knurk",
148   "krach",
149   "lachen",
150   "laser",
151   "miep",
152   "network",
153   "njam",
154   "oeffnen",
155   "pling",
156   "pong",
157   "pusch",
158   "quiek",
159   "quirk",
160   "rhythmloop",
161   "roaaar",
162   "roehr",
163   "rumms",
164   "schlopp",
165   "schlurf",
166   "schrff",
167   "schwirr",
168   "sirr",
169   "slurp",
170   "sproing",
171   "twilight",
172   "tyger",
173   "voyager",
174   "warnton",
175   "whoosh",
176   "zisch"
177 };
178
179 /* background music */
180 int background_loop[] =
181 {
182   SND_ALCHEMY,
183   SND_CHASE,
184   SND_NETWORK,
185   SND_CZARDASZ,
186   SND_TYGER,
187   SND_VOYAGER,
188   SND_TWILIGHT
189 };
190 int num_bg_loops = sizeof(background_loop)/sizeof(int);
191
192 char            *progname;
193
194 int main(int argc, char *argv[])
195 {
196   progname = argv[0];
197
198
199
200   /*
201   if (argc>1)
202     level_directory = argv[1];
203     */
204
205
206
207   if (argc > 1)
208     server_host = argv[1];
209
210   if (argc > 2)
211     server_port = atoi(argv[2]);
212
213
214
215 #ifdef MSDOS
216   _fmode = O_BINARY;
217 #endif
218
219   OpenAll(argc,argv);
220   EventLoop();
221   CloseAll();
222
223   exit(0);
224 }