Fix crash if Num_walls=0
[btb/d2x.git] / main / mglobal.c
1 /* $Id: mglobal.c,v 1.5 2004-08-28 23:17:45 schaffner Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Global variables for main directory
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #ifdef RCS
26 static char rcsid[] = "$Id: mglobal.c,v 1.5 2004-08-28 23:17:45 schaffner Exp $";
27 #endif
28
29 #include "fix.h"
30 #include "vecmat.h"
31 #include "inferno.h"
32 #include "segment.h"
33 #include "object.h"
34 #include "bm.h"
35 #include "3d.h"
36 #include "game.h"
37
38
39 // Global array of vertices, common to one mine.
40 vms_vector Vertices[MAX_VERTICES];
41 g3s_point Segment_points[MAX_VERTICES];
42
43 fix FrameTime = 0x1000; // Time since last frame, in seconds
44 fix GameTime = 0;                       //      Time in game, in seconds
45
46 //How many frames we've rendered
47 int FrameCount = 0;
48
49 //      This is the global mine which create_new_mine returns.
50 segment Segments[MAX_SEGMENTS];
51 segment2        Segment2s[MAX_SEGMENTS];
52 //lsegment      Lsegments[MAX_SEGMENTS];
53
54 // Number of vertices in current mine (ie, Vertices, pointed to by Vp)
55 int             Num_vertices = 0;
56 int             Num_segments = 0;
57
58 int             Highest_vertex_index=0;
59 int             Highest_segment_index=0;
60
61 //      Translate table to get opposite side of a face on a segment.
62 char    Side_opposite[MAX_SIDES_PER_SEGMENT] = {WRIGHT, WBOTTOM, WLEFT, WTOP, WFRONT, WBACK};
63
64 #define TOLOWER(c) ((((c)>='A') && ((c)<='Z'))?((c)+('a'-'A')):(c))
65
66 #ifdef PASSWORD
67 #define encrypt(a,b,c,d)        a ^ TOLOWER((((int) PASSWORD)>>24)&255), \
68                                                                         b ^ TOLOWER((((int) PASSWORD)>>16)&255), \
69                                                                         c ^ TOLOWER((((int) PASSWORD)>>8)&255), \
70                                                                         d ^ TOLOWER((((int) PASSWORD))&255)
71 #else
72 #define encrypt(a,b,c,d) a,b,c,d
73 #endif
74
75 sbyte Side_to_verts[MAX_SIDES_PER_SEGMENT][4] = {
76                         { encrypt(7,6,2,3) },                   // left
77                         { encrypt(0,4,7,3) },                   // top
78                         { encrypt(0,1,5,4) },                   // right
79                         { encrypt(2,6,5,1) },                   // bottom
80                         { encrypt(4,5,6,7) },                   // back
81                         { encrypt(3,2,1,0) },                   // front
82 };              
83
84 //      Note, this MUST be the same as Side_to_verts, it is an int for speed reasons.
85 int Side_to_verts_int[MAX_SIDES_PER_SEGMENT][4] = {
86                         { encrypt(7,6,2,3) },                   // left
87                         { encrypt(0,4,7,3) },                   // top
88                         { encrypt(0,1,5,4) },                   // right
89                         { encrypt(2,6,5,1) },                   // bottom
90                         { encrypt(4,5,6,7) },                   // back
91                         { encrypt(3,2,1,0) },                   // front
92 };              
93
94 // Texture map stuff
95
96 int NumTextures = 0;
97 bitmap_index Textures[MAX_TEXTURES];            // All textures.
98
99 fix     Next_laser_fire_time;                   //      Time at which player can next fire his selected laser.
100 fix     Next_missile_fire_time;                 //      Time at which player can next fire his selected missile.
101 //--unused-- fix        Laser_delay_time = F1_0/6;              //      Delay between laser fires.
102
103 #if defined(MACINTOSH) && defined(APPLE_DEMO)
104 #define DEFAULT_DIFFICULTY              0               // trainee for apple demo
105 #else
106 #define DEFAULT_DIFFICULTY              1
107 #endif
108
109 int     Difficulty_level=DEFAULT_DIFFICULTY;    //      Difficulty level in 0..NDL-1, 0 = easiest, NDL-1 = hardest
110 int     Detail_level=NUM_DETAIL_LEVELS-2;               //      Detail level in 0..NUM_DETAIL_LEVELS-1, 0 = boringest, NUM_DETAIL_LEVELS = coolest
111