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