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