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