rnd-19981003-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             networking = 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 int             TestPlayer = 0;
110
111 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
112 struct LevelInfo        level;
113 struct PlayerInfo       stored_player[MAX_PLAYERS+1];
114 struct PlayerInfo      *local_player;
115 struct HiScore          highscore[MAX_SCORE_ENTRIES];
116 struct SoundInfo        Sound[NUM_SOUNDS];
117 struct RecordingInfo    tape;
118
119 struct JoystickInfo joystick[2] =
120 {
121   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
122     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE },
123   { JOYSTICK_XLEFT, JOYSTICK_XRIGHT, JOYSTICK_XMIDDLE,
124     JOYSTICK_YUPPER, JOYSTICK_YLOWER, JOYSTICK_YMIDDLE }
125 };
126
127 /* data needed for playing sounds */
128 char *sound_name[NUM_SOUNDS] =
129 {
130   "alchemy",
131   "amoebe",
132   "antigrav",
133   "autsch",
134   "blurb",
135   "bong",
136   "buing",
137   "chase",
138   "czardasz",
139   "deng",
140   "fuel",
141   "gong",
142   "halloffame",
143   "holz",
144   "hui",
145   "kabumm",
146   "kink",
147   "klapper",
148   "kling",
149   "klopf",
150   "klumpf",
151   "knack",
152   "knurk",
153   "krach",
154   "lachen",
155   "laser",
156   "miep",
157   "network",
158   "njam",
159   "oeffnen",
160   "pling",
161   "pong",
162   "pusch",
163   "quiek",
164   "quirk",
165   "rhythmloop",
166   "roaaar",
167   "roehr",
168   "rumms",
169   "schlopp",
170   "schlurf",
171   "schrff",
172   "schwirr",
173   "sirr",
174   "slurp",
175   "sproing",
176   "twilight",
177   "tyger",
178   "voyager",
179   "warnton",
180   "whoosh",
181   "zisch"
182 };
183
184 /* background music */
185 int background_loop[] =
186 {
187   SND_ALCHEMY,
188   SND_CHASE,
189   SND_NETWORK,
190   SND_CZARDASZ,
191   SND_TYGER,
192   SND_VOYAGER,
193   SND_TWILIGHT
194 };
195 int num_bg_loops = sizeof(background_loop)/sizeof(int);
196
197 int main(int argc, char *argv[])
198 {
199   program_name = (strrchr(argv[0],'/') ? strrchr(argv[0],'/') + 1 : argv[0]);
200
201 #ifdef MSDOS
202   _fmode = O_BINARY;
203 #endif
204
205   GetOptions(argv);
206   OpenAll(argc,argv);
207   EventLoop();
208   CloseAllAndExit(0);
209   exit(0);      /* to keep compilers happy */
210 }