1 // "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
2 // Ken Silverman's official web site: "http://www.advsys.net/ken"
3 // See the included license file "BUILDLIC.TXT" for license info.
4 // This file has been modified from Ken Silverman's original release
5 
6 #define MAXSECTORS 1024
7 #define MAXWALLS 8192
8 #define MAXSPRITES 4096
9 
10 #define MAXTILES 6144
11 #define MAXSTATUS 1024
12 #define MAXPLAYERS 16
13 #define MAXXDIM 1600
14 #define MAXYDIM 1200
15 #define MAXPALOOKUPS 256
16 #define MAXPSKYTILES 256
17 #define MAXSPRITESONSCREEN 1024
18 
19 #define CLIPMASK0 (((1L)<<16)+1L)
20 #define CLIPMASK1 (((256L)<<16)+64L)
21 
22 	//Make all variables in BUILD.H defined in the ENGINE,
23 	//and externed in GAME
24 #ifdef ENGINE
25 	#define EXTERN
26 #else
27 	#define EXTERN extern
28 #endif
29 
30 #pragma pack(push,1);
31 
32 //ceilingstat/floorstat:
33 //   bit 0: 1 = parallaxing, 0 = not                                 "P"
34 //   bit 1: 1 = groudraw, 0 = not
35 //   bit 2: 1 = swap x&y, 0 = not                                    "F"
36 //   bit 3: 1 = double smooshiness                                   "E"
37 //   bit 4: 1 = x-flip                                               "F"
38 //   bit 5: 1 = y-flip                                               "F"
39 //   bit 6: 1 = Align texture to first wall of sector                "R"
40 //   bits 7-8:                                                       "T"
41 //          00 = normal floors
42 //          01 = masked floors
43 //          10 = transluscent masked floors
44 //          11 = reverse transluscent masked floors
45 //   bits 9-15: reserved
46 
47 	//40 bytes
48 typedef struct
49 {
50 	short wallptr, wallnum;
51 	long ceilingz, floorz;
52 	short ceilingstat, floorstat;
53 	short ceilingpicnum, ceilingheinum;
54 	signed char ceilingshade;
55 	char ceilingpal, ceilingxpanning, ceilingypanning;
56 	short floorpicnum, floorheinum;
57 	signed char floorshade;
58 	char floorpal, floorxpanning, floorypanning;
59 	char visibility, filler;
60 	short lotag, hitag, extra;
61 } sectortype;
62 
63 //cstat:
64 //   bit 0: 1 = Blocking wall (use with clipmove, getzrange)         "B"
65 //   bit 1: 1 = bottoms of invisible walls swapped, 0 = not          "2"
66 //   bit 2: 1 = align picture on bottom (for doors), 0 = top         "O"
67 //   bit 3: 1 = x-flipped, 0 = normal                                "F"
68 //   bit 4: 1 = masking wall, 0 = not                                "M"
69 //   bit 5: 1 = 1-way wall, 0 = not                                  "1"
70 //   bit 6: 1 = Blocking wall (use with hitscan / cliptype 1)        "H"
71 //   bit 7: 1 = Transluscence, 0 = not                               "T"
72 //   bit 8: 1 = y-flipped, 0 = normal                                "F"
73 //   bit 9: 1 = Transluscence reversing, 0 = normal                  "T"
74 //   bits 10-15: reserved
75 
76 	//32 bytes
77 typedef struct
78 {
79 	long x, y;
80 	short point2, nextwall, nextsector, cstat;
81 	short picnum, overpicnum;
82 	signed char shade;
83 	char pal, xrepeat, yrepeat, xpanning, ypanning;
84 	short lotag, hitag, extra;
85 } walltype;
86 
87 //cstat:
88 //   bit 0: 1 = Blocking sprite (use with clipmove, getzrange)       "B"
89 //   bit 1: 1 = transluscence, 0 = normal                            "T"
90 //   bit 2: 1 = x-flipped, 0 = normal                                "F"
91 //   bit 3: 1 = y-flipped, 0 = normal                                "F"
92 //   bits 5-4: 00 = FACE sprite (default)                            "R"
93 //             01 = WALL sprite (like masked walls)
94 //             10 = FLOOR sprite (parallel to ceilings&floors)
95 //   bit 6: 1 = 1-sided sprite, 0 = normal                           "1"
96 //   bit 7: 1 = Real centered centering, 0 = foot center             "C"
97 //   bit 8: 1 = Blocking sprite (use with hitscan / cliptype 1)      "H"
98 //   bit 9: 1 = Transluscence reversing, 0 = normal                  "T"
99 //   bits 10-14: reserved
100 //   bit 15: 1 = Invisible sprite, 0 = not invisible
101 
102 	//44 bytes
103 typedef struct
104 {
105 	long x, y, z;
106 	short cstat, picnum;
107 	signed char shade;
108 	char pal, clipdist, filler;
109 	unsigned char xrepeat, yrepeat;
110 	signed char xoffset, yoffset;
111 	short sectnum, statnum;
112 	short ang, owner, xvel, yvel, zvel;
113 	short lotag, hitag, extra;
114 } spritetype;
115 
116 #pragma pack(pop);
117 
118 EXTERN sectortype sector[MAXSECTORS];
119 EXTERN walltype wall[MAXWALLS];
120 EXTERN spritetype sprite[MAXSPRITES];
121 
122 EXTERN long spritesortcnt;
123 EXTERN spritetype tsprite[MAXSPRITESONSCREEN];
124 
125 EXTERN char vidoption;
126 EXTERN long xdim, ydim, ylookup[MAXYDIM+1], numpages;
127 EXTERN long yxaspect, viewingrange;
128 
129 EXTERN long validmodecnt;
130 EXTERN short validmode[256];
131 EXTERN long validmodexdim[256], validmodeydim[256];
132 
133 EXTERN short numsectors, numwalls;
134 EXTERN volatile long totalclock;
135 EXTERN long numframes, randomseed;
136 EXTERN short sintable[2048];
137 EXTERN char palette[768];
138 EXTERN short numpalookups;
139 EXTERN char *palookup[MAXPALOOKUPS];
140 EXTERN char parallaxtype, showinvisibility;
141 EXTERN long parallaxyoffs, parallaxyscale;
142 EXTERN long visibility, parallaxvisibility;
143 
144 EXTERN long windowx1, windowy1, windowx2, windowy2;
145 EXTERN short startumost[MAXXDIM], startdmost[MAXXDIM];
146 
147 EXTERN short pskyoff[MAXPSKYTILES], pskybits;
148 
149 EXTERN short headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1];
150 EXTERN short prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES];
151 EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES];
152 
153 EXTERN short tilesizx[MAXTILES], tilesizy[MAXTILES];
154 EXTERN char walock[MAXTILES];
155 EXTERN long numtiles, picanm[MAXTILES], waloff[MAXTILES];
156 
157 	//These variables are for auto-mapping with the draw2dscreen function.
158 	//When you load a new board, these bits are all set to 0 - since
159 	//you haven't mapped out anything yet.  Note that these arrays are
160 	//bit-mapped.
161 	//If you want draw2dscreen() to show sprite #54 then you say:
162 	//   spritenum = 54;
163 	//   show2dsprite[spritenum>>3] |= (1<<(spritenum&7));
164 	//And if you want draw2dscreen() to not show sprite #54 then you say:
165 	//   spritenum = 54;
166 	//   show2dsprite[spritenum>>3] &= ~(1<<(spritenum&7));
167 	//Automapping defaults to 0 (do nothing).  If you set automapping to 1,
168 	//   then in 3D mode, the walls and sprites that you see will show up the
169 	//   next time you flip to 2D mode.
170 
171 EXTERN char show2dsector[(MAXSECTORS+7)>>3];
172 EXTERN char show2dwall[(MAXWALLS+7)>>3];
173 EXTERN char show2dsprite[(MAXSPRITES+7)>>3];
174 EXTERN char automapping;
175 
176 EXTERN char gotpic[(MAXTILES+7)>>3];
177 EXTERN char gotsector[(MAXSECTORS+7)>>3];
178 
179 /*************************************************************************
180 POSITION VARIABLES:
181 
182 		POSX is your x - position ranging from 0 to 65535
183 		POSY is your y - position ranging from 0 to 65535
184 			(the length of a side of the grid in EDITBORD would be 1024)
185 		POSZ is your z - position (height) ranging from 0 to 65535, 0 highest.
186 		ANG is your angle ranging from 0 to 2047.  Instead of 360 degrees, or
187 			 2 * PI radians, I use 2048 different angles, so 90 degrees would
188 			 be 512 in my system.
189 
190 SPRITE VARIABLES:
191 
192 	EXTERN short headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1];
193 	EXTERN short prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES];
194 	EXTERN short nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES];
195 
196 	Example: if the linked lists look like the following:
197 		 ��������������������������������������������������������������Ŀ
198 		 �      Sector lists:               Status lists:               �
199 		 ��������������������������������������������������������������Ĵ
200 		 �  Sector0:  4, 5, 8             Status0:  2, 0, 8             �
201 		 �  Sector1:  16, 2, 0, 7         Status1:  4, 5, 16, 7, 3, 9   �
202 		 �  Sector2:  3, 9                                              �
203 		 ����������������������������������������������������������������
204 	Notice that each number listed above is shown exactly once on both the
205 		left and right side.  This is because any sprite that exists must
206 		be in some sector, and must have some kind of status that you define.
207 
208 
209 Coding example #1:
210 	To go through all the sprites in sector 1, the code can look like this:
211 
212 		sectnum = 1;
213 		i = headspritesect[sectnum];
214 		while (i != -1)
215 		{
216 			nexti = nextspritesect[i];
217 
218 			//your code goes here
219 			//ex: printf("Sprite %d is in sector %d\n",i,sectnum);
220 
221 			i = nexti;
222 		}
223 
224 Coding example #2:
225 	To go through all sprites with status = 1, the code can look like this:
226 
227 		statnum = 1;        //status 1
228 		i = headspritestat[statnum];
229 		while (i != -1)
230 		{
231 			nexti = nextspritestat[i];
232 
233 			//your code goes here
234 			//ex: printf("Sprite %d has a status of 1 (active)\n",i,statnum);
235 
236 			i = nexti;
237 		}
238 
239 			 insertsprite(short sectnum, short statnum);
240 			 deletesprite(short spritenum);
241 			 changespritesect(short spritenum, short newsectnum);
242 			 changespritestat(short spritenum, short newstatnum);
243 
244 TILE VARIABLES:
245 		NUMTILES - the number of tiles found TILES.DAT.
246 		TILESIZX[MAXTILES] - simply the x-dimension of the tile number.
247 		TILESIZY[MAXTILES] - simply the y-dimension of the tile number.
248 		WALOFF[MAXTILES] - the actual 32-bit offset pointing to the top-left
249 								 corner of the tile.
250 		PICANM[MAXTILES] - flags for animating the tile.
251 
252 TIMING VARIABLES:
253 		TOTALCLOCK - When the engine is initialized, TOTALCLOCK is set to zero.
254 			From then on, it is incremented 120 times a second by 1.  That
255 			means that the number of seconds elapsed is totalclock / 120.
256 		NUMFRAMES - The number of times the draw3dscreen function was called
257 			since the engine was initialized.  This helps to determine frame
258 			rate.  (Frame rate = numframes * 120 / totalclock.)
259 
260 OTHER VARIABLES:
261 
262 		STARTUMOST[320] is an array of the highest y-coordinates on each column
263 				that my engine is allowed to write to.  You need to set it only
264 				once.
265 		STARTDMOST[320] is an array of the lowest y-coordinates on each column
266 				that my engine is allowed to write to.  You need to set it only
267 				once.
268 		SINTABLE[2048] is a sin table with 2048 angles rather than the
269 			normal 360 angles for higher precision.  Also since SINTABLE is in
270 			all integers, the range is multiplied by 16383, so instead of the
271 			normal -1<sin(x)<1, the range of sintable is -16383<sintable[]<16383
272 			If you use this sintable, you can possibly speed up your code as
273 			well as save space in memory.  If you plan to use sintable, 2
274 			identities you may want to keep in mind are:
275 				sintable[ang&2047]       = sin(ang * (3.141592/1024)) * 16383
276 				sintable[(ang+512)&2047] = cos(ang * (3.141592/1024)) * 16383
277 		NUMSECTORS - the total number of existing sectors.  Modified every time
278 			you call the loadboard function.
279 ***************************************************************************/
280