rnd-19981120-1
[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 /*
54 int             width, height;
55 */
56
57 char           *program_name = NULL;
58
59 int             game_status = MAINMENU;
60 int             game_emulation = EMU_NONE;
61 boolean         network_playing = FALSE;
62 int             button_status = MB_NOT_PRESSED;
63 boolean         motion_status = FALSE;
64 int             key_joystick_mapping = 0;
65 int             global_joystick_status = JOYSTICK_STATUS;
66 int             joystick_status = JOYSTICK_STATUS;
67 int             sound_status = SOUND_STATUS;
68 boolean         sound_loops_allowed = FALSE;
69
70 boolean         redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
71 int             redraw_x1 = 0, redraw_y1 = 0;
72 int             redraw_mask;
73 int             redraw_tiles;
74
75 short           Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
76 short           Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
77 short           MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
78 short           MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
79 short           MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
80 short           Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
81 short           Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
82 short           StorePlayer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
83 short           Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
84 boolean         Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
85 short           JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
86 short           AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
87 short           AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
88 unsigned long   Elementeigenschaften[MAX_ELEMENTS];
89
90 int             level_nr, leveldir_nr, num_leveldirs;
91 int             lev_fieldx,lev_fieldy, scroll_x,scroll_y;
92
93 int             FX = SX, FY = SY, ScrollStepSize = TILEX/8;
94 int             ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0;
95 int             ScreenGfxPos = 0;
96 int             GameFrameDelay = GAME_FRAME_DELAY;
97 int             FfwdFrameDelay = FFWD_FRAME_DELAY;
98 int             MoveSpeed = 8;
99 int             BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
100 int             ZX,ZY, ExitX,ExitY;
101 int             AllPlayersGone;
102 int             FrameCounter, TimeFrames, TimeLeft;
103 int             MampferNr, SiebAktiv;
104
105 boolean         network_player_action_received = FALSE;
106 int             TestPlayer = 0;
107
108 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
109 struct LevelInfo        level;
110 struct PlayerInfo       stored_player[MAX_PLAYERS], *local_player = NULL;
111 struct HiScore          highscore[MAX_SCORE_ENTRIES];
112 struct SoundInfo        Sound[NUM_SOUNDS];
113 struct RecordingInfo    tape;
114 struct OptionInfo       options;
115 struct SetupInfo        setup;
116 struct SetupFileList    *setup_list = NULL;
117 struct SetupFileList    *level_setup_list = NULL;
118
119 /* data needed for playing sounds */
120 char *sound_name[NUM_SOUNDS] =
121 {
122   "alchemy",
123   "amoebe",
124   "antigrav",
125   "autsch",
126   "blurb",
127   "bong",
128   "buing",
129   "chase",
130   "czardasz",
131   "deng",
132   "fuel",
133   "gong",
134   "halloffame",
135   "holz",
136   "hui",
137   "kabumm",
138   "kink",
139   "klapper",
140   "kling",
141   "klopf",
142   "klumpf",
143   "knack",
144   "knurk",
145   "krach",
146   "lachen",
147   "laser",
148   "miep",
149   "network",
150   "njam",
151   "oeffnen",
152   "pling",
153   "pong",
154   "pusch",
155   "quiek",
156   "quirk",
157   "rhythmloop",
158   "roaaar",
159   "roehr",
160   "rumms",
161   "schlopp",
162   "schlurf",
163   "schrff",
164   "schwirr",
165   "sirr",
166   "slurp",
167   "sproing",
168   "twilight",
169   "tyger",
170   "voyager",
171   "warnton",
172   "whoosh",
173   "zisch"
174 };
175
176 /* background music */
177 int background_loop[] =
178 {
179   SND_ALCHEMY,
180   SND_CHASE,
181   SND_NETWORK,
182   SND_CZARDASZ,
183   SND_TYGER,
184   SND_VOYAGER,
185   SND_TWILIGHT
186 };
187 int num_bg_loops = sizeof(background_loop)/sizeof(int);
188
189 int main(int argc, char *argv[])
190 {
191   program_name = (strrchr(argv[0],'/') ? strrchr(argv[0],'/') + 1 : argv[0]);
192
193 #ifdef MSDOS
194   _fmode = O_BINARY;
195 #endif
196
197   GetOptions(argv);
198   OpenAll(argc,argv);
199   EventLoop();
200   CloseAllAndExit(0);
201   exit(0);      /* to keep compilers happy */
202 }