rnd-19981123-2
[rocksndiamonds.git] / src / main.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  (c) 1995-98 Artsoft Entertainment                       *
5 *              Holger Schemel                              *
6 *              Oststrasse 11a                              *
7 *              33604 Bielefeld                             *
8 *              phone: ++49 +521 290471                     *
9 *              email: aeglos@valinor.owl.de                *
10 *----------------------------------------------------------*
11 *  main.c                                                  *
12 ***********************************************************/
13
14 #include "main.h"
15 #include "init.h"
16 #include "game.h"
17 #include "events.h"
18 #include "sound.h"
19 #include "joystick.h"
20 #include "misc.h"
21
22 #ifdef MSDOS
23 #include <fcntl.h>
24 #endif
25
26 Display        *display;
27 Visual         *visual;
28 int             screen;
29 Window          window;
30 GC              gc, clip_gc[NUM_PIXMAPS], tile_clip_gc;
31 Pixmap          pix[NUM_PIXMAPS];
32 Pixmap          clipmask[NUM_PIXMAPS], tile_clipmask[NUM_TILES];
33
34 #ifdef USE_XPM_LIBRARY
35 XpmAttributes   xpm_att[NUM_PICTURES];
36 #endif
37
38 Drawable        drawto, drawto_field, backbuffer, fieldbuffer;
39 Colormap        cmap;
40
41 int             sound_pipe[2];
42 int             sound_device;
43 char           *sound_device_name = SOUND_DEVICE;
44 int             joystick_device = 0;
45 char           *joystick_device_name[MAX_PLAYERS] =
46 {
47   DEV_JOYSTICK_0,
48   DEV_JOYSTICK_1,
49   DEV_JOYSTICK_2,
50   DEV_JOYSTICK_3
51 };
52
53 char           *program_name = NULL;
54
55 int             game_status = MAINMENU;
56 boolean         network_playing = FALSE;
57 int             button_status = MB_NOT_PRESSED;
58 boolean         motion_status = FALSE;
59 int             key_joystick_mapping = 0;
60 int             global_joystick_status = JOYSTICK_STATUS;
61 int             joystick_status = JOYSTICK_STATUS;
62 int             sound_status = SOUND_STATUS;
63 boolean         sound_loops_allowed = FALSE;
64
65 boolean         redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
66 int             redraw_x1 = 0, redraw_y1 = 0;
67 int             redraw_mask;
68 int             redraw_tiles;
69
70 short           Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
71 short           Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
72 short           MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
73 short           MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
74 short           MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
75 short           Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
76 short           Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
77 short           StorePlayer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
78 short           Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
79 boolean         Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
80 short           JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
81 short           AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
82 short           AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
83 unsigned long   Elementeigenschaften[MAX_ELEMENTS];
84
85 int             level_nr, leveldir_nr, num_leveldirs;
86 int             lev_fieldx,lev_fieldy, scroll_x,scroll_y;
87
88 int             FX = SX, FY = SY, ScrollStepSize = TILEX/8;
89 int             ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0;
90 int             ScreenGfxPos = 0;
91 int             GameFrameDelay = GAME_FRAME_DELAY;
92 int             FfwdFrameDelay = FFWD_FRAME_DELAY;
93 int             MoveSpeed = 8;
94 int             BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
95 int             ZX,ZY, ExitX,ExitY;
96 int             AllPlayersGone;
97 int             FrameCounter, TimeFrames, TimeLeft;
98 int             MampferNr, SiebAktiv;
99
100 boolean         network_player_action_received = FALSE;
101 int             TestPlayer = 0;
102
103 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
104 struct LevelInfo        level;
105 struct PlayerInfo       stored_player[MAX_PLAYERS], *local_player = NULL;
106 struct HiScore          highscore[MAX_SCORE_ENTRIES];
107 struct SoundInfo        Sound[NUM_SOUNDS];
108 struct RecordingInfo    tape;
109 struct OptionInfo       options;
110 struct SetupInfo        setup;
111 struct SetupFileList    *setup_list = NULL;
112 struct SetupFileList    *level_setup_list = NULL;
113
114 /* data needed for playing sounds */
115 char *sound_name[NUM_SOUNDS] =
116 {
117   "alchemy",
118   "amoebe",
119   "antigrav",
120   "autsch",
121   "blurb",
122   "bong",
123   "buing",
124   "chase",
125   "czardasz",
126   "deng",
127   "fuel",
128   "gong",
129   "halloffame",
130   "holz",
131   "hui",
132   "kabumm",
133   "kink",
134   "klapper",
135   "kling",
136   "klopf",
137   "klumpf",
138   "knack",
139   "knurk",
140   "krach",
141   "lachen",
142   "laser",
143   "miep",
144   "network",
145   "njam",
146   "oeffnen",
147   "pling",
148   "pong",
149   "pusch",
150   "quiek",
151   "quirk",
152   "rhythmloop",
153   "roaaar",
154   "roehr",
155   "rumms",
156   "schlopp",
157   "schlurf",
158   "schrff",
159   "schwirr",
160   "sirr",
161   "slurp",
162   "sproing",
163   "twilight",
164   "tyger",
165   "voyager",
166   "warnton",
167   "whoosh",
168   "zisch"
169 };
170
171 /* background music */
172 int background_loop[] =
173 {
174   SND_ALCHEMY,
175   SND_CHASE,
176   SND_NETWORK,
177   SND_CZARDASZ,
178   SND_TYGER,
179   SND_VOYAGER,
180   SND_TWILIGHT
181 };
182 int num_bg_loops = sizeof(background_loop)/sizeof(int);
183
184 int main(int argc, char *argv[])
185 {
186   program_name = (strrchr(argv[0],'/') ? strrchr(argv[0],'/') + 1 : argv[0]);
187
188 #ifdef MSDOS
189   _fmode = O_BINARY;
190 #endif
191
192   GetOptions(argv);
193   OpenAll(argc,argv);
194   EventLoop();
195   CloseAllAndExit(0);
196   exit(0);      /* to keep compilers happy */
197 }