rnd-19980828
[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, ScrollStepSize = TILEX/8;
86 int             BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
87 int             JX,JY, lastJX,lastJY, ZX,ZY, ExitX,ExitY;
88 int             PlayerMovDir, PlayerMovPos, PlayerPushing;
89 int             PlayerFrame, PlayerGfxPos;
90 int             PlayerGone, LevelSolved, GameOver;
91 int             FrameCounter, TimeFrames, TimeLeft, Score;
92 int             Gems, SokobanFields, Lights, Friends;
93 int             Dynamite, Key[4], MampferNr;
94 int             DynaBombCount, DynaBombSize, DynaBombsLeft, DynaBombXL;
95 int             SiebAktiv;
96
97 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
98 struct LevelInfo        level;
99 struct PlayerInfo       player;
100 struct HiScore          highscore[MAX_SCORE_ENTRIES];
101 struct SoundInfo        Sound[NUM_SOUNDS];
102 struct RecordingInfo    tape;
103
104 struct JoystickInfo joystick[2] =
105 {
106   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
107     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE },
108   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
109     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE }
110 };
111
112 /* data needed for playing sounds */
113 char *sound_name[NUM_SOUNDS] =
114 {
115   "alchemy",
116   "amoebe",
117   "antigrav",
118   "autsch",
119   "blurb",
120   "bong",
121   "buing",
122   "chase",
123   "czardasz",
124   "deng",
125   "fuel",
126   "gong",
127   "halloffame",
128   "holz",
129   "hui",
130   "kabumm",
131   "kink",
132   "klapper",
133   "kling",
134   "klopf",
135   "klumpf",
136   "knack",
137   "knurk",
138   "krach",
139   "lachen",
140   "laser",
141   "miep",
142   "network",
143   "njam",
144   "oeffnen",
145   "pling",
146   "pong",
147   "pusch",
148   "quiek",
149   "quirk",
150   "rhythmloop",
151   "roaaar",
152   "roehr",
153   "rumms",
154   "schlopp",
155   "schlurf",
156   "schrff",
157   "schwirr",
158   "sirr",
159   "slurp",
160   "sproing",
161   "twilight",
162   "tyger",
163   "voyager",
164   "warnton",
165   "whoosh",
166   "zisch"
167 };
168
169 /* background music */
170 int background_loop[] =
171 {
172   SND_ALCHEMY,
173   SND_CHASE,
174   SND_NETWORK,
175   SND_CZARDASZ,
176   SND_TYGER,
177   SND_VOYAGER,
178   SND_TWILIGHT
179 };
180 int num_bg_loops = sizeof(background_loop)/sizeof(int);
181
182 char            *progname;
183
184 int main(int argc, char *argv[])
185 {
186   progname = argv[0];
187
188   if (argc>1)
189     level_directory = argv[1];
190
191   OpenAll(argc,argv);
192   EventLoop();
193   CloseAll();
194
195   exit(0);
196 }