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