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