]> icculus.org git repositories - btb/d2x.git/blob - main/mglobal.c
fix win32 eof bug
[btb/d2x.git] / main / mglobal.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Global variables for main directory
17  *
18  * Old Log:
19  * Revision 1.1  1995/12/05  16:03:10  allender
20  * Initial revision
21  *
22  * Revision 1.3  1995/10/10  11:49:41  allender
23  * removed malloc of static data now in ai module
24  *
25  * Revision 1.2  1995/07/12  12:48:52  allender
26  * malloc out edge_list global here, not static in automap.c
27  *
28  * Revision 1.1  1995/05/16  15:27:40  allender
29  * Initial revision
30  *
31  * Revision 2.2  1995/03/14  18:24:37  john
32  * Force Destination Saturn to use CD-ROM drive.
33  *
34  * Revision 2.1  1995/03/06  16:47:23  mike
35  * destination saturn
36  *
37  * Revision 2.0  1995/02/27  11:30:00  john
38  * New version 2.0, which has no anonymous unions, builds with
39  * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
40  *
41  * Revision 1.43  1995/01/19  17:00:53  john
42  * Made save game work between levels.
43  *
44  * Revision 1.42  1994/12/05  14:23:53  adam
45  * changed default detail to max, not custom
46  *
47  * Revision 1.41  1994/11/19  15:15:07  mike
48  * remove unused code and data
49  *
50  * Revision 1.40  1994/11/03  10:13:19  yuan
51  * Added #include "game.h"
52  *
53  * Revision 1.39  1994/11/03  10:09:59  matt
54  * Properly initialize detail & difficulty levels
55  *
56  * Revision 1.38  1994/10/30  14:11:21  mike
57  * rip out local segments stuff.
58  *
59  * Revision 1.37  1994/10/26  15:21:30  mike
60  * detail level.
61  *
62  * Revision 1.36  1994/09/22  10:46:12  mike
63  * Add difficulty levels.
64  *
65  * Revision 1.35  1994/09/13  11:19:11  mike
66  * Add Next_missile_fire_time.
67  *
68  * Revision 1.34  1994/08/31  19:25:34  mike
69  * GameTime and laser-firing limiting stuff added.
70  *
71  * Revision 1.33  1994/08/11  18:58:53  mike
72  * Add Side_to_verts_int.
73  *
74  * Revision 1.32  1994/07/21  19:01:38  mike
75  * Add Lsegment.
76  *
77  * Revision 1.31  1994/07/21  13:11:24  matt
78  * Ripped out remants of old demo system, and added demo only system that
79  * disables object movement and game options from menu.
80  *
81  * Revision 1.30  1994/06/17  18:06:48  matt
82  * Made password be treated as lowercase, since cmdline parsing converts
83  * everything to lowercase.
84  *
85  * Revision 1.29  1994/03/15  16:33:04  yuan
86  * Cleaned up bm-loading code.
87  * (Fixed structures too)
88  *
89  * Revision 1.28  1994/02/17  11:32:45  matt
90  * Changes in object system
91  *
92  * Revision 1.27  1994/02/16  17:08:43  matt
93  * Added needed include of 3d.h
94  *
95  * Revision 1.26  1994/02/16  13:47:58  mike
96  * fix bugs so editor can compile out.
97  *
98  * Revision 1.25  1994/02/11  21:52:13  matt
99  * Made password protection selectable by #define (and thus INFERNO.INI)
100  *
101  * Revision 1.24  1994/02/10  15:35:56  matt
102  * Various changes to make editor compile out.
103  *
104  * Revision 1.23  1994/02/02  12:34:29  mike
105  * take out BATS encryption.
106  *
107  * Revision 1.22  1994/01/21  16:08:11  matt
108  * Added FrameCount variable
109  *
110  * Revision 1.21  1994/01/06  17:13:10  john
111  * Added Video clip functionality
112  *
113  * Revision 1.20  1993/12/08  17:45:08  matt
114  * Changed password again
115  *
116  * Revision 1.19  1993/12/08  17:41:05  matt
117  * Changed password
118  *
119  * Revision 1.18  1993/12/08  10:55:10  mike
120  * Add free_obj_list
121  *
122  * Revision 1.17  1993/12/07  13:46:38  john
123  * Added Explosion bitmap array
124  *
125  * Revision 1.16  1993/12/06  18:40:35  matt
126  * Changed object loading & handling
127  *
128  * Revision 1.15  1993/12/05  22:47:48  matt
129  * Reworked include files in an attempt to cut down on build times
130  *
131  * Revision 1.14  1993/12/01  11:44:11  matt
132  * Chagned Frfract to FrameTime
133  *
134  * Revision 1.13  1993/12/01  00:27:11  yuan
135  * Implemented new bitmap structure system...
136  * overall bitmap scheme still needs some work.
137  *
138  * Revision 1.12  1993/11/19  17:21:59  matt
139  * Changed the bitmap number of object class UNICLASS
140  * Removed static initialization for objects
141  *
142  * Revision 1.11  1993/11/18  13:51:47  mike
143  * Add Classes, Class_views, Objects
144  *
145  * Revision 1.10  1993/11/04  18:52:36  matt
146  * Made Vertices[] and Segment_points[] use same constant for size, since
147  * they must be the same size anyway
148  *
149  * Revision 1.9  1993/11/04  14:01:06  matt
150  * Mucked with include files
151  *
152  * Revision 1.8  1993/10/26  13:58:42  mike
153  * Add password protection.
154  *
155  * Revision 1.7  1993/10/14  18:05:50  mike
156  * Change Side_to_verts to use MAX_SIDES_PER_SEGMENT in place of CONNECTIVITY
157  *
158  * Revision 1.6  1993/10/12  13:57:19  john
159  * added texture[]
160  *
161  * Revision 1.5  1993/10/12  09:58:15  mike
162  * Move Side_to_verts here from eglobal.c, since it is needed in the game.
163  *
164  * Revision 1.4  1993/10/09  15:52:30  mike
165  * Move test_pos, test_orient here from render.c.
166  *
167  * Revision 1.3  1993/10/02  18:15:45  mike
168  * Killed include of segment.h, which gets included by inferno.h.
169  *
170  * Revision 1.2  1993/09/23  17:54:24  mike
171  * Add Segment_points
172  *
173  * Revision 1.1  1993/09/23  15:01:50  mike
174  * Initial revision
175  *
176  *
177  */
178
179 #ifdef HAVE_CONFIG_H
180 #include <conf.h>
181 #endif
182
183 #ifdef RCS
184 static char rcsid[] = "$Id: mglobal.c,v 1.3 2003-10-04 03:14:47 btb Exp $";
185 #endif
186
187 #include "fix.h"
188 #include "vecmat.h"
189 #include "inferno.h"
190 #include "segment.h"
191 #include "object.h"
192 #include "bm.h"
193 #include "3d.h"
194 #include "game.h"
195
196
197 // Global array of vertices, common to one mine.
198 vms_vector Vertices[MAX_VERTICES];
199 g3s_point Segment_points[MAX_VERTICES];
200
201 fix FrameTime = 0x1000; // Time since last frame, in seconds
202 fix GameTime = 0;                       //      Time in game, in seconds
203
204 //How many frames we've rendered
205 int FrameCount = 0;
206
207 //      This is the global mine which create_new_mine returns.
208 segment Segments[MAX_SEGMENTS];
209 segment2        Segment2s[MAX_SEGMENTS];
210 //lsegment      Lsegments[MAX_SEGMENTS];
211
212 // Number of vertices in current mine (ie, Vertices, pointed to by Vp)
213 int             Num_vertices = 0;
214 int             Num_segments = 0;
215
216 int             Highest_vertex_index=0;
217 int             Highest_segment_index=0;
218
219 //      Translate table to get opposite side of a face on a segment.
220 char    Side_opposite[MAX_SIDES_PER_SEGMENT] = {WRIGHT, WBOTTOM, WLEFT, WTOP, WFRONT, WBACK};
221
222 #define TOLOWER(c) ((((c)>='A') && ((c)<='Z'))?((c)+('a'-'A')):(c))
223
224 #ifdef PASSWORD
225 #define encrypt(a,b,c,d)        a ^ TOLOWER((((int) PASSWORD)>>24)&255), \
226                                                                         b ^ TOLOWER((((int) PASSWORD)>>16)&255), \
227                                                                         c ^ TOLOWER((((int) PASSWORD)>>8)&255), \
228                                                                         d ^ TOLOWER((((int) PASSWORD))&255)
229 #else
230 #define encrypt(a,b,c,d) a,b,c,d
231 #endif
232
233 sbyte Side_to_verts[MAX_SIDES_PER_SEGMENT][4] = {
234                         { encrypt(7,6,2,3) },                   // left
235                         { encrypt(0,4,7,3) },                   // top
236                         { encrypt(0,1,5,4) },                   // right
237                         { encrypt(2,6,5,1) },                   // bottom
238                         { encrypt(4,5,6,7) },                   // back
239                         { encrypt(3,2,1,0) },                   // front
240 };              
241
242 //      Note, this MUST be the same as Side_to_verts, it is an int for speed reasons.
243 int Side_to_verts_int[MAX_SIDES_PER_SEGMENT][4] = {
244                         { encrypt(7,6,2,3) },                   // left
245                         { encrypt(0,4,7,3) },                   // top
246                         { encrypt(0,1,5,4) },                   // right
247                         { encrypt(2,6,5,1) },                   // bottom
248                         { encrypt(4,5,6,7) },                   // back
249                         { encrypt(3,2,1,0) },                   // front
250 };              
251
252 // Texture map stuff
253
254 int NumTextures = 0;
255 bitmap_index Textures[MAX_TEXTURES];            // All textures.
256
257 fix     Next_laser_fire_time;                   //      Time at which player can next fire his selected laser.
258 fix     Next_missile_fire_time;                 //      Time at which player can next fire his selected missile.
259 //--unused-- fix        Laser_delay_time = F1_0/6;              //      Delay between laser fires.
260
261 #if defined(MACINTOSH) && defined(APPLE_DEMO)
262 #define DEFAULT_DIFFICULTY              0               // trainee for apple demo
263 #else
264 #define DEFAULT_DIFFICULTY              1
265 #endif
266
267 int     Difficulty_level=DEFAULT_DIFFICULTY;    //      Difficulty level in 0..NDL-1, 0 = easiest, NDL-1 = hardest
268 int     Detail_level=NUM_DETAIL_LEVELS-2;               //      Detail level in 0..NUM_DETAIL_LEVELS-1, 0 = boringest, NUM_DETAIL_LEVELS = coolest
269