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