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