rnd-19990108-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 USE_XPM_LIBRARY
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           *program_name = NULL;
54
55 int             game_status = MAINMENU;
56 boolean         level_editor_test_game = FALSE;
57 boolean         network_playing = FALSE;
58 int             button_status = MB_NOT_PRESSED;
59 boolean         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;
64 boolean         sound_loops_allowed = FALSE;
65
66 boolean         redraw[MAX_BUF_XSIZE][MAX_BUF_YSIZE];
67 int             redraw_x1 = 0, redraw_y1 = 0;
68 int             redraw_mask;
69 int             redraw_tiles;
70
71 short           Feld[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
72 short           Ur[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
73 short           MovPos[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
74 short           MovDir[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
75 short           MovDelay[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
76 short           Store[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
77 short           Store2[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
78 short           StorePlayer[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
79 short           Frame[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
80 boolean         Stop[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
81 short           JustHit[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
82 short           AmoebaNr[MAX_LEV_FIELDX][MAX_LEV_FIELDY];
83 short           AmoebaCnt[MAX_NUM_AMOEBA], AmoebaCnt2[MAX_NUM_AMOEBA];
84 unsigned long   Elementeigenschaften[MAX_ELEMENTS];
85
86 int             level_nr, leveldir_nr, num_leveldirs;
87 int             lev_fieldx,lev_fieldy, scroll_x,scroll_y;
88
89 int             FX = SX, FY = SY, ScrollStepSize = TILEX/8;
90 int             ScreenMovDir = MV_NO_MOVING, ScreenMovPos = 0;
91 int             ScreenGfxPos = 0;
92 int             BorderElement = EL_BETON;
93 int             GameFrameDelay = GAME_FRAME_DELAY;
94 int             FfwdFrameDelay = FFWD_FRAME_DELAY;
95 int             MoveSpeed = 8;
96 int             BX1 = 0, BY1 = 0, BX2 = SCR_FIELDX-1, BY2 = SCR_FIELDY-1;
97 int             SBX_Left, SBX_Right;
98 int             SBY_Upper, SBY_Lower;
99 int             ZX,ZY, ExitX,ExitY;
100 int             AllPlayersGone;
101 int             FrameCounter, TimeFrames, TimePlayed, TimeLeft;
102 int             MampferMax, MampferNr;
103 boolean         SiebAktiv;
104 int             SiebCount;
105
106 int             game_emulation = EMU_NONE;
107
108 boolean         network_player_action_received = FALSE;
109
110 struct LevelDirInfo     leveldir[MAX_LEVDIR_ENTRIES];
111 struct LevelInfo        level;
112 struct PlayerInfo       stored_player[MAX_PLAYERS], *local_player = NULL;
113 struct HiScore          highscore[MAX_SCORE_ENTRIES];
114 struct SoundInfo        Sound[NUM_SOUNDS];
115 struct TapeInfo         tape;
116 struct OptionInfo       options;
117 struct SetupInfo        setup;
118 struct SetupFileList    *setup_list = NULL;
119 struct SetupFileList    *level_setup_list = NULL;
120
121 /* data needed for playing sounds */
122 char *sound_name[NUM_SOUNDS] =
123 {
124   "alchemy",
125   "amoebe",
126   "antigrav",
127   "autsch",
128   "blurb",
129   "bong",
130   "buing",
131   "chase",
132   "czardasz",
133   "deng",
134   "fuel",
135   "gong",
136   "halloffame",
137   "holz",
138   "hui",
139   "kabumm",
140   "kink",
141   "klapper",
142   "kling",
143   "klopf",
144   "klumpf",
145   "knack",
146   "knurk",
147   "krach",
148   "lachen",
149   "laser",
150   "miep",
151   "network",
152   "njam",
153   "oeffnen",
154   "pling",
155   "pong",
156   "pusch",
157   "quiek",
158   "quirk",
159   "rhythmloop",
160   "roaaar",
161   "roehr",
162   "rumms",
163   "schlopp",
164   "schlurf",
165   "schrff",
166   "schwirr",
167   "sirr",
168   "slurp",
169   "sproing",
170   "twilight",
171   "tyger",
172   "voyager",
173   "warnton",
174   "whoosh",
175   "zisch",
176   "base",
177   "infotron",
178   "zonkdown",
179   "zonkpush",
180   "bug",
181   "boom",
182   "booom",
183   "exit",
184   "empty"
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 }