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