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