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