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