summaryrefslogtreecommitdiff
path: root/src/include/module.h
blob: ac68355245e5dce355526917b79349dc7b64e743 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#ifndef MODULE_INCLUDED


/*

 Modules

*/


#ifdef __cplusplus

	extern "C" {

#endif


	#if SupportModules


#include "bh_waypt.h"

typedef struct moduletableheader {

	int mth_xsize;		/* Extents in world space */
	int mth_ysize;
	int mth_zsize;

	int mth_numx;		/* Number of modules along each axis */
	int mth_numy;
	int mth_numz;

	/* Pointer to an array of pointers to modules */

	struct module **mth_moduletable;

} MODULETABLEHEADER;


/*

 NOTES

 There are no pointers to strategy and/or animation data structures yet.
 These will be added as and when they are needed.

*/

typedef enum {

	mtype_module,
	mtype_term

} MODULETYPE;


typedef union mref {

	char mref_name[4];					/* Module name */
	struct module *mref_ptr;			/* Module pointer */

} MREF;


typedef enum {

	vmtype_vmodule,
	vmtype_term

} VMODULETYPE;


typedef enum {

	vmodi_null,			/* Null instruction */
	vmodi_bra_vc		/* Branch if viewport closed */

} VMODI;

typedef union _vmodidata {

	char vmodidata_label[4];
	struct vmodule *vmodidata_ptr;
	int vmodidata;

} VMODIDATA;


typedef struct vmodule {

	VMODULETYPE vmod_type;
	char vmod_name[4];				/* Unique name for this VMODULE */
	VMODI vmod_instr;
	VMODIDATA vmod_data;
	MREF vmod_mref;
	VECTORCH vmod_dir;
	int vmod_angle;
	int vmod_flags;

} VMODULE;


#define vm_flag_gotptrs				0x00000001	/* VMODULE references have
																been converted from
																names to pointers */


#if 0

typedef enum {

	vptype_viewport,
	vptype_term

} VIEWPORTTYPE;


typedef struct viewport {

	VIEWPORTTYPE vp_type;

	int vp_flags;

	VECTORCH vp0;
	VECTORCH vp1;
	VECTORCH vp2;
	VECTORCH vp3;

} VIEWPORT;

#endif


/*

 This is the map block for module objects. It was originally based on the
 MAPBLOCK8 structure.

*/

typedef struct modulemapblock {

	int MapType;
	int MapShape;

	#if LoadingMapsShapesAndTexturesEtc

		int MapFNameIndex;
		char **MapFNameArray;
		SHAPEHEADER **MapShapeDataArray;

	#endif

	VECTORCH MapWorld;

	EULER MapEuler;

	int MapFlags;
	int MapFlags2;
	int MapFlags3;



	MAPSETVDB *MapVDBData;

	int MapInteriorType;

	#if InterfaceEngine

	/* This will point to the Object_Chunk, it will have to be */
	/* cast within C++ though */
	
	void * o_chunk;

	#endif

	int MapLightType;			/* See LIGHTTYPES */


	VECTORCH MapOrigin;			/* Origin of Rotation */

	SIMSHAPELIST *MapSimShapes;

	int MapViewType;			/* See "VDB_ViewType" */


	struct displayblock **MapMPtr;	/* Write our dptr here as mother */
	struct displayblock **MapDPtr;	/* Read our dptr here as daughter */

	VECTORCH MapMOffset;					/* Offset from mother */

	#if SupportMorphing
	MORPHHEADER *MapMorphHeader;
	#endif
	
} MODULEMAPBLOCK;


/*

 Module functions called either when the module is visible or when the view
 is inside the module.

*/

typedef enum {

	mfun_null,

} MFUNCTION;


/*

 This is the MODULE structure

*/

struct aimodule;

typedef struct module {

	MODULETYPE m_type;

	char m_name[4];						/* Unique name for this MODULE */

	int m_index;							/* Unique module index */

	int m_flags;

	VECTORCH m_world;						/* World location */

	MREF m_ext;								/* Get module extents from the shape
													found through this other module */

	int m_ext_scale;						/* Scale extents by this value (fp) */

	int m_maxx;								/* Module extents */
	int m_minx;
	int m_maxy;
	int m_miny;
	int m_maxz;
	int m_minz;

	MODULEMAPBLOCK *m_mapptr;			/* Map data for the module object */
	struct displayblock *m_dptr;		/* Display block (not constant) */

	MREF m_vptr;							/* Vertical pointer to module array */

	VMODULE *m_vmptr;						/* Pointer to an array of VMODULE, or
													"visible module" structures */
	
	MREF *m_link_ptrs;					/* Pointer to an arbitrary sized array
													of module references - the array is
													zero terminated */
										/*should be got rid of  soon*/



	MODULETABLEHEADER *m_table;		/* A hash table whose creation is
													triggered by a threshold value set by
													"system.h". This is to speed up module
													list traversal */

	MFUNCTION m_ifvisible;				/* Function called if module visible */
	MFUNCTION m_ifvinside;				/* Function called if view inside */
	MREF m_funref;							/* Function access to another module */

	struct strategyblock *m_sbptr;	/* Project supplies structure */

	int m_numlights;						/* # light blocks in array */
	struct lightblock *m_lightarray;	/* Ptr. to array of light blocks */

	struct extraitemdata *m_extraitemdata;

	MATRIXCH m_mat;						/* Internal use only */
	
	char * name;

	WAYPOINT_HEADER *m_waypoints;

	struct aimodule *m_aimodule;  /* the aimodule that this module is a part of*/

	float m_sound_reverb; /*settings for the way sound should */
	int m_sound_env_index;/*be played in this module*/
	
} MODULE;


/* Flags */

#define m_flag_infinite						0x00000001	/* No extent test, the
																		view is always in this
																		module */

#define m_flag_gotptrs						0x00000002	/* Module references have
																		been converted from
																		names to pointers */

#define m_flag_open							0x00000004	/* The viewport/Door is
																		open. This state is
																		read from the "dptr"
																		morphing frame if it is
																		present and if it is
																		appropriate to do so */

#define m_flag_dormant						0x00000008	/* The module is not active */


#define m_flag_gotmat						0x00000010	/* Internal use only */

#define m_flag_visible_on_map		0x00000020	/* Flag for Kevin's map stuff */

#define m_flag_slipped_inside		0x00000040  /* Another flag 4 Kevin */

#define MODULEFLAG_AIRDUCT			0x80000000
#define MODULEFLAG_STAIRS			0x40000000
#define MODULEFLAG_SKY				0x20000000
#define MODULEFLAG_FOG				0x10000000
#define MODULEFLAG_HORIZONTALDOOR	0x08000000


typedef struct aimodule
{
	int m_index; //the index in AIModuleArray
	
	VECTORCH m_world;						/* World location */
	
	//adjacent aimodules - null terminated array
	struct aimodule **m_link_ptrs;					
	
	//the render modules that make up this ai module - null terminated array
	MODULE **m_module_ptrs;					
	
	WAYPOINT_HEADER *m_waypoints;

	/* CDF 1/6/98 - Routefinder Globals */
	int RouteFinder_FrameStamp;
	int RouteFinder_IterationNumber;

}AIMODULE;


/*
 Module Scene Structure

*/

typedef struct scenemodule {

	MODULE *sm_module;	/* Pointer to module structure for this scene */
	MODULE **sm_marray;	/* Pointer to array of pointers to all modules */

} SCENEMODULE;


/*

 "The View"

 The "View Finder" accesses the view location and orientation through this
 global structure. This is so that views can be passed to other functions as
 a single pointer if required.

*/

typedef struct aview {

	VECTORCH vloc;
	MATRIXCH vmat;
	struct viewdescriptorblock *vvdb;

} AVIEW;




/*

 Module Function Prototypes

*/

#if IncludeModuleFunctionPrototypes

void ModuleHandler(VIEWDESCRIPTORBLOCK *vdb);
void ProcessModules(VIEWDESCRIPTORBLOCK *vdb, MODULE *mptr);
void ViewFinder(MODULE *mptr);
void ReadVMODULEArrays(VMODULE *vptr);


void UpdateModules(void);
void ModuleFunctions(MODULE *mptr, MFUNCTION mf);
void AllocateModuleObject(MODULE *mptr);
void DeallocateModuleObject(MODULE *mptr);
void AllNewModuleHandler(void);


/*

 A project supplied function. The display block has been successfuly
 allocated and has been fully initialised.

*/

void ModuleObjectJustAllocated(MODULE *mptr);


/*

 A project supplied function. The display block is about to be deallocated.

*/

void ModuleObjectAboutToBeDeallocated(MODULE *mptr);


/*

 A project supplied function. These are the new and old modules this ????

*/

void NewAndOldModules(int num_new, MODULE **m_new,
								int num_old, MODULE **m_old, char *m_currvis);



#if SupportMultiCamModules
void InitGlobalVMA(void);
void DeallocateGlobalVMA(void);
#if SupportMultiCamModules
void UpdateDynamicModuleObjects(void);
#endif
#endif

void PreprocessAllModules(void);
void PreprocessModuleArray(MODULE **m_array_ptr);
void PreprocessVMODIDATA(VMODULE *v_ptr);

void DeallocateModuleVisArrays(void);
int GetModuleVisArrays(void);
int InsideModule(MODULE *mptr);

void ConvertModuleNameToPointer(MREF *mref_ptr, MODULE **m_array_ptr);
void ConvertVModuleNameToPointer(VMODIDATA *vmodidata_ptr, VMODULE *v_array_ptr);

int CompareName(char *name1, char *name2);
void PrintName(char *name);

int SaveModuleArray(MODULE *mptr, char *filename);
MODULE* LoadModuleArray(MODULE *mptr, int size, char *filename);

int IsModuleVisibleFromModule(MODULE *source, MODULE *target);
int ThisObjectIsInAModuleVisibleFromCurrentlyVisibleModules(struct strategyblock *sbPtr);

#endif	/* IncludeModuleFunctionPrototypes */

extern SCENEMODULE **Global_ModulePtr;
extern SCENEMODULE *MainSceneArray[];
extern AVIEW ModuleView;
extern MODULE *Global_MotherModule;
extern char *ModuleCurrVisArray;
extern char *ModulePrevVisArray;
extern char *ModuleTempArray;
extern char *ModuleLocalVisArray;
extern int ModuleArraySize;

extern int AIModuleArraySize;
extern AIMODULE *AIModuleArray;


#endif	/* SupportModules */


#ifdef __cplusplus

	};

#endif

#define MODULE_INCLUDED

#endif