rnd-19980812
[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 Display        *display;
22 int             screen;
23 Window          window;
24 GC              gc, clip_gc[NUM_PIXMAPS];
25 Pixmap          pix[NUM_PIXMAPS];
26 Pixmap          clipmask[NUM_PIXMAPS];
27
28 #ifdef XPM_INCLUDE_FILE
29 XpmAttributes   xpm_att[NUM_PICTURES];
30 #endif
31
32 Drawable        drawto, drawto_field, backbuffer, fieldbuffer;
33 Colormap        cmap;
34
35 int             sound_pipe[2];
36 int             sound_device;
37 char           *sound_device_name = SOUND_DEVICE;
38 int             joystick_device = 0;
39 char           *joystick_device_name[2] = { DEV_JOYSTICK_0, DEV_JOYSTICK_1 };
40 char           *level_directory = LEVEL_PATH;
41 int             width, height;
42 unsigned long   pen_fg, pen_bg;
43
44 int             game_status = MAINMENU;
45 int             game_emulation = EMU_NONE;
46 int             button_status = MB_NOT_PRESSED, motion_status = FALSE;
47 int             key_joystick_mapping = 0;
48 int             global_joystick_status = JOYSTICK_STATUS;
49 int             joystick_status = JOYSTICK_STATUS;
50 int             sound_status = SOUND_STATUS, sound_on = TRUE;
51 int             sound_loops_allowed = FALSE, sound_loops_on = FALSE;
52 int             sound_music_on = FALSE;
53 int             sound_simple_on = FALSE;
54 int             toons_on = TRUE;
55 int             direct_draw_on = FALSE;
56 int             scroll_delay_on = FALSE;
57 int             soft_scrolling_on = TRUE;
58 int             fading_on = FALSE;
59 int             autorecord_on = FALSE;
60 int             joystick_nr = 0;
61 int             quick_doors = FALSE;
62
63 BOOL            redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
64 int             redraw_x1 = 0, redraw_y1 = 0;
65 int             redraw_mask;
66 int             redraw_tiles;
67
68 int             Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
69 int             Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
70 int             MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
71 int             MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
72 int             MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
73 int             Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
74 int             Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
75 int             Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
76 int             Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
77 int             JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
78 int             AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
79 int             AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
80 long            Elementeigenschaften[MAX_ELEMENTS];
81
82 int             level_nr, leveldir_nr, num_leveldirs;
83 int             lev_fieldx,lev_fieldy, scroll_x,scroll_y;
84
85 int             FX = SX, FY = SY, ScreenMovPos = 0;
86 int             BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
87 int             JX,JY, JX2,JY2, ZX,ZY, ExitX,ExitY;
88 int             PlayerMovDir, PlayerMovPos, PlayerFrame, PlayerPushing;
89 int             PlayerGone,LevelSolved,GameOver;
90 int             FrameCounter,TimeFrames,TimeLeft,Score;
91 int             Gems,SokobanFields,Lights,Friends;
92 int             Dynamite,Key[4],MampferNr;
93 int             DynaBombCount, DynaBombSize, DynaBombsLeft, DynaBombXL;
94 int             SiebAktiv;
95
96 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
97 struct LevelInfo        level;
98 struct PlayerInfo       player;
99 struct HiScore          highscore[MAX_SCORE_ENTRIES];
100 struct SoundInfo        Sound[NUM_SOUNDS];
101 struct RecordingInfo    tape;
102
103 struct JoystickInfo joystick[2] =
104 {
105   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
106     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE },
107   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
108     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE }
109 };
110
111 /* data needed for playing sounds */
112 char *sound_name[NUM_SOUNDS] =
113 {
114   "alchemy",
115   "amoebe",
116   "antigrav",
117   "autsch",
118   "blurb",
119   "bong",
120   "buing",
121   "chase",
122   "czardasz",
123   "deng",
124   "fuel",
125   "gong",
126   "halloffame",
127   "holz",
128   "hui",
129   "kabumm",
130   "kink",
131   "klapper",
132   "kling",
133   "klopf",
134   "klumpf",
135   "knack",
136   "knurk",
137   "krach",
138   "lachen",
139   "laser",
140   "miep",
141   "network",
142   "njam",
143   "oeffnen",
144   "pling",
145   "pong",
146   "pusch",
147   "quiek",
148   "quirk",
149   "rhythmloop",
150   "roaaar",
151   "roehr",
152   "rumms",
153   "schlopp",
154   "schlurf",
155   "schrff",
156   "schwirr",
157   "sirr",
158   "slurp",
159   "sproing",
160   "twilight",
161   "tyger",
162   "voyager",
163   "warnton",
164   "whoosh",
165   "zisch"
166 };
167
168 /* background music */
169 int background_loop[] =
170 {
171   SND_ALCHEMY,
172   SND_CHASE,
173   SND_NETWORK,
174   SND_CZARDASZ,
175   SND_TYGER,
176   SND_VOYAGER,
177   SND_TWILIGHT
178 };
179 int num_bg_loops = sizeof(background_loop)/sizeof(int);
180
181 char            *progname;
182
183 int main(int argc, char *argv[])
184 {
185   progname = argv[0];
186
187   if (argc>1)
188     level_directory = argv[1];
189
190   OpenAll(argc,argv);
191   EventLoop();
192   CloseAll();
193
194   exit(0);
195 }