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