rnd-19980904-1
[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 "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 int             screen;
27 Window          window;
28 GC              gc, clip_gc[NUM_PIXMAPS];
29 Pixmap          pix[NUM_PIXMAPS];
30 Pixmap          clipmask[NUM_PIXMAPS];
31
32
33 Pixmap          test_pix[NUM_PICTURES];
34 Pixmap          test_clipmask[NUM_PICTURES];
35 int             test_picture_count = 0;
36
37
38 #ifdef XPM_INCLUDE_FILE
39 XpmAttributes   xpm_att[NUM_PICTURES];
40 #endif
41
42 Drawable        drawto, drawto_field, backbuffer, fieldbuffer;
43 Colormap        cmap;
44
45 int             sound_pipe[2];
46 int             sound_device;
47 char           *sound_device_name = SOUND_DEVICE;
48 int             joystick_device = 0;
49 char           *joystick_device_name[2] = { DEV_JOYSTICK_0, DEV_JOYSTICK_1 };
50 char           *level_directory = LEVEL_PATH;
51 int             width, height;
52 unsigned long   pen_fg, pen_bg;
53
54 int             game_status = MAINMENU;
55 int             game_emulation = EMU_NONE;
56 int             button_status = MB_NOT_PRESSED, motion_status = FALSE;
57 int             key_joystick_mapping = 0;
58 int             global_joystick_status = JOYSTICK_STATUS;
59 int             joystick_status = JOYSTICK_STATUS;
60 int             sound_status = SOUND_STATUS, sound_on = TRUE;
61 int             sound_loops_allowed = FALSE, sound_loops_on = FALSE;
62 int             sound_music_on = FALSE;
63 int             sound_simple_on = FALSE;
64 int             toons_on = TRUE;
65 int             direct_draw_on = FALSE;
66 int             scroll_delay_on = FALSE;
67 int             soft_scrolling_on = TRUE;
68 int             fading_on = FALSE;
69 int             autorecord_on = FALSE;
70 int             joystick_nr = 0;
71 int             quick_doors = FALSE;
72
73 BOOL            redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
74 int             redraw_x1 = 0, redraw_y1 = 0;
75 int             redraw_mask;
76 int             redraw_tiles;
77
78 int             Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
79 int             Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
80 int             MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
81 int             MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
82 int             MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
83 int             Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
84 int             Store2[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, ScreenMovPos = 0, ScrollStepSize = TILEX/8;
96 int             BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
97 int             JX,JY, lastJX,lastJY, ZX,ZY, ExitX,ExitY;
98 int             PlayerMovDir, PlayerMovPos, PlayerPushing;
99 int             PlayerFrame, PlayerGfxPos;
100 int             PlayerGone, LevelSolved, GameOver;
101 int             FrameCounter, TimeFrames, TimeLeft, Score;
102 int             Gems, SokobanFields, Lights, Friends;
103 int             Dynamite, Key[4], MampferNr;
104 int             DynaBombCount, DynaBombSize, DynaBombsLeft, DynaBombXL;
105 int             SiebAktiv;
106
107 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
108 struct LevelInfo        level;
109 struct PlayerInfo       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   if (argc>1)
199     level_directory = argv[1];
200
201 #ifdef MSDOS
202   _fmode = O_BINARY;
203 #endif
204
205   OpenAll(argc,argv);
206   EventLoop();
207   CloseAll();
208
209   exit(0);
210 }