1 #include "3dc.h"
2 
3 #include "inline.h"
4 #include "module.h"
5 #include "stratdef.h"
6 
7 #define UseLocalAssert Yes
8 #include "ourasert.h"
9 
10 
11 /*
12  externs for commonly used global variables and arrays
13 */
14 
15 
16 extern VIEWDESCRIPTORBLOCK *Global_VDB_Ptr;
17 
18 /*
19  Global Variables
20 */
21 
22 DISPLAYBLOCK *dptr_last;
23 DISPLAYBLOCK *Player;
24 
25 
26 /*
27 		Map Reading Functions
28 		Read the map data passed and create the objects on the map
29 		The map header contains an array of pointers to the different map data
30 		structures
31 */
32 
33 
ReadMap(MAPHEADER * mapheader)34 DISPLAYBLOCK* ReadMap(MAPHEADER *mapheader)
35 {
36 	MAPBLOCK8 *mapblock8ptr;
37 	DISPLAYBLOCK *dblockptr = 0;
38 
39 
40 	/* Set up pointers to the map arrays */
41 	mapblock8ptr = mapheader->MapType8Objects;
42 
43 
44  	/* Map Type #8 Structure */
45 	if(mapblock8ptr) {
46 
47 		while(mapblock8ptr->MapType != MapType_Term) {
48 
49 			dblockptr = CreateActiveObject();
50 
51 			if(dblockptr)
52 			{
53 				dblockptr->ObShape = mapblock8ptr->MapShape;
54 
55 				CopyLocation(&mapblock8ptr->MapWorld, &dblockptr->ObWorld);
56 				CopyEuler(&mapblock8ptr->MapEuler, &dblockptr->ObEuler);
57 
58 				dblockptr->ObFlags  = mapblock8ptr->MapFlags;
59 				dblockptr->ObFlags2 = mapblock8ptr->MapFlags2;
60 				dblockptr->ObFlags3 = mapblock8ptr->MapFlags3;
61 
62 				if (mapblock8ptr->MapType == MapType_Player)
63 				{
64 					Player = dblockptr;
65 				}
66 				else
67 				{
68 					dblockptr->ObLightType = LightType_PerVertex;
69 					dblockptr->ObFlags |= ObFlag_MultLSrc;
70 				}
71 
72 /* KJL 16:55:57 06/05/97 - removing camera stuff */
73 				if(mapblock8ptr->MapVDBData)
74 					MapSetVDB(dblockptr, mapblock8ptr->MapVDBData);
75 
76 				dblockptr->ObLightType = mapblock8ptr->MapLightType;
77 
78 /* KJL 15:23:52 06/07/97 - removed */
79 //				CopyVector(&mapblock8ptr->MapOrigin, &dblockptr->ObOrigin);
80 //				dblockptr->ObSimShapes = mapblock8ptr->MapSimShapes;
81 //				dblockptr->ObViewType = mapblock8ptr->MapViewType;
82 
83 				MapBlockInit(dblockptr);
84 
85 				CreateEulerMatrix(&dblockptr->ObEuler,&dblockptr->ObMat);
86 				TransposeMatrixCH(&dblockptr->ObMat);
87 
88 				MapPostProcessing(dblockptr);
89 			}
90 
91 			dptr_last = dblockptr;
92 
93 			mapblock8ptr++;
94 
95 		}
96 
97 	}
98  	return dblockptr;
99 }
100 
101 
102 
103 /*
104 
105  Some objects might require a certain amount of general processing after
106  all the other map functions have been called
107 
108 */
109 
MapPostProcessing(DISPLAYBLOCK * dptr)110 void MapPostProcessing(DISPLAYBLOCK *dptr)
111 {
112 	if(dptr)
113 	{
114 		/*
115 
116 		Make sure that objects requesting multiple light sources are at
117 		least set to "LightType_PerObject"
118 
119 		*/
120 		if(dptr->ObFlags & ObFlag_MultLSrc)
121 		{
122 			if(dptr->ObLightType == LightType_Infinite)
123 				dptr->ObLightType = LightType_PerObject;
124 		}
125 	}
126 }
127 
128 
MapSetVDB(DISPLAYBLOCK * dptr,MAPSETVDB * mapvdbdata)129 void MapSetVDB(DISPLAYBLOCK *dptr, MAPSETVDB *mapvdbdata)
130 {
131 
132 	VIEWDESCRIPTORBLOCK *vdb;
133 
134 	/* TEST */
135 	/*LIGHTBLOCK *lptr;*/
136 
137 
138 
139 	/* Allocate a VDB */
140 
141 	vdb = CreateActiveVDB();
142 
143 	if(vdb) {
144 
145 		dptr->ObVDBPtr = vdb;			/* Object Block ptr to VDB */
146 
147 		vdb->VDB_ViewObject = dptr;	/* VDB ptr to Object Block */
148 
149 
150 		/* VDB Setup */
151 
152 		SetVDB(
153 
154 			vdb,
155 
156 			mapvdbdata->SVDB_Flags,
157 			mapvdbdata->SVDB_ViewType,
158 
159 			mapvdbdata->SVDB_Depth,
160 
161 			mapvdbdata->SVDB_CentreX,
162 			mapvdbdata->SVDB_CentreY,
163 
164 			mapvdbdata->SVDB_ProjX,
165 			mapvdbdata->SVDB_ProjY,
166 			mapvdbdata->SVDB_MaxProj,
167 
168 			mapvdbdata->SVDB_ClipLeft,
169 			mapvdbdata->SVDB_ClipRight,
170 			mapvdbdata->SVDB_ClipUp,
171 			mapvdbdata->SVDB_ClipDown,
172 
173 			mapvdbdata->SVDB_H1,
174 			mapvdbdata->SVDB_H2,
175 			mapvdbdata->SVDB_HColour,
176 
177 			mapvdbdata->SVDB_Ambience
178 
179 		);
180 
181 		PlatformSpecificVDBInit(vdb);
182 
183 		#if ProjectSpecificVDBs
184 		ProjectSpecificVDBInit(vdb);
185 		#endif
186 
187 
188 	}
189 
190 }
191 
192 
193 
194 
195 
196 
197 
198 /*
199 
200  Standard Initialisation for Map Objects
201 
202 */
203 
MapBlockInit(DISPLAYBLOCK * dptr)204 void MapBlockInit(DISPLAYBLOCK *dptr)
205 {
206 	SHAPEHEADER *sptr;
207 
208 	/* Get the shape header ptr */
209 
210 	sptr = GetShapeData(dptr->ObShape);
211 
212 
213 	/* Augmented Z */
214 
215 	if(sptr->shapeflags & ShapeFlag_AugZ) dptr->ObFlags2 |= ObFlag2_AugZ;
216 
217 
218 	/* Pass address of the shape data header back to the block for others */
219 
220 	dptr->ObShapeData = sptr;
221 
222 
223 	/* Does this shape use a BSP tree or a Z Sort ? */
224 
225 	dptr->ObFlags |= ObFlag_TypeZ;
226 
227 
228 	/* Copy shape radius to ODB */
229 
230 	dptr->ObRadius = sptr->shaperadius;
231 
232 	/* Copy shape xyz extents to ODB */
233 
234 	dptr->ObMaxX = sptr->shapemaxx;
235 	dptr->ObMinX = sptr->shapeminx;
236 
237 	dptr->ObMaxY = sptr->shapemaxy;
238 	dptr->ObMinY = sptr->shapeminy;
239 
240 	dptr->ObMaxZ = sptr->shapemaxz;
241 	dptr->ObMinZ = sptr->shapeminz;
242 
243 
244 
245 }
246