1 /*
2    Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4 
5    This file is part of GtkRadiant.
6 
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11 
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16 
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 
23 //
24 // qfiles.h: quake file formats
25 // This file must be identical in the quake and utils directories
26 //
27 
28 /*
29    ========================================================================
30 
31    The .pak files are just a linear collapse of a directory tree
32 
33    ========================================================================
34  */
35 
36 #define IDPAKHEADER     ( ( 'K' << 24 ) + ( 'C' << 16 ) + ( 'A' << 8 ) + 'P' )
37 
38 typedef struct
39 {
40 	char name[56];
41 	int filepos, filelen;
42 } dpackfile_t;
43 
44 typedef struct
45 {
46 	int ident;          // == IDPAKHEADER
47 	int dirofs;
48 	int dirlen;
49 } dpackheader_t;
50 
51 #define MAX_FILES_IN_PACK   6144
52 
53 
54 /*
55    ========================================================================
56 
57    PCX files are used for as many images as possible
58 
59    ========================================================================
60  */
61 
62 typedef struct
63 {
64 	char manufacturer;
65 	char version;
66 	char encoding;
67 	char bits_per_pixel;
68 	unsigned short xmin,ymin,xmax,ymax;
69 	unsigned short hres,vres;
70 	unsigned char palette[48];
71 	char reserved;
72 	char color_planes;
73 	unsigned short bytes_per_line;
74 	unsigned short palette_type;
75 	char filler[58];
76 	unsigned char data;             // unbounded
77 } pcx_t;
78 
79 /*
80    ========================================================================
81 
82    .MD2 compressed triangle model file format
83 
84    ========================================================================
85  */
86 #define IDCOMPRESSEDALIASHEADER ( ( '2' << 24 ) + ( 'C' << 16 ) + ( 'D' << 8 ) + 'I' )
87 
88 /*
89    ========================================================================
90 
91    .MD2 compressed triangle model file format
92 
93    ========================================================================
94  */
95 #define IDJOINTEDALIASHEADER    ( ( '2' << 24 ) + ( 'J' << 16 ) + ( 'D' << 8 ) + 'I' )
96 
97 /*
98    ========================================================================
99 
100    .MD2 triangle model file format
101 
102    ========================================================================
103  */
104 
105 #define IDALIASHEADER       ( ( '2' << 24 ) + ( 'P' << 16 ) + ( 'D' << 8 ) + 'I' )
106 #define ALIAS_VERSION   8
107 
108 #define MAX_TRIANGLES   4096
109 #define MAX_VERTS       2048
110 #define MAX_FRAMES      512
111 #define MAX_MD2SKINS    64
112 #define MAX_SKINNAME    64
113 
114 typedef struct
115 {
116 	short s;
117 	short t;
118 } dstvert_t;
119 
120 typedef struct
121 {
122 	short index_xyz[3];
123 	short index_st[3];
124 } dtriangle_t;
125 
126 typedef struct
127 {
128 	union
129 	{
130 		struct
131 		{
132 			byte v[3];          // scaled byte to fit in frame mins/maxs
133 			byte lightnormalindex;
134 		};
135 
136 		int vert;
137 	};
138 } dtrivertx_t;
139 
140 #define DTRIVERTX_V0   0
141 #define DTRIVERTX_V1   1
142 #define DTRIVERTX_V2   2
143 #define DTRIVERTX_LNI  3
144 #define DTRIVERTX_SIZE 4
145 
146 typedef struct
147 {
148 	float scale[3];         // multiply byte verts by this
149 	float translate[3];         // then add this
150 	char name[16];          // frame name from grabbing
151 	dtrivertx_t verts[1];   // variable sized
152 } daliasframe_t;
153 
154 
155 // the glcmd format:
156 // a positive integer starts a tristrip command, followed by that many
157 // vertex structures.
158 // a negative integer starts a trifan command, followed by -x vertexes
159 // a zero indicates the end of the command list.
160 // a vertex consists of a floating point s, a floating point t,
161 // and an integer vertex index.
162 
163 
164 typedef struct
165 {
166 	int ident;
167 	int version;
168 
169 	int skinwidth;
170 	int skinheight;
171 	int framesize;              // byte size of each frame
172 
173 	int num_skins;
174 	int num_xyz;
175 	int num_st;                 // greater than num_xyz for seams
176 	int num_tris;
177 	int num_glcmds;             // dwords in strip/fan command list
178 	int num_frames;
179 
180 	int ofs_skins;              // each skin is a MAX_SKINNAME string
181 	int ofs_st;                 // byte offset from start for stverts
182 	int ofs_tris;               // offset for dtriangles
183 	int ofs_frames;             // offset for first frame
184 	int ofs_glcmds;
185 	int ofs_end;                // end of file
186 
187 } dmdl_t;
188 
189 // compressed model
190 typedef struct dcompmdl_s
191 {
192 	dmdl_t header;
193 	short CompressedFrameSize;
194 	short UniqueVerts;
195 	short *remap;
196 	float *translate;   // then add this
197 	float *scale;   // multiply byte verts by this
198 	char *mat;
199 	char *frames;
200 	char *base;
201 	float *ctranslate;
202 	float *cscale;
203 	char data[1];
204 } dcompmdl_t;
205 
206 typedef struct
207 {
208 	dcompmdl_t compModInfo;
209 	int rootCluster;
210 	int skeletalType;
211 	struct ModelSkeleton_s *skeletons;
212 } JointedModel_t;
213 
214 /*
215    ========================================================================
216 
217    .BK file format
218 
219    ========================================================================
220  */
221 
222 #define IDBOOKHEADER    ( ( 'K' << 24 ) + ( 'O' << 16 ) + ( 'O' << 8 ) + 'B' )
223 #define BOOK_VERSION    2
224 
225 typedef struct bookframe_s
226 {
227 	int x;
228 	int y;
229 	int w;
230 	int h;
231 	char name[MAX_SKINNAME];            // name of gfx file
232 } bookframe_t;
233 
234 typedef struct bookheader_s
235 {
236 	unsigned int ident;
237 	unsigned int version;
238 	int num_segments;
239 	int total_w;
240 	int total_h;
241 } bookheader_t;
242 
243 typedef struct book_s
244 {
245 	bookheader_t bheader;
246 	bookframe_t bframes[MAX_MD2SKINS];
247 } book_t;
248 
249 /*
250    ========================================================================
251 
252    .SP2 sprite file format
253 
254    ========================================================================
255  */
256 
257 #define IDSPRITEHEADER  ( ( '2' << 24 ) + ( 'S' << 16 ) + ( 'D' << 8 ) + 'I' )
258 // little-endian "IDS2"
259 #define SPRITE_VERSION  2
260 
261 typedef struct
262 {
263 	int width, height;
264 	int origin_x, origin_y;         // raster coordinates inside pic
265 	char name[MAX_SKINNAME];        // name of pcx file
266 } dsprframe_t;
267 
268 typedef struct {
269 	int ident;
270 	int version;
271 	int numframes;
272 	dsprframe_t frames[1];          // variable sized
273 } dsprite_t;
274 
275 /*
276    ==============================================================================
277 
278    .M8 texture file format
279 
280    ==============================================================================
281  */
282 
283 typedef struct palette_s
284 {
285 	union
286 	{
287 		struct
288 		{
289 			byte r,g,b;
290 		};
291 	};
292 } palette_t;
293 
294 #define MIP_VERSION     2
295 #define PAL_SIZE        256
296 #define MIPLEVELS       16
297 
298 typedef struct miptex_s
299 {
300 	int version;
301 	char name[32];
302 	unsigned width[MIPLEVELS], height[MIPLEVELS];
303 	unsigned offsets[MIPLEVELS];        // four mip maps stored
304 	char animname[32];                  // next frame in animation chain
305 	palette_t palette[PAL_SIZE];
306 	int flags;
307 	int contents;
308 	int value;
309 } miptex_t;
310 
311 
312 
313 #define MIP32_VERSION   4
314 
315 typedef struct miptex32_s
316 {
317 	int version;
318 	char name[128];
319 	char altname[128];                  // texture substitution
320 	char animname[128];                 // next frame in animation chain
321 	char damagename[128];               // image that should be shown when damaged
322 	unsigned width[MIPLEVELS], height[MIPLEVELS];
323 	unsigned offsets[MIPLEVELS];
324 	int flags;
325 	int contents;
326 	int value;
327 	float scale_x, scale_y;
328 	int mip_scale;
329 
330 	// detail texturing info
331 	char dt_name[128];              // detailed texture name
332 	float dt_scale_x, dt_scale_y;
333 	float dt_u, dt_v;
334 	float dt_alpha;
335 	int dt_src_blend_mode, dt_dst_blend_mode;
336 
337 	int unused[20];                     // future expansion to maintain compatibility with h2
338 } miptex32_t;
339 
340 
341 /*
342    ==============================================================================
343 
344    .BSP file format
345 
346    ==============================================================================
347  */
348 
349 #define IDBSPHEADER ( ( 'P' << 24 ) + ( 'S' << 16 ) + ( 'B' << 8 ) + 'I' )
350 // little-endian "IBSP"
351 
352 #define BSPVERSION  38
353 
354 
355 // upper design bounds
356 // leaffaces, leafbrushes, planes, and verts are still bounded by
357 // 16 bit short limits
358 #define MAX_MAP_MODELS      1024
359 //#define	MAX_MAP_BRUSHES		8192	// Quake 2 original
360 #define MAX_MAP_BRUSHES     10240
361 #define MAX_MAP_ENTITIES    2048
362 #define MAX_MAP_ENTSTRING   0x40000
363 #define MAX_MAP_TEXINFO     8192
364 
365 #define MAX_MAP_AREAS       256
366 #define MAX_MAP_AREAPORTALS 1024
367 #define MAX_MAP_PLANES      65536
368 #define MAX_MAP_NODES       65536
369 #define MAX_MAP_BRUSHSIDES  65536
370 #define MAX_MAP_LEAFS       65536
371 #define MAX_MAP_VERTS       65536
372 #define MAX_MAP_FACES       65536
373 #define MAX_MAP_LEAFFACES   65536
374 #define MAX_MAP_LEAFBRUSHES 65536
375 #define MAX_MAP_PORTALS     65536
376 #define MAX_MAP_EDGES       128000
377 #define MAX_MAP_SURFEDGES   256000
378 #define MAX_MAP_LIGHTING    0x200000
379 #define MAX_MAP_VISIBILITY  0x180000
380 
381 // key / value pair sizes
382 
383 #define MAX_KEY     32
384 #define MAX_VALUE   1024
385 
386 //=============================================================================
387 
388 typedef struct
389 {
390 	int fileofs, filelen;
391 } lump_t;
392 
393 #define LUMP_ENTITIES       0
394 #define LUMP_PLANES         1
395 #define LUMP_VERTEXES       2
396 #define LUMP_VISIBILITY     3
397 #define LUMP_NODES          4
398 #define LUMP_TEXINFO        5
399 #define LUMP_FACES          6
400 #define LUMP_LIGHTING       7
401 #define LUMP_LEAFS          8
402 #define LUMP_LEAFFACES      9
403 #define LUMP_LEAFBRUSHES    10
404 #define LUMP_EDGES          11
405 #define LUMP_SURFEDGES      12
406 #define LUMP_MODELS         13
407 #define LUMP_BRUSHES        14
408 #define LUMP_BRUSHSIDES     15
409 #define LUMP_POP            16
410 #define LUMP_AREAS          17
411 #define LUMP_AREAPORTALS    18
412 #define HEADER_LUMPS        19
413 
414 typedef struct
415 {
416 	int ident;
417 	int version;
418 	lump_t lumps[HEADER_LUMPS];
419 } dheader_t;
420 
421 typedef struct
422 {
423 	float mins[3], maxs[3];
424 	float origin[3];            // for sounds or lights
425 	int headnode;
426 	int firstface, numfaces;            // submodels just draw faces
427 	                                    // without walking the bsp tree
428 } dmodel_t;
429 
430 
431 typedef struct
432 {
433 	float point[3];
434 } dvertex_t;
435 
436 
437 // 0-2 are axial planes
438 #define PLANE_X         0
439 #define PLANE_Y         1
440 #define PLANE_Z         2
441 
442 // 3-5 are non-axial planes snapped to the nearest
443 #define PLANE_ANYX      3
444 #define PLANE_ANYY      4
445 #define PLANE_ANYZ      5
446 
447 // planes (x&~1) and (x&~1)+1 are allways opposites
448 
449 typedef struct
450 {
451 	float normal[3];
452 	float dist;
453 	int type;           // PLANE_X - PLANE_ANYZ ?remove? trivial to regenerate
454 } dplane_t;
455 
456 
457 // contents flags are seperate bits
458 // a given brush can contribute multiple content bits
459 // multiple brushes can be in a single leaf
460 
461 // These definitions also need to be in q_shared.h!
462 
463 // ************************************************************************************************
464 // CONTENTS_XXX
465 // ------------
466 // Contents flags.
467 // ************************************************************************************************
468 
469 // Lower bits are stronger, and will eat weaker brushes completely.
470 
471 #define CONTENTS_SOLID          0x00000001  // An eye is never valid in a solid.
472 #define CONTENTS_WINDOW         0x00000002  // Translucent, but not watery.
473 #define CONTENTS_AUX            0x00000004
474 #define CONTENTS_LAVA           0x00000008
475 #define CONTENTS_SLIME          0x00000010
476 #define CONTENTS_WATER          0x00000020
477 #define CONTENTS_MIST           0x00000040
478 #define LAST_VISIBLE_CONTENTS   CONTENTS_MIST
479 
480 // Remaining contents are non-visible, and don't eat brushes.
481 
482 #define CONTENTS_AREAPORTAL     0x00008000
483 #define CONTENTS_PLAYERCLIP     0x00010000
484 #define CONTENTS_MONSTERCLIP    0x00020000
485 
486 // Currents can be added to any other contents, and may be mixed.
487 
488 #define CONTENTS_CURRENT_0      0x00040000
489 #define CONTENTS_CURRENT_90     0x00080000
490 #define CONTENTS_CURRENT_180    0x00100000
491 #define CONTENTS_CURRENT_270    0x00200000
492 #define CONTENTS_CURRENT_UP     0x00400000
493 #define CONTENTS_CURRENT_DOWN   0x00800000
494 #define CONTENTS_ORIGIN         0x01000000  // Removed before bsping an entity.
495 #define CONTENTS_MONSTER        0x02000000  // Should never be on a brush, only in game.
496 #define CONTENTS_DEADMONSTER    0x04000000
497 #define CONTENTS_DETAIL         0x08000000  // Brushes to be added after vis leaves.
498 #define CONTENTS_TRANSLUCENT    0x10000000  // Auto set if any surface has transparency.
499 #define CONTENTS_LADDER         0x20000000
500 #define CONTENTS_CAMERANOBLOCK  0x40000000  // Camera LOS ignores any brushes with this flag.
501 
502 typedef struct
503 {
504 	int planenum;
505 	int children[2];            // negative numbers are -(leafs+1), not nodes
506 	short mins[3];              // for frustom culling
507 	short maxs[3];
508 	unsigned short firstface;
509 	unsigned short numfaces;    // counting both sides
510 } dnode_t;
511 
512 
513 typedef struct texinfo_s
514 {
515 	float vecs[2][4];           // [s/t][xyz offset]
516 	int flags;                  // miptex flags + overrides
517 	int value;                  // light emission, etc
518 	char texture[32];           // texture name (textures/*.wal)
519 	int nexttexinfo;            // for animations, -1 = end of chain
520 } texinfo_t;
521 
522 
523 // note that edge 0 is never used, because negative edge nums are used for
524 // counterclockwise use of the edge in a face
525 typedef struct
526 {
527 	unsigned short v[2];        // vertex numbers
528 } dedge_t;
529 
530 #define MAXLIGHTMAPS    4
531 typedef struct
532 {
533 	unsigned short planenum;
534 	short side;
535 
536 	int firstedge;              // we must support > 64k edges
537 	short numedges;
538 	short texinfo;
539 
540 // lighting info
541 	byte styles[MAXLIGHTMAPS];
542 	int lightofs;               // start of [numstyles*surfsize] samples
543 } dface_t;
544 
545 typedef struct
546 {
547 	int contents;                       // OR of all brushes (not needed?)
548 
549 	short cluster;
550 	short area;
551 
552 	short mins[3];                      // for frustum culling
553 	short maxs[3];
554 
555 	unsigned short firstleafface;
556 	unsigned short numleaffaces;
557 
558 	unsigned short firstleafbrush;
559 	unsigned short numleafbrushes;
560 } dleaf_t;
561 
562 typedef struct
563 {
564 	unsigned short planenum;        // facing out of the leaf
565 	short texinfo;
566 } dbrushside_t;
567 
568 typedef struct
569 {
570 	int firstside;
571 	int numsides;
572 	int contents;
573 } dbrush_t;
574 
575 #define ANGLE_UP    -1
576 #define ANGLE_DOWN  -2
577 
578 
579 // the visibility lump consists of a header with a count, then
580 // byte offsets for the PVS and PHS of each cluster, then the raw
581 // compressed bit vectors
582 #define DVIS_PVS    0
583 #define DVIS_PHS    1
584 typedef struct
585 {
586 	int numclusters;
587 	int bitofs[8][2];           // bitofs[numclusters][2]
588 } dvis_t;
589 
590 // each area has a list of portals that lead into other areas
591 // when portals are closed, other areas may not be visible or
592 // hearable even if the vis info says that it should be
593 typedef struct
594 {
595 	int portalnum;
596 	int otherarea;
597 } dareaportal_t;
598 
599 typedef struct
600 {
601 	int numareaportals;
602 	int firstareaportal;
603 } darea_t;
604