]> icculus.org git repositories - btb/d2x.git/blob - main/gamemine.c
more header cleanup
[btb/d2x.git] / main / gamemine.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 /*
15  *
16  * Functions for loading mines in the game
17  *
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <conf.h>
22 #endif
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include <string.h>
28
29 #include "mono.h"
30 #include "inferno.h"
31 #include "error.h"
32 #ifdef EDITOR
33 #include "editor/editor.h"
34 #endif
35 #include "cfile.h"
36 #include "hash.h"
37 #include "key.h"
38 #include "byteswap.h"
39
40
41 #define REMOVE_EXT(s)  (*(strchr( (s), '.' ))='\0')
42
43 fix Level_shake_frequency = 0, Level_shake_duration = 0;
44 int Secret_return_segment = 0;
45 vms_matrix Secret_return_orient;
46
47 #ifdef EDITOR
48 struct mtfi mine_top_fileinfo; // Should be same as first two fields below...
49 struct mfi mine_fileinfo;
50 struct mh mine_header;
51 struct me mine_editor;
52 #endif // EDITOR
53
54 typedef struct v16_segment {
55         #ifdef EDITOR
56         short   segnum;             // segment number, not sure what it means
57         #endif
58         side    sides[MAX_SIDES_PER_SEGMENT];       // 6 sides
59         short   children[MAX_SIDES_PER_SEGMENT];    // indices of 6 children segments, front, left, top, right, bottom, back
60         short   verts[MAX_VERTICES_PER_SEGMENT];    // vertex ids of 4 front and 4 back vertices
61         #ifdef  EDITOR
62         short   group;              // group number to which the segment belongs.
63         #endif
64         short   objects;            // pointer to objects in this segment
65         ubyte   special;            // what type of center this is
66         sbyte   matcen_num;         // which center segment is associated with.
67         short   value;
68         fix     static_light;       // average static light in segment
69         #ifndef EDITOR
70         short   pad;                // make structure longword aligned
71         #endif
72 } v16_segment;
73
74 #if 0
75 struct mfi_v19 {
76         ushort  fileinfo_signature;
77         ushort  fileinfo_version;
78         int     fileinfo_sizeof;
79         int     header_offset;      // Stuff common to game & editor
80         int     header_size;
81         int     editor_offset;      // Editor specific stuff
82         int     editor_size;
83         int     segment_offset;
84         int     segment_howmany;
85         int     segment_sizeof;
86         int     newseg_verts_offset;
87         int     newseg_verts_howmany;
88         int     newseg_verts_sizeof;
89         int     group_offset;
90         int     group_howmany;
91         int     group_sizeof;
92         int     vertex_offset;
93         int     vertex_howmany;
94         int     vertex_sizeof;
95         int     texture_offset;
96         int     texture_howmany;
97         int     texture_sizeof;
98         int     walls_offset;
99         int     walls_howmany;
100         int     walls_sizeof;
101         int     triggers_offset;
102         int     triggers_howmany;
103         int     triggers_sizeof;
104         int     links_offset;
105         int     links_howmany;
106         int     links_sizeof;
107         int     object_offset;      // Object info
108         int     object_howmany;
109         int     object_sizeof;
110         int     unused_offset;      // was: doors_offset
111         int     unused_howmamy;     // was: doors_howmany
112         int     unused_sizeof;      // was: doors_sizeof
113         short   level_shake_frequency;  // Shakes every level_shake_frequency seconds
114         short   level_shake_duration;   // for level_shake_duration seconds (on average, random).  In 16ths second.
115         int     secret_return_segment;
116         vms_matrix  secret_return_orient;
117
118         int     dl_indices_offset;
119         int     dl_indices_howmany;
120         int     dl_indices_sizeof;
121
122         int     delta_light_offset;
123         int     delta_light_howmany;
124         int     delta_light_sizeof;
125
126 };
127 #endif // 0
128
129 int CreateDefaultNewSegment();
130
131 int New_file_format_load = 1; // "new file format" is everything newer than d1 shareware
132
133 int d1_pig_present = 0; // can descent.pig from descent 1 be loaded?
134
135 /* returns nonzero if d1_tmap_num references a texture which isn't available in d2. */
136 int d1_tmap_num_unique(short d1_tmap_num) {
137         switch (d1_tmap_num) {
138         case   0: case   2: case   4: case   5: case   6: case   7: case   9:
139         case  10: case  11: case  12: case  17: case  18:
140         case  20: case  21: case  25: case  28:
141         case  38: case  39: case  41: case  44: case  49:
142         case  50: case  55: case  57: case  88:
143         case 132: case 141: case 147:
144         case 154: case 155: case 158: case 159:
145         case 160: case 161: case 167: case 168: case 169:
146         case 170: case 171: case 174: case 175: case 185:
147         case 193: case 194: case 195: case 198: case 199:
148         case 200: case 202: case 210: case 211:
149         case 220: case 226: case 227: case 228: case 229: case 230:
150         case 240: case 241: case 242: case 243: case 246:
151         case 250: case 251: case 252: case 253: case 257: case 258: case 259:
152         case 260: case 263: case 266: case 283: case 298:
153         case 315: case 317: case 319: case 320: case 321:
154         case 330: case 331: case 332: case 333: case 349:
155         case 351: case 352: case 353: case 354:
156         case 355: case 357: case 358: case 359:
157         case 362: case 370: return 1;
158         default: return 0;
159         }
160 }
161
162 /* Converts descent 1 texture numbers to descent 2 texture numbers.
163  * Textures from d1 which are unique to d1 have extra spaces around "return".
164  * If we can load the original d1 pig, we make sure this function is bijective.
165  * This function was updated using the file config/convtabl.ini from devil 2.2.
166  */
167 short convert_d1_tmap_num(short d1_tmap_num) {
168         switch (d1_tmap_num) {
169         case 0: case 2: case 4: case 5:
170                 // all refer to grey rock001 (exception to bijectivity rule)
171                 return  d1_pig_present ? 137 : 43; // (devil:95)
172         case   1: return 0;
173         case   3: return 1; // rock021
174         case   6:  return  270; // blue rock002
175         case   7:  return  271; // yellow rock265
176         case   8: return 2; // rock004
177         case   9:  return  d1_pig_present ? 138 : 62; // purple (devil:179)
178         case  10:  return  272; // red rock006
179         case  11:  return  d1_pig_present ? 139 : 117;
180         case  12:  return  d1_pig_present ? 140 : 12; //devil:43
181         case  13: return 3; // rock014
182         case  14: return 4; // rock019
183         case  15: return 5; // rock020
184         case  16: return 6;
185         case  17:  return  d1_pig_present ? 141 : 52;
186         case  18:  return  129;
187         case  19: return 7;
188         case  20:  return  d1_pig_present ? 142 : 22;
189         case  21:  return  d1_pig_present ? 143 : 9;
190         case  22: return 8;
191         case  23: return 9;
192         case  24: return 10;
193         case  25:  return  d1_pig_present ? 144 : 12; //devil:35
194         case  26: return 11;
195         case  27: return 12;
196         case  28:  return  d1_pig_present ? 145 : 11; //devil:43
197         //range handled by default case, returns 13..21 (- 16)
198         case  38:  return  163; //devil:27
199         case  39:  return  147; //31
200         case  40: return 22;
201         case  41:  return  266;
202         case  42: return 23;
203         case  43: return 24;
204         case  44:  return  136; //devil:135
205         case  45: return 25;
206         case  46: return 26;
207         case  47: return 27;
208         case  48: return 28;
209         case  49:  return  d1_pig_present ? 146 : 43; //devil:60
210         case  50:  return  131; //devil:138
211         case  51: return 29;
212         case  52: return 30;
213         case  53: return 31;
214         case  54: return 32;
215         case  55:  return  165; //devil:193
216         case  56: return 33;
217         case  57:  return  132; //devil:119
218         // range handled by default case, returns 34..63 (- 24)
219         case  88:  return  197; //devil:15
220         // range handled by default case, returns 64..106 (- 25)
221         case 132:  return  167;
222         // range handled by default case, returns 107..114 (- 26)
223         case 141:  return  d1_pig_present ? 148 : 110; //devil:106
224         case 142: return 115;
225         case 143: return 116;
226         case 144: return 117;
227         case 145: return 118;
228         case 146: return 119;
229         case 147:  return  d1_pig_present ? 149 : 93;
230         case 148: return 120;
231         case 149: return 121;
232         case 150: return 122;
233         case 151: return 123;
234         case 152: return 124;
235         case 153: return 125; // rock263
236         case 154:  return  d1_pig_present ? 150 : 27;
237         case 155:  return  126; // rock269
238         case 156: return 200; // metl002
239         case 157: return 201; // metl003
240         case 158:  return  186; //devil:227
241         case 159:  return  190; //devil:246
242         case 160:  return  d1_pig_present ? 151 : 206;
243         case 161:  return  d1_pig_present ? 152 : 114; //devil:206
244         case 162: return 202;
245         case 163: return 203;
246         case 164: return 204;
247         case 165: return 205;
248         case 166: return 206;
249         case 167:  return  d1_pig_present ? 153 : 206;
250         case 168:  return  d1_pig_present ? 154 : 206;
251         case 169:  return  d1_pig_present ? 155 : 206;
252         case 170:  return  d1_pig_present ? 156 : 227;//206;
253         case 171:  return  d1_pig_present ? 157 : 206;//227;
254         case 172: return 207;
255         case 173: return 208;
256         case 174:  return  d1_pig_present ? 158 : 202;
257         case 175:  return  d1_pig_present ? 159 : 206;
258         // range handled by default case, returns 209..217 (+ 33)
259         case 185:  return  d1_pig_present ? 160 : 217;
260         // range handled by default case, returns 218..224 (+ 32)
261         case 193:  return  d1_pig_present ? 161 : 206;
262         case 194:  return  d1_pig_present ? 162 : 203;//206;
263         case 195:  return  d1_pig_present ? 166 : 234;
264         case 196: return 225;
265         case 197: return 226;
266         case 198:  return  d1_pig_present ? 193 : 225;
267         case 199:  return  d1_pig_present ? 168 : 206; //devil:204
268         case 200:  return  d1_pig_present ? 169 : 206; //devil:204
269         case 201: return 227;
270         case 202:  return  d1_pig_present ? 170 : 206; //devil:227
271         // range handled by default case, returns 228..234 (+ 25)
272         case 210:  return  d1_pig_present ? 171 : 234; //devil:242
273         case 211:  return  d1_pig_present ? 172 : 206; //devil:240
274         // range handled by default case, returns 235..242 (+ 23)
275         case 220:  return  d1_pig_present ? 173 : 242; //devil:240
276         case 221: return 243;
277         case 222: return 244;
278         case 223:  return  d1_pig_present ? 174 : 313;
279         case 224: return 245;
280         case 225: return 246;
281         case 226:  return  164;//247; matching names but not matching textures
282         case 227:  return  179; //devil:181
283         case 228:  return  196;//248; matching names but not matching textures
284         case 229:  return  d1_pig_present ? 175 : 15; //devil:66
285         case 230:  return  d1_pig_present ? 176 : 15; //devil:66
286         // range handled by default case, returns 249..257 (+ 18)
287         case 240:  return  d1_pig_present ? 177 : 6; //devil:132
288         case 241:  return  130; //devil:131
289         case 242:  return  d1_pig_present ? 178 : 78; //devil:15
290         case 243:  return  d1_pig_present ? 180 : 33; //devil:38
291         case 244: return 258;
292         case 245: return 259;
293         case 246:  return  d1_pig_present ? 181 : 321; // grate metl127
294         case 247: return 260;
295         case 248: return 261;
296         case 249: return 262;
297         case 250:  return  340; //  white doorframe metl126
298         case 251:  return  412; //    red doorframe metl133
299         case 252:  return  410; //   blue doorframe metl134
300         case 253:  return  411; // yellow doorframe metl135
301         case 254: return 263; // metl136
302         case 255: return 264; // metl139
303         case 256: return 265; // metl140
304         case 257:  return  d1_pig_present ? 182 : 249;//246; brig001
305         case 258:  return  d1_pig_present ? 183 : 251;//246; brig002
306         case 259:  return  d1_pig_present ? 184 : 252;//246; brig003
307         case 260:  return  d1_pig_present ? 185 : 256;//246; brig004
308         case 261: return 273; // exit01
309         case 262: return 274; // exit02
310         case 263:  return  d1_pig_present ? 187 : 281; // ceil001
311         case 264: return 275; // ceil002
312         case 265: return 276; // ceil003
313         case 266:  return  d1_pig_present ? 188 : 279; //devil:291
314         // range handled by default case, returns 277..291 (+ 10)
315         case 282: return 293;
316         case 283:  return  d1_pig_present ? 189 : 295;
317         case 284: return 295;
318         case 285: return 296;
319         case 286: return 298;
320         // range handled by default case, returns 300..310 (+ 13)
321         case 298:  return  d1_pig_present ? 191 : 364; // devil:374 misc010
322         // range handled by default case, returns 311..326 (+ 12)
323         case 315:  return  d1_pig_present ? 192 : 361; // bad producer misc044
324         // range handled by default case,  returns  327..337 (+ 11)
325         case 327: return 352; // arw01
326         case 328: return 353; // misc17
327         case 329: return 354; // fan01
328         case 330:  return  380; // mntr04
329         case 331:  return  379;//373; matching names but not matching textures
330         case 332:  return  355;//344; matching names but not matching textures
331         case 333:  return  409; // lava misc11 //devil:404
332         case 334: return 356; // ctrl04
333         case 335: return 357; // ctrl01
334         case 336: return 358; // ctrl02
335         case 337: return 359; // ctrl03
336         case 338: return 360; // misc14
337         case 339: return 361; // producer misc16
338         case 340: return 362; // misc049
339         case 341: return 364; // misc060
340         case 342: return 363; // blown01
341         case 343: return 366; // misc061
342         case 344: return 365;
343         case 345: return 368;
344         case 346: return 376;
345         case 347: return 370;
346         case 348: return 367;
347         case 349:  return  372;
348         case 350: return 369;
349         case 351:  return  374;//429; matching names but not matching textures
350         case 352:  return  375;//387; matching names but not matching textures
351         case 353:  return  371;
352         case 354:  return  377;//425; matching names but not matching textures
353         case 355:  return  408;
354         case 356: return 378; // lava02
355         case 357:  return  383;//384; matching names but not matching textures
356         case 358:  return  384;//385; matching names but not matching textures
357         case 359:  return  385;//386; matching names but not matching textures
358         case 360: return 386;
359         case 361: return 387;
360         case 362:  return  d1_pig_present ? 194 : 388; // mntr04b (devil: -1)
361         case 363: return 388;
362         case 364: return 391;
363         case 365: return 392;
364         case 366: return 393;
365         case 367: return 394;
366         case 368: return 395;
367         case 369: return 396;
368         case 370:  return  d1_pig_present ? 195 : 392; // mntr04d (devil: -1)
369         // range 371..584 handled by default case (wall01 and door frames)
370         default:
371                 // ranges:
372                 if (d1_tmap_num >= 29 && d1_tmap_num <= 37)
373                         return d1_tmap_num - 16;
374                 if (d1_tmap_num >= 58 && d1_tmap_num <= 87)
375                         return d1_tmap_num - 24;
376                 if (d1_tmap_num >= 89 && d1_tmap_num <= 131)
377                         return d1_tmap_num - 25;
378                 if (d1_tmap_num >= 133 && d1_tmap_num <= 140)
379                         return d1_tmap_num - 26;
380                 if (d1_tmap_num >= 176 && d1_tmap_num <= 184)
381                         return d1_tmap_num + 33;
382                 if (d1_tmap_num >= 186 && d1_tmap_num <= 192)
383                         return d1_tmap_num + 32;
384                 if (d1_tmap_num >= 203 && d1_tmap_num <= 209)
385                         return d1_tmap_num + 25;
386                 if (d1_tmap_num >= 212 && d1_tmap_num <= 219)
387                         return d1_tmap_num + 23;
388                 if (d1_tmap_num >= 231 && d1_tmap_num <= 239)
389                         return d1_tmap_num + 18;
390                 if (d1_tmap_num >= 267 && d1_tmap_num <= 281)
391                         return d1_tmap_num + 10;
392                 if (d1_tmap_num >= 287 && d1_tmap_num <= 297)
393                         return d1_tmap_num + 13;
394                 if (d1_tmap_num >= 299 && d1_tmap_num <= 314)
395                         return d1_tmap_num + 12;
396                 if (d1_tmap_num >= 316 && d1_tmap_num <= 326)
397                          return  d1_tmap_num + 11; // matching names but not matching textures
398                 // wall01 and door frames:
399                 if (d1_tmap_num > 370 && d1_tmap_num < 584) {
400                         if (New_file_format_load) return d1_tmap_num + 64;
401                         // d1 shareware needs special treatment:
402                         if (d1_tmap_num < 410) return d1_tmap_num + 68;
403                         if (d1_tmap_num < 417) return d1_tmap_num + 73;
404                         if (d1_tmap_num < 446) return d1_tmap_num + 91;
405                         if (d1_tmap_num < 453) return d1_tmap_num + 104;
406                         if (d1_tmap_num < 462) return d1_tmap_num + 111;
407                         if (d1_tmap_num < 486) return d1_tmap_num + 117;
408                         if (d1_tmap_num < 494) return d1_tmap_num + 141;
409                         if (d1_tmap_num < 584) return d1_tmap_num + 147;
410                 }
411                 { // handle rare case where orientation != 0
412                         short tmap_num = d1_tmap_num &  TMAP_NUM_MASK;
413                         short orient = d1_tmap_num & ~TMAP_NUM_MASK;
414                         if (orient != 0) {
415                                 return orient | convert_d1_tmap_num(tmap_num);
416                         } else {
417                                 Warning("can't convert unknown descent 1 texture #%d.\n", tmap_num);
418                                 return d1_tmap_num;
419                         }
420                 }
421         }
422 }
423
424 #ifdef EDITOR
425
426 static char old_tmap_list[MAX_TEXTURES][FILENAME_LEN];
427 short tmap_xlate_table[MAX_TEXTURES];
428 static short tmap_times_used[MAX_TEXTURES];
429
430 // -----------------------------------------------------------------------------
431 //loads from an already-open file
432 // returns 0=everything ok, 1=old version, -1=error
433 int load_mine_data(CFILE *LoadFile)
434 {
435         int   i, j,oldsizeadjust;
436         short tmap_xlate;
437         int     translate;
438         char    *temptr;
439         int     mine_start = cftell(LoadFile);
440
441         oldsizeadjust=(sizeof(int)*2)+sizeof (vms_matrix);
442         fuelcen_reset();
443
444         for (i=0; i<MAX_TEXTURES; i++ )
445                 tmap_times_used[i] = 0;
446
447         #ifdef EDITOR
448         // Create a new mine to initialize things.
449         //texpage_goto_first();
450         create_new_mine();
451         #endif
452
453         //===================== READ FILE INFO ========================
454
455         // These are the default values... version and fileinfo_sizeof
456         // don't have defaults.
457         mine_fileinfo.header_offset     =   -1;
458         mine_fileinfo.header_size       =   sizeof(mine_header);
459         mine_fileinfo.editor_offset     =   -1;
460         mine_fileinfo.editor_size       =   sizeof(mine_editor);
461         mine_fileinfo.vertex_offset     =   -1;
462         mine_fileinfo.vertex_howmany    =   0;
463         mine_fileinfo.vertex_sizeof     =   sizeof(vms_vector);
464         mine_fileinfo.segment_offset    =   -1;
465         mine_fileinfo.segment_howmany   =   0;
466         mine_fileinfo.segment_sizeof    =   sizeof(segment);
467         mine_fileinfo.newseg_verts_offset     =   -1;
468         mine_fileinfo.newseg_verts_howmany    =   0;
469         mine_fileinfo.newseg_verts_sizeof     =   sizeof(vms_vector);
470         mine_fileinfo.group_offset                =     -1;
471         mine_fileinfo.group_howmany       =     0;
472         mine_fileinfo.group_sizeof                =     sizeof(group);
473         mine_fileinfo.texture_offset    =   -1;
474         mine_fileinfo.texture_howmany   =   0;
475         mine_fileinfo.texture_sizeof    =   FILENAME_LEN;  // num characters in a name
476         mine_fileinfo.walls_offset                =     -1;
477         mine_fileinfo.walls_howmany       =     0;
478         mine_fileinfo.walls_sizeof                =     sizeof(wall);  
479         mine_fileinfo.triggers_offset     =     -1;
480         mine_fileinfo.triggers_howmany  =       0;
481         mine_fileinfo.triggers_sizeof     =     sizeof(trigger);  
482         mine_fileinfo.object_offset             =       -1;
483         mine_fileinfo.object_howmany            =       1;
484         mine_fileinfo.object_sizeof             =       sizeof(object);  
485
486         mine_fileinfo.level_shake_frequency             =       0;
487         mine_fileinfo.level_shake_duration              =       0;
488
489         //      Delta light stuff for blowing out light sources.
490 //      if (mine_top_fileinfo.fileinfo_version >= 19) {
491                 mine_fileinfo.dl_indices_offset         =       -1;
492                 mine_fileinfo.dl_indices_howmany                =       0;
493                 mine_fileinfo.dl_indices_sizeof         =       sizeof(dl_index);  
494
495                 mine_fileinfo.delta_light_offset                =       -1;
496                 mine_fileinfo.delta_light_howmany               =       0;
497                 mine_fileinfo.delta_light_sizeof                =       sizeof(delta_light);  
498
499 //      }
500
501         mine_fileinfo.segment2_offset           = -1;
502         mine_fileinfo.segment2_howmany  = 0;
503         mine_fileinfo.segment2_sizeof    = sizeof(segment2);
504
505         // Read in mine_top_fileinfo to get size of saved fileinfo.
506         
507         memset( &mine_top_fileinfo, 0, sizeof(mine_top_fileinfo) );
508
509         if (cfseek( LoadFile, mine_start, SEEK_SET ))
510                 Error( "Error moving to top of file in gamemine.c" );
511
512         if (cfread( &mine_top_fileinfo, sizeof(mine_top_fileinfo), 1, LoadFile )!=1)
513                 Error( "Error reading mine_top_fileinfo in gamemine.c" );
514
515         if (mine_top_fileinfo.fileinfo_signature != 0x2884)
516                 return -1;
517
518         // Check version number
519         if (mine_top_fileinfo.fileinfo_version < COMPATIBLE_VERSION )
520                 return -1;
521
522         // Now, Read in the fileinfo
523         if (cfseek( LoadFile, mine_start, SEEK_SET ))
524                 Error( "Error seeking to top of file in gamemine.c" );
525
526         if (cfread( &mine_fileinfo, mine_top_fileinfo.fileinfo_sizeof, 1, LoadFile )!=1)
527                 Error( "Error reading mine_fileinfo in gamemine.c" );
528
529         if (mine_top_fileinfo.fileinfo_version < 18) {
530                 mprintf((1, "Old version, setting shake intensity to 0.\n"));
531                 Level_shake_frequency = 0;
532                 Level_shake_duration = 0;
533                 Secret_return_segment = 0;
534                 Secret_return_orient = vmd_identity_matrix;
535         } else {
536                 Level_shake_frequency = mine_fileinfo.level_shake_frequency << 12;
537                 Level_shake_duration = mine_fileinfo.level_shake_duration << 12;
538                 Secret_return_segment = mine_fileinfo.secret_return_segment;
539                 Secret_return_orient = mine_fileinfo.secret_return_orient;
540         }
541
542         //===================== READ HEADER INFO ========================
543
544         // Set default values.
545         mine_header.num_vertices        =   0;
546         mine_header.num_segments        =   0;
547
548         if (mine_fileinfo.header_offset > -1 )
549         {
550                 if (cfseek( LoadFile, mine_fileinfo.header_offset, SEEK_SET ))
551                         Error( "Error seeking to header_offset in gamemine.c" );
552         
553                 if (cfread( &mine_header, mine_fileinfo.header_size, 1, LoadFile )!=1)
554                         Error( "Error reading mine_header in gamemine.c" );
555         }
556
557         //===================== READ EDITOR INFO ==========================
558
559         // Set default values
560         mine_editor.current_seg         =   0;
561         mine_editor.newsegment_offset   =   -1; // To be written
562         mine_editor.newsegment_size     =   sizeof(segment);
563         mine_editor.Curside             =   0;
564         mine_editor.Markedsegp          =   -1;
565         mine_editor.Markedside          =   0;
566
567         if (mine_fileinfo.editor_offset > -1 )
568         {
569                 if (cfseek( LoadFile, mine_fileinfo.editor_offset, SEEK_SET ))
570                         Error( "Error seeking to editor_offset in gamemine.c" );
571         
572                 if (cfread( &mine_editor, mine_fileinfo.editor_size, 1, LoadFile )!=1)
573                         Error( "Error reading mine_editor in gamemine.c" );
574         }
575
576         //===================== READ TEXTURE INFO ==========================
577
578         if ( (mine_fileinfo.texture_offset > -1) && (mine_fileinfo.texture_howmany > 0))
579         {
580                 if (cfseek( LoadFile, mine_fileinfo.texture_offset, SEEK_SET ))
581                         Error( "Error seeking to texture_offset in gamemine.c" );
582
583                 for (i=0; i< mine_fileinfo.texture_howmany; i++ )
584                 {
585                         if (cfread( &old_tmap_list[i], mine_fileinfo.texture_sizeof, 1, LoadFile )!=1)
586                                 Error( "Error reading old_tmap_list[i] in gamemine.c" );
587                 }
588         }
589
590         //=============== GENERATE TEXTURE TRANSLATION TABLE ===============
591
592         translate = 0;
593         
594         Assert (NumTextures < MAX_TEXTURES);
595
596         {
597                 hashtable ht;
598         
599                 hashtable_init( &ht, NumTextures );
600         
601                 // Remove all the file extensions in the textures list
602         
603                 for (i=0;i<NumTextures;i++)     {
604                         temptr = strchr(TmapInfo[i].filename, '.');
605                         if (temptr) *temptr = '\0';
606                         hashtable_insert( &ht, TmapInfo[i].filename, i );
607                 }
608         
609                 // For every texture, search through the texture list
610                 // to find a matching name.
611                 for (j=0;j<mine_fileinfo.texture_howmany;j++)   {
612                         // Remove this texture name's extension
613                         temptr = strchr(old_tmap_list[j], '.');
614                         if (temptr) *temptr = '\0';
615         
616                         tmap_xlate_table[j] = hashtable_search( &ht,old_tmap_list[j]);
617                         if (tmap_xlate_table[j] < 0 )   {
618                                 //tmap_xlate_table[j] = 0;
619                                 // mprintf( (0, "Couldn't find texture '%s'\n", old_tmap_list[j] ));
620                                 ;
621                         }
622                         if (tmap_xlate_table[j] != j ) translate = 1;
623                         if (tmap_xlate_table[j] >= 0)
624                                 tmap_times_used[tmap_xlate_table[j]]++;
625                 }
626         
627                 {
628                         int count = 0;
629                         for (i=0; i<MAX_TEXTURES; i++ )
630                                 if (tmap_times_used[i])
631                                         count++;
632                         mprintf( (0, "This mine has %d unique textures in it (~%d KB)\n", count, (count*4096) /1024 ));
633                 }
634         
635                 // -- mprintf( (0, "Translate=%d\n", translate ));
636         
637                 hashtable_free( &ht );
638         }
639
640         //====================== READ VERTEX INFO ==========================
641
642         // New check added to make sure we don't read in too many vertices.
643         if ( mine_fileinfo.vertex_howmany > MAX_VERTICES )
644                 {
645                 mprintf((0, "Num vertices exceeds maximum.  Loading MAX %d vertices\n", MAX_VERTICES));
646                 mine_fileinfo.vertex_howmany = MAX_VERTICES;
647                 }
648
649         if ( (mine_fileinfo.vertex_offset > -1) && (mine_fileinfo.vertex_howmany > 0))
650         {
651                 if (cfseek( LoadFile, mine_fileinfo.vertex_offset, SEEK_SET ))
652                         Error( "Error seeking to vertex_offset in gamemine.c" );
653
654                 for (i=0; i< mine_fileinfo.vertex_howmany; i++ )
655                 {
656                         // Set the default values for this vertex
657                         Vertices[i].x = 1;
658                         Vertices[i].y = 1;
659                         Vertices[i].z = 1;
660
661                         if (cfread( &Vertices[i], mine_fileinfo.vertex_sizeof, 1, LoadFile )!=1)
662                                 Error( "Error reading Vertices[i] in gamemine.c" );
663                 }
664         }
665
666         //==================== READ SEGMENT INFO ===========================
667
668         // New check added to make sure we don't read in too many segments.
669         if ( mine_fileinfo.segment_howmany > MAX_SEGMENTS ) {
670                 mprintf((0, "Num segments exceeds maximum.  Loading MAX %d segments\n", MAX_SEGMENTS));
671                 mine_fileinfo.segment_howmany = MAX_SEGMENTS;
672                 mine_fileinfo.segment2_howmany = MAX_SEGMENTS;
673         }
674
675         // [commented out by mk on 11/20/94 (weren't we supposed to hit final in October?) because it looks redundant.  I think I'll test it now...]  fuelcen_reset();
676
677         if ( (mine_fileinfo.segment_offset > -1) && (mine_fileinfo.segment_howmany > 0))        {
678
679                 if (cfseek( LoadFile, mine_fileinfo.segment_offset,SEEK_SET ))
680
681                         Error( "Error seeking to segment_offset in gamemine.c" );
682
683                 Highest_segment_index = mine_fileinfo.segment_howmany-1;
684
685                 for (i=0; i< mine_fileinfo.segment_howmany; i++ ) {
686
687                         // Set the default values for this segment (clear to zero )
688                         //memset( &Segments[i], 0, sizeof(segment) );
689
690                         if (mine_top_fileinfo.fileinfo_version < 20) {
691                                 v16_segment v16_seg;
692
693                                 Assert(mine_fileinfo.segment_sizeof == sizeof(v16_seg));
694
695                                 if (cfread( &v16_seg, mine_fileinfo.segment_sizeof, 1, LoadFile )!=1)
696                                         Error( "Error reading segments in gamemine.c" );
697
698                                 #ifdef EDITOR
699                                 Segments[i].segnum = v16_seg.segnum;
700                                 // -- Segments[i].pad = v16_seg.pad;
701                                 #endif
702
703                                 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
704                                         Segments[i].sides[j] = v16_seg.sides[j];
705
706                                 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
707                                         Segments[i].children[j] = v16_seg.children[j];
708
709                                 for (j=0; j<MAX_VERTICES_PER_SEGMENT; j++)
710                                         Segments[i].verts[j] = v16_seg.verts[j];
711
712                                 Segment2s[i].special = v16_seg.special;
713                                 Segment2s[i].value = v16_seg.value;
714                                 Segment2s[i].s2_flags = 0;
715                                 Segment2s[i].matcen_num = v16_seg.matcen_num;
716                                 Segment2s[i].static_light = v16_seg.static_light;
717                                 fuelcen_activate( &Segments[i], Segment2s[i].special );
718
719                         } else  {
720                                 if (cfread( &Segments[i], mine_fileinfo.segment_sizeof, 1, LoadFile )!=1)
721                                         Error("Unable to read segment %i\n", i);
722                         }
723
724                         Segments[i].objects = -1;
725                         #ifdef EDITOR
726                         Segments[i].group = -1;
727                         #endif
728
729                         if (mine_top_fileinfo.fileinfo_version < 15) {  //used old uvl ranges
730                                 int sn,uvln;
731
732                                 for (sn=0;sn<MAX_SIDES_PER_SEGMENT;sn++)
733                                         for (uvln=0;uvln<4;uvln++) {
734                                                 Segments[i].sides[sn].uvls[uvln].u /= 64;
735                                                 Segments[i].sides[sn].uvls[uvln].v /= 64;
736                                                 Segments[i].sides[sn].uvls[uvln].l /= 32;
737                                         }
738                         }
739
740                         if (translate == 1)
741                                 for (j=0;j<MAX_SIDES_PER_SEGMENT;j++) {
742                                         unsigned short orient;
743                                         tmap_xlate = Segments[i].sides[j].tmap_num;
744                                         Segments[i].sides[j].tmap_num = tmap_xlate_table[tmap_xlate];
745                                         if ((WALL_IS_DOORWAY(&Segments[i],j) & WID_RENDER_FLAG))
746                                                 if (Segments[i].sides[j].tmap_num < 0)  {
747                                                         mprintf( (0, "Couldn't find texture '%s' for Segment %d, side %d\n", old_tmap_list[tmap_xlate],i,j));
748                                                         Int3();
749                                                         Segments[i].sides[j].tmap_num = NumTextures-1;
750                                                 }
751                                         tmap_xlate = Segments[i].sides[j].tmap_num2 & TMAP_NUM_MASK;
752                                         orient = Segments[i].sides[j].tmap_num2 & (~TMAP_NUM_MASK);
753                                         if (tmap_xlate != 0) {
754                                                 int xlated_tmap = tmap_xlate_table[tmap_xlate];
755
756                                                 if ((WALL_IS_DOORWAY(&Segments[i],j) & WID_RENDER_FLAG))
757                                                         if (xlated_tmap <= 0)   {
758                                                                 mprintf( (0, "Couldn't find texture '%s' for Segment %d, side %d\n", old_tmap_list[tmap_xlate],i,j));
759                                                                 Int3();
760                                                                 Segments[i].sides[j].tmap_num2 = NumTextures-1;
761                                                         }
762                                                 Segments[i].sides[j].tmap_num2 = xlated_tmap | orient;
763                                         }
764                                 }
765                 }
766
767
768                 if (mine_top_fileinfo.fileinfo_version >= 20)
769                         for (i=0; i<=Highest_segment_index; i++) {
770                                 cfread(&Segment2s[i], sizeof(segment2), 1, LoadFile);
771                                 fuelcen_activate( &Segments[i], Segment2s[i].special );
772                         }
773         }
774
775         //===================== READ NEWSEGMENT INFO =====================
776
777         #ifdef EDITOR
778
779         {               // Default segment created.
780                 vms_vector      sizevec;
781                 med_create_new_segment(vm_vec_make(&sizevec,DEFAULT_X_SIZE,DEFAULT_Y_SIZE,DEFAULT_Z_SIZE));             // New_segment = Segments[0];
782                 //memset( &New_segment, 0, sizeof(segment) );
783         }
784
785         if (mine_editor.newsegment_offset > -1)
786         {
787                 if (cfseek( LoadFile, mine_editor.newsegment_offset,SEEK_SET ))
788                         Error( "Error seeking to newsegment_offset in gamemine.c" );
789                 if (cfread( &New_segment, mine_editor.newsegment_size,1,LoadFile )!=1)
790                         Error( "Error reading new_segment in gamemine.c" );
791         }
792
793         if ( (mine_fileinfo.newseg_verts_offset > -1) && (mine_fileinfo.newseg_verts_howmany > 0))
794         {
795                 if (cfseek( LoadFile, mine_fileinfo.newseg_verts_offset, SEEK_SET ))
796                         Error( "Error seeking to newseg_verts_offset in gamemine.c" );
797                 for (i=0; i< mine_fileinfo.newseg_verts_howmany; i++ )
798                 {
799                         // Set the default values for this vertex
800                         Vertices[NEW_SEGMENT_VERTICES+i].x = 1;
801                         Vertices[NEW_SEGMENT_VERTICES+i].y = 1;
802                         Vertices[NEW_SEGMENT_VERTICES+i].z = 1;
803                         
804                         if (cfread( &Vertices[NEW_SEGMENT_VERTICES+i], mine_fileinfo.newseg_verts_sizeof,1,LoadFile )!=1)
805                                 Error( "Error reading Vertices[NEW_SEGMENT_VERTICES+i] in gamemine.c" );
806
807                         New_segment.verts[i] = NEW_SEGMENT_VERTICES+i;
808                 }
809         }
810
811         #endif
812                                                                                                                         
813         //========================= UPDATE VARIABLES ======================
814
815         #ifdef EDITOR
816
817         // Setting to Markedsegp to NULL ignores Curside and Markedside, which
818         // we want to do when reading in an old file.
819         
820         Markedside = mine_editor.Markedside;
821         Curside = mine_editor.Curside;
822         for (i=0;i<10;i++)
823                 Groupside[i] = mine_editor.Groupside[i];
824
825         if ( mine_editor.current_seg != -1 )
826                 Cursegp = &Segments[mine_editor.current_seg];
827         else
828                 Cursegp = NULL;
829
830         if (mine_editor.Markedsegp != -1 ) 
831                 Markedsegp = &Segments[mine_editor.Markedsegp];
832         else
833                 Markedsegp = NULL;
834
835         num_groups = 0;
836         current_group = -1;
837
838         #endif
839
840         Num_vertices = mine_fileinfo.vertex_howmany;
841         Num_segments = mine_fileinfo.segment_howmany;
842         Highest_vertex_index = Num_vertices-1;
843         Highest_segment_index = Num_segments-1;
844
845         reset_objects(1);               //one object, the player
846
847         #ifdef EDITOR
848         Highest_vertex_index = MAX_SEGMENT_VERTICES-1;
849         Highest_segment_index = MAX_SEGMENTS-1;
850         set_vertex_counts();
851         Highest_vertex_index = Num_vertices-1;
852         Highest_segment_index = Num_segments-1;
853
854         warn_if_concave_segments();
855         #endif
856
857         #ifdef EDITOR
858                 validate_segment_all();
859         #endif
860
861         //create_local_segment_data();
862
863         //gamemine_find_textures();
864
865         if (mine_top_fileinfo.fileinfo_version < MINE_VERSION )
866                 return 1;               //old version
867         else
868                 return 0;
869
870 }
871 #endif
872
873 #define COMPILED_MINE_VERSION 0
874
875 void read_children(int segnum,ubyte bit_mask,CFILE *LoadFile)
876 {
877         int bit;
878
879         for (bit=0; bit<MAX_SIDES_PER_SEGMENT; bit++) {
880                 if (bit_mask & (1 << bit)) {
881                         Segments[segnum].children[bit] = cfile_read_short(LoadFile);
882                 } else
883                         Segments[segnum].children[bit] = -1;
884         }
885 }
886
887 void read_verts(int segnum,CFILE *LoadFile)
888 {
889         int i;
890         // Read short Segments[segnum].verts[MAX_VERTICES_PER_SEGMENT]
891         for (i = 0; i < MAX_VERTICES_PER_SEGMENT; i++)
892                 Segments[segnum].verts[i] = cfile_read_short(LoadFile);
893 }
894
895 void read_special(int segnum,ubyte bit_mask,CFILE *LoadFile)
896 {
897         if (bit_mask & (1 << MAX_SIDES_PER_SEGMENT)) {
898                 // Read ubyte   Segment2s[segnum].special
899                 Segment2s[segnum].special = cfile_read_byte(LoadFile);
900                 // Read byte    Segment2s[segnum].matcen_num
901                 Segment2s[segnum].matcen_num = cfile_read_byte(LoadFile);
902                 // Read short   Segment2s[segnum].value
903                 Segment2s[segnum].value = cfile_read_short(LoadFile);
904         } else {
905                 Segment2s[segnum].special = 0;
906                 Segment2s[segnum].matcen_num = -1;
907                 Segment2s[segnum].value = 0;
908         }
909 }
910
911 int load_mine_data_compiled(CFILE *LoadFile)
912 {
913         int     i, segnum, sidenum;
914         ubyte   compiled_version;
915         short   temp_short;
916         ushort  temp_ushort = 0;
917         ubyte   bit_mask;
918
919         d1_pig_present = cfexist(D1_PIGFILE);
920 #if 0 // the following will be deleted once reading old pigfiles works reliably
921         if (d1_pig_present) {
922                 CFILE * d1_Piggy_fp = cfopen( D1_PIGFILE, "rb" );
923                 switch (cfilelength(d1_Piggy_fp)) {
924                 case D1_SHARE_BIG_PIGSIZE:
925                 case D1_SHARE_10_PIGSIZE:
926                 case D1_SHARE_PIGSIZE:
927                 case D1_10_BIG_PIGSIZE:
928                 case D1_10_PIGSIZE:
929                         //d1_pig_present = 0;
930                 }
931                 cfclose (d1_Piggy_fp);
932         }
933 #endif
934
935         if (!strcmp(strchr(Gamesave_current_filename, '.'), ".sdl"))
936                 New_file_format_load = 0; // descent 1 shareware
937         else
938                 New_file_format_load = 1;
939
940         //      For compiled levels, textures map to themselves, prevent tmap_override always being gray,
941         //      bug which Matt and John refused to acknowledge, so here is Mike, fixing it.
942 #ifdef EDITOR
943         for (i=0; i<MAX_TEXTURES; i++)
944                 tmap_xlate_table[i] = i;
945 #endif
946
947 //      memset( Segments, 0, sizeof(segment)*MAX_SEGMENTS );
948         fuelcen_reset();
949
950         //=============================== Reading part ==============================
951         compiled_version = cfile_read_byte(LoadFile);
952         //Assert( compiled_version==COMPILED_MINE_VERSION );
953         if (compiled_version!=COMPILED_MINE_VERSION)
954                 mprintf((0,"compiled mine version=%i\n", compiled_version)); //many levels have "wrong" versions.  Theres no point in aborting because of it, I think.
955
956         if (New_file_format_load)
957                 Num_vertices = cfile_read_short(LoadFile);
958         else
959                 Num_vertices = cfile_read_int(LoadFile);
960         Assert( Num_vertices <= MAX_VERTICES );
961
962         if (New_file_format_load)
963                 Num_segments = cfile_read_short(LoadFile);
964         else
965                 Num_segments = cfile_read_int(LoadFile);
966         Assert( Num_segments <= MAX_SEGMENTS );
967
968         for (i = 0; i < Num_vertices; i++)
969                 cfile_read_vector( &(Vertices[i]), LoadFile);
970
971         for (segnum=0; segnum<Num_segments; segnum++ )  {
972
973                 #ifdef EDITOR
974                 Segments[segnum].segnum = segnum;
975                 Segments[segnum].group = 0;
976                 #endif
977
978                 if (New_file_format_load)
979                         bit_mask = cfile_read_byte(LoadFile);
980                 else
981                         bit_mask = 0x7f; // read all six children and special stuff...
982
983                 if (Gamesave_current_version == 5) { // d2 SHAREWARE level
984                         read_special(segnum,bit_mask,LoadFile);
985                         read_verts(segnum,LoadFile);
986                         read_children(segnum,bit_mask,LoadFile);
987                 } else {
988                         read_children(segnum,bit_mask,LoadFile);
989                         read_verts(segnum,LoadFile);
990                         if (Gamesave_current_version <= 1) { // descent 1 level
991                                 read_special(segnum,bit_mask,LoadFile);
992                         }
993                 }
994
995                 Segments[segnum].objects = -1;
996
997                 if (Gamesave_current_version <= 5) { // descent 1 thru d2 SHAREWARE level
998                         // Read fix     Segments[segnum].static_light (shift down 5 bits, write as short)
999                         temp_ushort = cfile_read_short(LoadFile);
1000                         Segment2s[segnum].static_light  = ((fix)temp_ushort) << 4;
1001                         //cfread( &Segments[segnum].static_light, sizeof(fix), 1, LoadFile );
1002                 }
1003
1004                 // Read the walls as a 6 byte array
1005                 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++ )      {
1006                         Segments[segnum].sides[sidenum].pad = 0;
1007                 }
1008
1009                 if (New_file_format_load)
1010                         bit_mask = cfile_read_byte(LoadFile);
1011                 else
1012                         bit_mask = 0x3f; // read all six sides
1013                 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
1014                         ubyte byte_wallnum;
1015
1016                         if (bit_mask & (1 << sidenum)) {
1017                                 byte_wallnum = cfile_read_byte(LoadFile);
1018                                 if ( byte_wallnum == 255 )
1019                                         Segments[segnum].sides[sidenum].wall_num = -1;
1020                                 else
1021                                         Segments[segnum].sides[sidenum].wall_num = byte_wallnum;
1022                         } else
1023                                         Segments[segnum].sides[sidenum].wall_num = -1;
1024                 }
1025
1026                 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++ )      {
1027
1028                         if ( (Segments[segnum].children[sidenum]==-1) || (Segments[segnum].sides[sidenum].wall_num!=-1) )       {
1029                                 // Read short Segments[segnum].sides[sidenum].tmap_num;
1030                                 if (New_file_format_load) {
1031                                         temp_ushort = cfile_read_short(LoadFile);
1032                                         Segments[segnum].sides[sidenum].tmap_num = temp_ushort & 0x7fff;
1033                                 } else
1034                                         Segments[segnum].sides[sidenum].tmap_num = cfile_read_short(LoadFile);
1035
1036                                 if (Gamesave_current_version <= 1)
1037                                         Segments[segnum].sides[sidenum].tmap_num = convert_d1_tmap_num(Segments[segnum].sides[sidenum].tmap_num);
1038
1039                                 if (New_file_format_load && !(temp_ushort & 0x8000))
1040                                         Segments[segnum].sides[sidenum].tmap_num2 = 0;
1041                                 else {
1042                                         // Read short Segments[segnum].sides[sidenum].tmap_num2;
1043                                         Segments[segnum].sides[sidenum].tmap_num2 = cfile_read_short(LoadFile);
1044                                         if (Gamesave_current_version <= 1 && Segments[segnum].sides[sidenum].tmap_num2 != 0)
1045                                                 Segments[segnum].sides[sidenum].tmap_num2 = convert_d1_tmap_num(Segments[segnum].sides[sidenum].tmap_num2);
1046                                 }
1047
1048                                 // Read uvl Segments[segnum].sides[sidenum].uvls[4] (u,v>>5, write as short, l>>1 write as short)
1049                                 for (i=0; i<4; i++ )    {
1050                                         temp_short = cfile_read_short(LoadFile);
1051                                         Segments[segnum].sides[sidenum].uvls[i].u = ((fix)temp_short) << 5;
1052                                         temp_short = cfile_read_short(LoadFile);
1053                                         Segments[segnum].sides[sidenum].uvls[i].v = ((fix)temp_short) << 5;
1054                                         temp_ushort = cfile_read_short(LoadFile);
1055                                         Segments[segnum].sides[sidenum].uvls[i].l = ((fix)temp_ushort) << 1;
1056                                         //cfread( &Segments[segnum].sides[sidenum].uvls[i].l, sizeof(fix), 1, LoadFile );
1057                                 }
1058                         } else {
1059                                 Segments[segnum].sides[sidenum].tmap_num = 0;
1060                                 Segments[segnum].sides[sidenum].tmap_num2 = 0;
1061                                 for (i=0; i<4; i++ )    {
1062                                         Segments[segnum].sides[sidenum].uvls[i].u = 0;
1063                                         Segments[segnum].sides[sidenum].uvls[i].v = 0;
1064                                         Segments[segnum].sides[sidenum].uvls[i].l = 0;
1065                                 }
1066                         }
1067                 }
1068         }
1069
1070 #if 0
1071         {
1072                 FILE *fp;
1073
1074                 fp = fopen("segments.out", "wt");
1075                 for (i = 0; i <= Highest_segment_index; i++) {
1076                         side    sides[MAX_SIDES_PER_SEGMENT];   // 6 sides
1077                         short   children[MAX_SIDES_PER_SEGMENT];        // indices of 6 children segments, front, left, top, right, bottom, back
1078                         short   verts[MAX_VERTICES_PER_SEGMENT];        // vertex ids of 4 front and 4 back vertices
1079                         int             objects;                                                                // pointer to objects in this segment
1080
1081                         for (j = 0; j < MAX_SIDES_PER_SEGMENT; j++) {
1082                                 sbyte   type;                           // replaces num_faces and tri_edge, 1 = quad, 2 = 0:2 triangulation, 3 = 1:3 triangulation
1083                                 ubyte   pad;                                                                    //keep us longword alligned
1084                                 short   wall_num;
1085                                 short   tmap_num;
1086                                 short   tmap_num2;
1087                                 uvl             uvls[4];
1088                                 vms_vector      normals[2];                                             // 2 normals, if quadrilateral, both the same.
1089                                 fprintf(fp, "%d\n", Segments[i].sides[j].type);
1090                                 fprintf(fp, "%d\n", Segments[i].sides[j].pad);
1091                                 fprintf(fp, "%d\n", Segments[i].sides[j].wall_num);
1092                                 fprintf(fp, "%d\n", Segments[i].tmap_num);
1093
1094                         }
1095                         fclose(fp);
1096                 }
1097         }
1098 #endif
1099
1100         Highest_vertex_index = Num_vertices-1;
1101         Highest_segment_index = Num_segments-1;
1102
1103         validate_segment_all();                 // Fill in side type and normals.
1104
1105         for (i=0; i<Num_segments; i++) {
1106                 if (Gamesave_current_version > 5)
1107                         segment2_read(&Segment2s[i], LoadFile);
1108                 fuelcen_activate( &Segments[i], Segment2s[i].special );
1109         }
1110
1111         reset_objects(1);               //one object, the player
1112
1113         return 0;
1114 }