rnd-19980906
[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 #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 unsigned long   pen_fg, pen_bg;
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
68 BOOL            redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
69 int             redraw_x1 = 0, redraw_y1 = 0;
70 int             redraw_mask;
71 int             redraw_tiles;
72
73 int             Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
74 int             Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
75 int             MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
76 int             MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
77 int             MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
78 int             Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
79 int             Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
80 int             Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
81 int             Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
82 int             JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
83 int             AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
84 int             AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
85 long            Elementeigenschaften[MAX_ELEMENTS];
86
87 int             level_nr, leveldir_nr, num_leveldirs;
88 int             lev_fieldx,lev_fieldy, scroll_x,scroll_y;
89
90 int             FX = SX, FY = SY, ScreenMovPos = 0, ScrollStepSize = TILEX/8;
91 int             BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
92 int             JX,JY, lastJX,lastJY, ZX,ZY, ExitX,ExitY;
93 int             PlayerMovDir, PlayerMovPos, PlayerPushing;
94 int             PlayerFrame, PlayerGfxPos;
95 int             PlayerGone, LevelSolved, GameOver;
96 int             FrameCounter, TimeFrames, TimeLeft, Score;
97 int             Gems, SokobanFields, Lights, Friends;
98 int             Dynamite, Key[4], MampferNr;
99 int             DynaBombCount, DynaBombSize, DynaBombsLeft, DynaBombXL;
100 int             SiebAktiv;
101
102 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
103 struct LevelInfo        level;
104 struct PlayerInfo       player;
105 struct HiScore          highscore[MAX_SCORE_ENTRIES];
106 struct SoundInfo        Sound[NUM_SOUNDS];
107 struct RecordingInfo    tape;
108
109 struct JoystickInfo joystick[2] =
110 {
111   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
112     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE },
113   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
114     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE }
115 };
116
117 /* data needed for playing sounds */
118 char *sound_name[NUM_SOUNDS] =
119 {
120   "alchemy",
121   "amoebe",
122   "antigrav",
123   "autsch",
124   "blurb",
125   "bong",
126   "buing",
127   "chase",
128   "czardasz",
129   "deng",
130   "fuel",
131   "gong",
132   "halloffame",
133   "holz",
134   "hui",
135   "kabumm",
136   "kink",
137   "klapper",
138   "kling",
139   "klopf",
140   "klumpf",
141   "knack",
142   "knurk",
143   "krach",
144   "lachen",
145   "laser",
146   "miep",
147   "network",
148   "njam",
149   "oeffnen",
150   "pling",
151   "pong",
152   "pusch",
153   "quiek",
154   "quirk",
155   "rhythmloop",
156   "roaaar",
157   "roehr",
158   "rumms",
159   "schlopp",
160   "schlurf",
161   "schrff",
162   "schwirr",
163   "sirr",
164   "slurp",
165   "sproing",
166   "twilight",
167   "tyger",
168   "voyager",
169   "warnton",
170   "whoosh",
171   "zisch"
172 };
173
174 /* background music */
175 int background_loop[] =
176 {
177   SND_ALCHEMY,
178   SND_CHASE,
179   SND_NETWORK,
180   SND_CZARDASZ,
181   SND_TYGER,
182   SND_VOYAGER,
183   SND_TWILIGHT
184 };
185 int num_bg_loops = sizeof(background_loop)/sizeof(int);
186
187 char            *progname;
188
189 int main(int argc, char *argv[])
190 {
191   progname = argv[0];
192
193   if (argc>1)
194     level_directory = argv[1];
195
196 #ifdef MSDOS
197   _fmode = O_BINARY;
198 #endif
199
200   OpenAll(argc,argv);
201   EventLoop();
202   CloseAll();
203
204   exit(0);
205 }