allow the editor to be built with NDEBUG
[btb/d2x.git] / main / gamesave.c
1 /* $Id: gamesave.c,v 1.35 2006-03-05 12:19:42 chris Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Save game information
18  *
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include <conf.h>
23 #endif
24
25 #ifdef RCS
26 char gamesave_rcsid[] = "$Id: gamesave.c,v 1.35 2006-03-05 12:19:42 chris Exp $";
27 #endif
28
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "pstypes.h"
33 #include "strutil.h"
34 #include "mono.h"
35 #include "key.h"
36 #include "gr.h"
37 #include "palette.h"
38 #include "newmenu.h"
39
40 #include "inferno.h"
41 #ifdef EDITOR
42 #include "editor/editor.h"
43 #endif
44 #include "error.h"
45 #include "object.h"
46 #include "game.h"
47 #include "screens.h"
48 #include "wall.h"
49 #include "gamemine.h"
50 #include "robot.h"
51
52
53 #include "cfile.h"
54 #include "bm.h"
55 #include "menu.h"
56 #include "switch.h"
57 #include "fuelcen.h"
58 #include "cntrlcen.h"
59 #include "powerup.h"
60 #include "weapon.h"
61 #include "newdemo.h"
62 #include "gameseq.h"
63 #include "automap.h"
64 #include "polyobj.h"
65 #include "text.h"
66 #include "gamefont.h"
67 #include "gamesave.h"
68 #include "gamepal.h"
69 #include "laser.h"
70 #include "byteswap.h"
71 #include "multi.h"
72 #include "makesig.h"
73
74 char Gamesave_current_filename[PATH_MAX];
75
76 int Gamesave_current_version;
77
78 #define GAME_VERSION            32
79 #define GAME_COMPATIBLE_VERSION 22
80
81 //version 28->29  add delta light support
82 //version 27->28  controlcen id now is reactor number, not model number
83 //version 28->29  ??
84 //version 29->30  changed trigger structure
85 //version 30->31  changed trigger structure some more
86 //version 31->32  change segment structure, make it 512 bytes w/o editor, add Segment2s array.
87
88 #define MENU_CURSOR_X_MIN       MENU_X
89 #define MENU_CURSOR_X_MAX       MENU_X+6
90
91 #ifdef EDITOR
92 struct {
93         ushort  fileinfo_signature;
94         ushort  fileinfo_version;
95         int     fileinfo_sizeof;
96 } game_top_fileinfo;    // Should be same as first two fields below...
97
98 struct {
99         ushort  fileinfo_signature;
100         ushort  fileinfo_version;
101         int     fileinfo_sizeof;
102         char    mine_filename[15];
103         int     level;
104         int     player_offset;              // Player info
105         int     player_sizeof;
106         int     object_offset;              // Object info
107         int     object_howmany;
108         int     object_sizeof;
109         int     walls_offset;
110         int     walls_howmany;
111         int     walls_sizeof;
112         int     doors_offset;
113         int     doors_howmany;
114         int     doors_sizeof;
115         int     triggers_offset;
116         int     triggers_howmany;
117         int     triggers_sizeof;
118         int     links_offset;
119         int     links_howmany;
120         int     links_sizeof;
121         int     control_offset;
122         int     control_howmany;
123         int     control_sizeof;
124         int     matcen_offset;
125         int     matcen_howmany;
126         int     matcen_sizeof;
127         int     dl_indices_offset;
128         int     dl_indices_howmany;
129         int     dl_indices_sizeof;
130         int     delta_light_offset;
131         int     delta_light_howmany;
132         int     delta_light_sizeof;
133 } game_fileinfo;
134 #endif // EDITOR
135
136 //  LINT: adding function prototypes
137 void read_object(object *obj, CFILE *f, int version);
138 #ifdef EDITOR
139 void write_object(object *obj, short version, PHYSFS_file *f);
140 void do_load_save_levels(int save);
141 #endif
142 #ifndef NDEBUG
143 void dump_mine_info(void);
144 #endif
145
146 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
147 extern char PowerupsInMine[MAX_POWERUP_TYPES];
148
149 #ifdef EDITOR
150 extern char mine_filename[];
151 extern int save_mine_data_compiled(PHYSFS_file *SaveFile);
152 //--unused-- #else
153 //--unused-- char mine_filename[128];
154 #endif
155
156 int Gamesave_num_org_robots = 0;
157 //--unused-- grs_bitmap * Gamesave_saved_bitmap = NULL;
158
159 #ifdef EDITOR
160 // Return true if this level has a name of the form "level??"
161 // Note that a pathspec can appear at the beginning of the filename.
162 int is_real_level(char *filename)
163 {
164         int len = strlen(filename);
165
166         if (len < 6)
167                 return 0;
168
169         //mprintf((0, "String = [%s]\n", &filename[len-11]));
170         return !strnicmp(&filename[len-11], "level", 5);
171
172 }
173 #endif
174
175 //--unused-- vms_angvec zero_angles={0,0,0};
176
177 #define vm_angvec_zero(v) do {(v)->p=(v)->b=(v)->h=0;} while (0)
178
179 int Gamesave_num_players=0;
180
181 int N_save_pof_names;
182 char Save_pof_names[MAX_POLYGON_MODELS][FILENAME_LEN];
183
184 void check_and_fix_matrix(vms_matrix *m);
185
186 void verify_object( object * obj )      {
187
188         obj->lifeleft = IMMORTAL_TIME;          //all loaded object are immortal, for now
189
190         if ( obj->type == OBJ_ROBOT )   {
191                 Gamesave_num_org_robots++;
192
193                 // Make sure valid id...
194                 if ( obj->id >= N_robot_types )
195                         obj->id = obj->id % N_robot_types;
196
197                 // Make sure model number & size are correct...
198                 if ( obj->render_type == RT_POLYOBJ ) {
199                         Assert(Robot_info[obj->id].model_num != -1);
200                                 //if you fail this assert, it means that a robot in this level
201                                 //hasn't been loaded, possibly because he's marked as
202                                 //non-shareware.  To see what robot number, print obj->id.
203
204                         Assert(Robot_info[obj->id].always_0xabcd == 0xabcd);
205                                 //if you fail this assert, it means that the robot_ai for
206                                 //a robot in this level hasn't been loaded, possibly because
207                                 //it's marked as non-shareware.  To see what robot number,
208                                 //print obj->id.
209
210                         obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
211                         obj->size = Polygon_models[obj->rtype.pobj_info.model_num].rad;
212
213                         //@@Took out this ugly hack 1/12/96, because Mike has added code
214                         //@@that should fix it in a better way.
215                         //@@//this is a super-ugly hack.  Since the baby stripe robots have
216                         //@@//their firing point on their bounding sphere, the firing points
217                         //@@//can poke through a wall if the robots are very close to it. So
218                         //@@//we make their radii bigger so the guns can't get too close to 
219                         //@@//the walls
220                         //@@if (Robot_info[obj->id].flags & RIF_BIG_RADIUS)
221                         //@@    obj->size = (obj->size*3)/2;
222
223                         //@@if (obj->control_type==CT_AI && Robot_info[obj->id].attack_type)
224                         //@@    obj->size = obj->size*3/4;
225                 }
226
227                 if (obj->id == 65)                                              //special "reactor" robots
228                         obj->movement_type = MT_NONE;
229
230                 if (obj->movement_type == MT_PHYSICS) {
231                         obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
232                         obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
233                 }
234         }
235         else {          //Robots taken care of above
236
237                 if ( obj->render_type == RT_POLYOBJ ) {
238                         int i;
239                         char *name = Save_pof_names[obj->rtype.pobj_info.model_num];
240
241                         for (i=0;i<N_polygon_models;i++)
242                                 if (!stricmp(Pof_names[i],name)) {              //found it!     
243                                         // mprintf((0,"Mapping <%s> to %d (was %d)\n",name,i,obj->rtype.pobj_info.model_num));
244                                         obj->rtype.pobj_info.model_num = i;
245                                         break;
246                                 }
247                 }
248         }
249
250         if ( obj->type == OBJ_POWERUP ) {
251                 if ( obj->id >= N_powerup_types )       {
252                         obj->id = 0;
253                         Assert( obj->render_type != RT_POLYOBJ );
254                 }
255                 obj->control_type = CT_POWERUP;
256                 obj->size = Powerup_info[obj->id].size;
257                 obj->ctype.powerup_info.creation_time = 0;
258
259 #ifdef NETWORK
260                 if (Game_mode & GM_NETWORK)
261                         {
262                           if (multi_powerup_is_4pack(obj->id))
263                                 {
264                                  PowerupsInMine[obj->id-1]+=4;
265                                  MaxPowerupsAllowed[obj->id-1]+=4;
266                                 }
267                           PowerupsInMine[obj->id]++;
268                      MaxPowerupsAllowed[obj->id]++;
269                           mprintf ((0,"PowerupLimiter: ID=%d\n",obj->id));
270                           if (obj->id>MAX_POWERUP_TYPES)
271                                 mprintf ((1,"POWERUP: Overwriting array bounds!! Get JL!\n"));
272                         }
273 #endif
274
275         }
276
277         if ( obj->type == OBJ_WEAPON )  {
278                 if ( obj->id >= N_weapon_types )        {
279                         obj->id = 0;
280                         Assert( obj->render_type != RT_POLYOBJ );
281                 }
282
283                 if (obj->id == PMINE_ID) {              //make sure pmines have correct values
284
285                         obj->mtype.phys_info.mass = Weapon_info[obj->id].mass;
286                         obj->mtype.phys_info.drag = Weapon_info[obj->id].drag;
287                         obj->mtype.phys_info.flags |= PF_FREE_SPINNING;
288
289                         // Make sure model number & size are correct...         
290                         Assert( obj->render_type == RT_POLYOBJ );
291
292                         obj->rtype.pobj_info.model_num = Weapon_info[obj->id].model_num;
293                         obj->size = Polygon_models[obj->rtype.pobj_info.model_num].rad;
294                 }
295         }
296
297         if ( obj->type == OBJ_CNTRLCEN ) {
298
299                 obj->render_type = RT_POLYOBJ;
300                 obj->control_type = CT_CNTRLCEN;
301
302                 if (Gamesave_current_version <= 1) { // descent 1 reactor
303                         obj->id = 0;                         // used to be only one kind of reactor
304                         obj->rtype.pobj_info.model_num = Reactors[0].model_num;// descent 1 reactor
305                 }
306
307                 // Make sure model number is correct...
308                 //obj->rtype.pobj_info.model_num = Reactors[obj->id].model_num;
309         }
310
311         if ( obj->type == OBJ_PLAYER )  {
312                 //int i;
313
314                 //Assert(obj == Player);
315
316                 if ( obj == ConsoleObject )             
317                         init_player_object();
318                 else
319                         if (obj->render_type == RT_POLYOBJ)     //recover from Matt's pof file matchup bug
320                                 obj->rtype.pobj_info.model_num = Player_ship->model_num;
321
322                 //Make sure orient matrix is orthogonal
323                 check_and_fix_matrix(&obj->orient);
324
325                 obj->id = Gamesave_num_players++;
326         }
327
328         if (obj->type == OBJ_HOSTAGE) {
329
330                 //@@if (obj->id > N_hostage_types)
331                 //@@    obj->id = 0;
332
333                 obj->render_type = RT_HOSTAGE;
334                 obj->control_type = CT_POWERUP;
335         }
336
337 }
338
339 //static gs_skip(int len,CFILE *file)
340 //{
341 //
342 //      cfseek(file,len,SEEK_CUR);
343 //}
344
345
346 extern int multi_powerup_is_4pack(int);
347 //reads one object of the given version from the given file
348 void read_object(object *obj,CFILE *f,int version)
349 {
350
351         obj->type           = cfile_read_byte(f);
352         obj->id             = cfile_read_byte(f);
353
354         obj->control_type   = cfile_read_byte(f);
355         obj->movement_type  = cfile_read_byte(f);
356         obj->render_type    = cfile_read_byte(f);
357         obj->flags          = cfile_read_byte(f);
358
359         obj->segnum         = cfile_read_short(f);
360         obj->attached_obj   = -1;
361
362         cfile_read_vector(&obj->pos,f);
363         cfile_read_matrix(&obj->orient,f);
364
365         obj->size           = cfile_read_fix(f);
366         obj->shields        = cfile_read_fix(f);
367
368         cfile_read_vector(&obj->last_pos,f);
369
370         obj->contains_type  = cfile_read_byte(f);
371         obj->contains_id    = cfile_read_byte(f);
372         obj->contains_count = cfile_read_byte(f);
373
374         switch (obj->movement_type) {
375
376                 case MT_PHYSICS:
377
378                         cfile_read_vector(&obj->mtype.phys_info.velocity,f);
379                         cfile_read_vector(&obj->mtype.phys_info.thrust,f);
380
381                         obj->mtype.phys_info.mass               = cfile_read_fix(f);
382                         obj->mtype.phys_info.drag               = cfile_read_fix(f);
383                         obj->mtype.phys_info.brakes     = cfile_read_fix(f);
384
385                         cfile_read_vector(&obj->mtype.phys_info.rotvel,f);
386                         cfile_read_vector(&obj->mtype.phys_info.rotthrust,f);
387
388                         obj->mtype.phys_info.turnroll   = cfile_read_fixang(f);
389                         obj->mtype.phys_info.flags              = cfile_read_short(f);
390
391                         break;
392
393                 case MT_SPINNING:
394
395                         cfile_read_vector(&obj->mtype.spin_rate,f);
396                         break;
397
398                 case MT_NONE:
399                         break;
400
401                 default:
402                         Int3();
403         }
404
405         switch (obj->control_type) {
406
407                 case CT_AI: {
408                         int i;
409
410                         obj->ctype.ai_info.behavior                             = cfile_read_byte(f);
411
412                         for (i=0;i<MAX_AI_FLAGS;i++)
413                                 obj->ctype.ai_info.flags[i]                     = cfile_read_byte(f);
414
415                         obj->ctype.ai_info.hide_segment                 = cfile_read_short(f);
416                         obj->ctype.ai_info.hide_index                   = cfile_read_short(f);
417                         obj->ctype.ai_info.path_length                  = cfile_read_short(f);
418                         obj->ctype.ai_info.cur_path_index               = cfile_read_short(f);
419
420                         if (version <= 25) {
421                                 cfile_read_short(f);    //                              obj->ctype.ai_info.follow_path_start_seg        = 
422                                 cfile_read_short(f);    //                              obj->ctype.ai_info.follow_path_end_seg          = 
423                         }
424
425                         break;
426                 }
427
428                 case CT_EXPLOSION:
429
430                         obj->ctype.expl_info.spawn_time         = cfile_read_fix(f);
431                         obj->ctype.expl_info.delete_time                = cfile_read_fix(f);
432                         obj->ctype.expl_info.delete_objnum      = cfile_read_short(f);
433                         obj->ctype.expl_info.next_attach = obj->ctype.expl_info.prev_attach = obj->ctype.expl_info.attach_parent = -1;
434
435                         break;
436
437                 case CT_WEAPON:
438
439                         //do I really need to read these?  Are they even saved to disk?
440
441                         obj->ctype.laser_info.parent_type               = cfile_read_short(f);
442                         obj->ctype.laser_info.parent_num                = cfile_read_short(f);
443                         obj->ctype.laser_info.parent_signature  = cfile_read_int(f);
444
445                         break;
446
447                 case CT_LIGHT:
448
449                         obj->ctype.light_info.intensity = cfile_read_fix(f);
450                         break;
451
452                 case CT_POWERUP:
453
454                         if (version >= 25)
455                                 obj->ctype.powerup_info.count = cfile_read_int(f);
456                         else
457                                 obj->ctype.powerup_info.count = 1;
458
459                         if (obj->id == POW_VULCAN_WEAPON)
460                                         obj->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT;
461
462                         if (obj->id == POW_GAUSS_WEAPON)
463                                         obj->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT;
464
465                         if (obj->id == POW_OMEGA_WEAPON)
466                                         obj->ctype.powerup_info.count = MAX_OMEGA_CHARGE;
467
468                         break;
469
470
471                 case CT_NONE:
472                 case CT_FLYING:
473                 case CT_DEBRIS:
474                         break;
475
476                 case CT_SLEW:           //the player is generally saved as slew
477                         break;
478
479                 case CT_CNTRLCEN:
480                         break;
481
482                 case CT_MORPH:
483                 case CT_FLYTHROUGH:
484                 case CT_REPAIRCEN:
485                 default:
486                         Int3();
487         
488         }
489
490         switch (obj->render_type) {
491
492                 case RT_NONE:
493                         break;
494
495                 case RT_MORPH:
496                 case RT_POLYOBJ: {
497                         int i,tmo;
498
499                         obj->rtype.pobj_info.model_num          = cfile_read_int(f);
500
501                         for (i=0;i<MAX_SUBMODELS;i++)
502                                 cfile_read_angvec(&obj->rtype.pobj_info.anim_angles[i],f);
503
504                         obj->rtype.pobj_info.subobj_flags       = cfile_read_int(f);
505
506                         tmo = cfile_read_int(f);
507
508                         #ifndef EDITOR
509                         obj->rtype.pobj_info.tmap_override      = tmo;
510                         #else
511                         if (tmo==-1)
512                                 obj->rtype.pobj_info.tmap_override      = -1;
513                         else {
514                                 int xlated_tmo = tmap_xlate_table[tmo];
515                                 if (xlated_tmo < 0)     {
516                                         mprintf( (0, "Couldn't find texture for demo object, model_num = %d\n", obj->rtype.pobj_info.model_num));
517                                         Int3();
518                                         xlated_tmo = 0;
519                                 }
520                                 obj->rtype.pobj_info.tmap_override      = xlated_tmo;
521                         }
522                         #endif
523
524                         obj->rtype.pobj_info.alt_textures       = 0;
525
526                         break;
527                 }
528
529                 case RT_WEAPON_VCLIP:
530                 case RT_HOSTAGE:
531                 case RT_POWERUP:
532                 case RT_FIREBALL:
533
534                         obj->rtype.vclip_info.vclip_num = cfile_read_int(f);
535                         obj->rtype.vclip_info.frametime = cfile_read_fix(f);
536                         obj->rtype.vclip_info.framenum  = cfile_read_byte(f);
537
538                         break;
539
540                 case RT_LASER:
541                         break;
542
543                 default:
544                         Int3();
545
546         }
547
548 }
549
550 #ifdef EDITOR
551
552 //writes one object to the given file
553 void write_object(object *obj, short version, PHYSFS_file *f)
554 {
555         PHYSFSX_writeU8(f, obj->type);
556         PHYSFSX_writeU8(f, obj->id);
557
558         PHYSFSX_writeU8(f, obj->control_type);
559         PHYSFSX_writeU8(f, obj->movement_type);
560         PHYSFSX_writeU8(f, obj->render_type);
561         PHYSFSX_writeU8(f, obj->flags);
562
563         PHYSFS_writeSLE16(f, obj->segnum);
564
565         PHYSFSX_writeVector(f, &obj->pos);
566         PHYSFSX_writeMatrix(f, &obj->orient);
567
568         PHYSFSX_writeFix(f, obj->size);
569         PHYSFSX_writeFix(f, obj->shields);
570
571         PHYSFSX_writeVector(f, &obj->last_pos);
572
573         PHYSFSX_writeU8(f, obj->contains_type);
574         PHYSFSX_writeU8(f, obj->contains_id);
575         PHYSFSX_writeU8(f, obj->contains_count);
576
577         switch (obj->movement_type) {
578
579                 case MT_PHYSICS:
580
581                         PHYSFSX_writeVector(f, &obj->mtype.phys_info.velocity);
582                         PHYSFSX_writeVector(f, &obj->mtype.phys_info.thrust);
583
584                         PHYSFSX_writeFix(f, obj->mtype.phys_info.mass);
585                         PHYSFSX_writeFix(f, obj->mtype.phys_info.drag);
586                         PHYSFSX_writeFix(f, obj->mtype.phys_info.brakes);
587
588                         PHYSFSX_writeVector(f, &obj->mtype.phys_info.rotvel);
589                         PHYSFSX_writeVector(f, &obj->mtype.phys_info.rotthrust);
590
591                         PHYSFSX_writeFixAng(f, obj->mtype.phys_info.turnroll);
592                         PHYSFS_writeSLE16(f, obj->mtype.phys_info.flags);
593
594                         break;
595
596                 case MT_SPINNING:
597
598                         PHYSFSX_writeVector(f, &obj->mtype.spin_rate);
599                         break;
600
601                 case MT_NONE:
602                         break;
603
604                 default:
605                         Int3();
606         }
607
608         switch (obj->control_type) {
609
610                 case CT_AI: {
611                         int i;
612
613                         PHYSFSX_writeU8(f, obj->ctype.ai_info.behavior);
614
615                         for (i = 0; i < MAX_AI_FLAGS; i++)
616                                 PHYSFSX_writeU8(f, obj->ctype.ai_info.flags[i]);
617
618                         PHYSFS_writeSLE16(f, obj->ctype.ai_info.hide_segment);
619                         PHYSFS_writeSLE16(f, obj->ctype.ai_info.hide_index);
620                         PHYSFS_writeSLE16(f, obj->ctype.ai_info.path_length);
621                         PHYSFS_writeSLE16(f, obj->ctype.ai_info.cur_path_index);
622
623                         if (version <= 25)
624                         {
625                                 PHYSFS_writeSLE16(f, -1);       //obj->ctype.ai_info.follow_path_start_seg
626                                 PHYSFS_writeSLE16(f, -1);       //obj->ctype.ai_info.follow_path_end_seg
627                         }
628
629                         break;
630                 }
631
632                 case CT_EXPLOSION:
633
634                         PHYSFSX_writeFix(f, obj->ctype.expl_info.spawn_time);
635                         PHYSFSX_writeFix(f, obj->ctype.expl_info.delete_time);
636                         PHYSFS_writeSLE16(f, obj->ctype.expl_info.delete_objnum);
637
638                         break;
639
640                 case CT_WEAPON:
641
642                         //do I really need to write these objects?
643
644                         PHYSFS_writeSLE16(f, obj->ctype.laser_info.parent_type);
645                         PHYSFS_writeSLE16(f, obj->ctype.laser_info.parent_num);
646                         PHYSFS_writeSLE32(f, obj->ctype.laser_info.parent_signature);
647
648                         break;
649
650                 case CT_LIGHT:
651
652                         PHYSFSX_writeFix(f, obj->ctype.light_info.intensity);
653                         break;
654
655                 case CT_POWERUP:
656
657                         if (version >= 25)
658                                 PHYSFS_writeSLE32(f, obj->ctype.powerup_info.count);
659                         break;
660
661                 case CT_NONE:
662                 case CT_FLYING:
663                 case CT_DEBRIS:
664                         break;
665
666                 case CT_SLEW:           //the player is generally saved as slew
667                         break;
668
669                 case CT_CNTRLCEN:
670                         break;                  //control center object.
671
672                 case CT_MORPH:
673                 case CT_REPAIRCEN:
674                 case CT_FLYTHROUGH:
675                 default:
676                         Int3();
677         
678         }
679
680         switch (obj->render_type) {
681
682                 case RT_NONE:
683                         break;
684
685                 case RT_MORPH:
686                 case RT_POLYOBJ: {
687                         int i;
688
689                         PHYSFS_writeSLE32(f, obj->rtype.pobj_info.model_num);
690
691                         for (i = 0; i < MAX_SUBMODELS; i++)
692                                 PHYSFSX_writeAngleVec(f, &obj->rtype.pobj_info.anim_angles[i]);
693
694                         PHYSFS_writeSLE32(f, obj->rtype.pobj_info.subobj_flags);
695
696                         PHYSFS_writeSLE32(f, obj->rtype.pobj_info.tmap_override);
697
698                         break;
699                 }
700
701                 case RT_WEAPON_VCLIP:
702                 case RT_HOSTAGE:
703                 case RT_POWERUP:
704                 case RT_FIREBALL:
705
706                         PHYSFS_writeSLE32(f, obj->rtype.vclip_info.vclip_num);
707                         PHYSFSX_writeFix(f, obj->rtype.vclip_info.frametime);
708                         PHYSFSX_writeU8(f, obj->rtype.vclip_info.framenum);
709
710                         break;
711
712                 case RT_LASER:
713                         break;
714
715                 default:
716                         Int3();
717
718         }
719
720 }
721 #endif
722
723 extern int remove_trigger_num(int trigger_num);
724
725 // --------------------------------------------------------------------
726 // Load game 
727 // Loads all the relevant data for a level.
728 // If level != -1, it loads the filename with extension changed to .min
729 // Otherwise it loads the appropriate level mine.
730 // returns 0=everything ok, 1=old version, -1=error
731 int load_game_data(CFILE *LoadFile)
732 {
733         int i,j;
734
735         short game_top_fileinfo_version;
736         int object_offset;
737         int gs_num_objects;
738         int num_delta_lights;
739         int trig_size;
740
741         //===================== READ FILE INFO ========================
742
743 #if 0
744         cfread(&game_top_fileinfo, sizeof(game_top_fileinfo), 1, LoadFile);
745 #endif
746
747         // Check signature
748         if (cfile_read_short(LoadFile) != 0x6705)
749                 return -1;
750
751         // Read and check version number
752         game_top_fileinfo_version = cfile_read_short(LoadFile);
753         if (game_top_fileinfo_version < GAME_COMPATIBLE_VERSION )
754                 return -1;
755
756         // We skip some parts of the former game_top_fileinfo
757         cfseek(LoadFile, 31, SEEK_CUR);
758
759         object_offset = cfile_read_int(LoadFile);
760         gs_num_objects = cfile_read_int(LoadFile);
761         cfseek(LoadFile, 8, SEEK_CUR);
762
763         Num_walls = cfile_read_int(LoadFile);
764         cfseek(LoadFile, 20, SEEK_CUR);
765
766         Num_triggers = cfile_read_int(LoadFile);
767         cfseek(LoadFile, 24, SEEK_CUR);
768
769         trig_size = cfile_read_int(LoadFile);
770         Assert(trig_size == sizeof(ControlCenterTriggers));
771         cfseek(LoadFile, 4, SEEK_CUR);
772
773         Num_robot_centers = cfile_read_int(LoadFile);
774         cfseek(LoadFile, 4, SEEK_CUR);
775
776         if (game_top_fileinfo_version >= 29) {
777                 cfseek(LoadFile, 4, SEEK_CUR);
778                 Num_static_lights = cfile_read_int(LoadFile);
779                 cfseek(LoadFile, 8, SEEK_CUR);
780                 num_delta_lights = cfile_read_int(LoadFile);
781                 cfseek(LoadFile, 4, SEEK_CUR);
782         } else {
783                 Num_static_lights = 0;
784                 num_delta_lights = 0;
785         }
786
787         if (game_top_fileinfo_version >= 31) //load mine filename
788                 // read newline-terminated string, not sure what version this changed.
789                 cfgets(Current_level_name,sizeof(Current_level_name),LoadFile);
790         else if (game_top_fileinfo_version >= 14) { //load mine filename
791                 // read null-terminated string
792                 char *p=Current_level_name;
793                 //must do read one char at a time, since no cfgets()
794                 do *p = cfgetc(LoadFile); while (*p++!=0);
795         }
796         else
797                 Current_level_name[0]=0;
798
799         if (game_top_fileinfo_version >= 19) {  //load pof names
800                 N_save_pof_names = cfile_read_short(LoadFile);
801                 if (N_save_pof_names != 0x614d && N_save_pof_names != 0x5547) { // "Ma"de w/DMB beta/"GU"ILE
802                         Assert(N_save_pof_names < MAX_POLYGON_MODELS);
803                         cfread(Save_pof_names,N_save_pof_names,FILENAME_LEN,LoadFile);
804                 }
805         }
806
807         //===================== READ PLAYER INFO ==========================
808         Object_next_signature = 0;
809
810         //===================== READ OBJECT INFO ==========================
811
812         Gamesave_num_org_robots = 0;
813         Gamesave_num_players = 0;
814
815         if (object_offset > -1) {
816                 if (cfseek( LoadFile, object_offset, SEEK_SET ))
817                         Error( "Error seeking to object_offset in gamesave.c" );
818
819                 for (i = 0; i < gs_num_objects; i++) {
820
821                         read_object(&Objects[i], LoadFile, game_top_fileinfo_version);
822
823                         Objects[i].signature = Object_next_signature++;
824                         verify_object( &Objects[i] );
825                 }
826
827         }
828
829         //===================== READ WALL INFO ============================
830
831         for (i = 0; i < Num_walls; i++) {
832                 if (game_top_fileinfo_version >= 20)
833                         wall_read(&Walls[i], LoadFile); // v20 walls and up.
834                 else if (game_top_fileinfo_version >= 17) {
835                         v19_wall w;
836                         v19_wall_read(&w, LoadFile);
837                         Walls[i].segnum         = w.segnum;
838                         Walls[i].sidenum        = w.sidenum;
839                         Walls[i].linked_wall    = w.linked_wall;
840                         Walls[i].type           = w.type;
841                         Walls[i].flags          = w.flags;
842                         Walls[i].hps            = w.hps;
843                         Walls[i].trigger        = w.trigger;
844                         Walls[i].clip_num       = w.clip_num;
845                         Walls[i].keys           = w.keys;
846                         Walls[i].state          = WALL_DOOR_CLOSED;
847                 } else {
848                         v16_wall w;
849                         v16_wall_read(&w, LoadFile);
850                         Walls[i].segnum = Walls[i].sidenum = Walls[i].linked_wall = -1;
851                         Walls[i].type           = w.type;
852                         Walls[i].flags          = w.flags;
853                         Walls[i].hps            = w.hps;
854                         Walls[i].trigger        = w.trigger;
855                         Walls[i].clip_num       = w.clip_num;
856                         Walls[i].keys           = w.keys;
857                 }
858         }
859
860 #if 0
861         //===================== READ DOOR INFO ============================
862
863         if (game_fileinfo.doors_offset > -1)
864         {
865                 if (!cfseek( LoadFile, game_fileinfo.doors_offset,SEEK_SET ))   {
866
867                         for (i=0;i<game_fileinfo.doors_howmany;i++) {
868
869                                 if (game_top_fileinfo_version >= 20)
870                                         active_door_read(&ActiveDoors[i], LoadFile); // version 20 and up
871                                 else {
872                                         v19_door d;
873                                         int p;
874
875                                         v19_door_read(&d, LoadFile);
876
877                                         ActiveDoors[i].n_parts = d.n_parts;
878
879                                         for (p=0;p<d.n_parts;p++) {
880                                                 int cseg,cside;
881
882                                                 cseg = Segments[d.seg[p]].children[d.side[p]];
883                                                 cside = find_connect_side(&Segments[d.seg[p]],&Segments[cseg]);
884
885                                                 ActiveDoors[i].front_wallnum[p] = Segments[d.seg[p]].sides[d.side[p]].wall_num;
886                                                 ActiveDoors[i].back_wallnum[p] = Segments[cseg].sides[cside].wall_num;
887                                         }
888                                 }
889
890                         }
891                 }
892         }
893 #endif // 0
894
895         //==================== READ TRIGGER INFO ==========================
896
897
898 // for MACINTOSH -- assume all triggers >= verion 31 triggers.
899
900         for (i = 0; i < Num_triggers; i++)
901         {
902                 if (game_top_fileinfo_version < 31)
903                 {
904                         v30_trigger trig;
905                         int t,type;
906                         type=0;
907
908                         if (game_top_fileinfo_version < 30) {
909                                 v29_trigger trig29;
910                                 int t;
911                                 v29_trigger_read(&trig29, LoadFile);
912                                 trig.flags      = trig29.flags;
913                                 trig.num_links  = trig29.num_links;
914                                 trig.num_links  = trig29.num_links;
915                                 trig.value      = trig29.value;
916                                 trig.time       = trig29.time;
917
918                                 for (t=0;t<trig.num_links;t++) {
919                                         trig.seg[t]  = trig29.seg[t];
920                                         trig.side[t] = trig29.side[t];
921                                 }
922                         }
923                         else
924                                 v30_trigger_read(&trig, LoadFile);
925
926                         //Assert(trig.flags & TRIGGER_ON);
927                         trig.flags &= ~TRIGGER_ON;
928
929                         if (trig.flags & TRIGGER_CONTROL_DOORS)
930                                 type = TT_OPEN_DOOR;
931                         else if (trig.flags & TRIGGER_SHIELD_DAMAGE)
932                                 Int3();
933                         else if (trig.flags & TRIGGER_ENERGY_DRAIN)
934                                 Int3();
935                         else if (trig.flags & TRIGGER_EXIT)
936                                 type = TT_EXIT;
937                         else if (trig.flags & TRIGGER_ONE_SHOT)
938                                 Int3();
939                         else if (trig.flags & TRIGGER_MATCEN)
940                                 type = TT_MATCEN;
941                         else if (trig.flags & TRIGGER_ILLUSION_OFF)
942                                 type = TT_ILLUSION_OFF;
943                         else if (trig.flags & TRIGGER_SECRET_EXIT)
944                                 type = TT_SECRET_EXIT;
945                         else if (trig.flags & TRIGGER_ILLUSION_ON)
946                                 type = TT_ILLUSION_ON;
947                         else if (trig.flags & TRIGGER_UNLOCK_DOORS)
948                                 type = TT_UNLOCK_DOOR;
949                         else if (trig.flags & TRIGGER_OPEN_WALL)
950                                 type = TT_OPEN_WALL;
951                         else if (trig.flags & TRIGGER_CLOSE_WALL)
952                                 type = TT_CLOSE_WALL;
953                         else if (trig.flags & TRIGGER_ILLUSORY_WALL)
954                                 type = TT_ILLUSORY_WALL;
955                         else
956                                 Int3();
957                         Triggers[i].type        = type;
958                         Triggers[i].flags       = 0;
959                         Triggers[i].num_links   = trig.num_links;
960                         Triggers[i].num_links   = trig.num_links;
961                         Triggers[i].value       = trig.value;
962                         Triggers[i].time        = trig.time;
963                         for (t=0;t<trig.num_links;t++) {
964                                 Triggers[i].seg[t] = trig.seg[t];
965                                 Triggers[i].side[t] = trig.side[t];
966                         }
967                 }
968                 else
969                         trigger_read(&Triggers[i], LoadFile);
970         }
971
972         //================ READ CONTROL CENTER TRIGGER INFO ===============
973
974 #if 0
975         if (game_fileinfo.control_offset > -1)
976                 if (!cfseek(LoadFile, game_fileinfo.control_offset, SEEK_SET))
977                 {
978                         Assert(game_fileinfo.control_sizeof == sizeof(control_center_triggers));
979 #endif // 0
980         control_center_triggers_read_n(&ControlCenterTriggers, 1, LoadFile);
981
982         //================ READ MATERIALOGRIFIZATIONATORS INFO ===============
983
984         // mprintf((0, "Reading %i materialization centers.\n", game_fileinfo.matcen_howmany));
985         for (i = 0; i < Num_robot_centers; i++) {
986                 if (game_top_fileinfo_version < 27) {
987                         old_matcen_info m;
988                         old_matcen_info_read(&m, LoadFile);
989                         RobotCenters[i].robot_flags[0] = m.robot_flags;
990                         RobotCenters[i].robot_flags[1] = 0;
991                         RobotCenters[i].hit_points = m.hit_points;
992                         RobotCenters[i].interval = m.interval;
993                         RobotCenters[i].segnum = m.segnum;
994                         RobotCenters[i].fuelcen_num = m.fuelcen_num;
995                 }
996                 else
997                         matcen_info_read(&RobotCenters[i], LoadFile);
998                         //      Set links in RobotCenters to Station array
999                         for (j = 0; j <= Highest_segment_index; j++)
1000                         if (Segment2s[j].special == SEGMENT_IS_ROBOTMAKER)
1001                                 if (Segment2s[j].matcen_num == i)
1002                                         RobotCenters[i].fuelcen_num = Segment2s[j].value;
1003                         // mprintf((0, "   %i: flags = %08x\n", i, RobotCenters[i].robot_flags));
1004         }
1005
1006         //================ READ DL_INDICES INFO ===============
1007
1008         for (i = 0; i < Num_static_lights; i++) {
1009                 if (game_top_fileinfo_version < 29) {
1010                         mprintf((0, "Warning: Old mine version.  Not reading Dl_indices info.\n"));
1011                         Int3(); //shouldn't be here!!!
1012                 } else
1013                         dl_index_read(&Dl_indices[i], LoadFile);
1014         }
1015
1016         //      Indicate that no light has been subtracted from any vertices.
1017         clear_light_subtracted();
1018
1019         //================ READ DELTA LIGHT INFO ===============
1020
1021         for (i = 0; i < num_delta_lights; i++) {
1022                 if (game_top_fileinfo_version < 29) {
1023                         mprintf((0, "Warning: Old mine version.  Not reading delta light info.\n"));
1024                 } else
1025                         delta_light_read(&Delta_lights[i], LoadFile);
1026         }
1027
1028         //========================= UPDATE VARIABLES ======================
1029
1030         reset_objects(gs_num_objects);
1031
1032         for (i=0; i<MAX_OBJECTS; i++) {
1033                 Objects[i].next = Objects[i].prev = -1;
1034                 if (Objects[i].type != OBJ_NONE) {
1035                         int objsegnum = Objects[i].segnum;
1036
1037                         if (objsegnum > Highest_segment_index)          //bogus object
1038                                 Objects[i].type = OBJ_NONE;
1039                         else {
1040                                 Objects[i].segnum = -1;                 //avoid Assert()
1041                                 obj_link(i,objsegnum);
1042                         }
1043                 }
1044         }
1045
1046         clear_transient_objects(1);             //1 means clear proximity bombs
1047
1048         // Make sure non-transparent doors are set correctly.
1049         for (i=0; i< Num_segments; i++)
1050                 for (j=0;j<MAX_SIDES_PER_SEGMENT;j++) {
1051                         side    *sidep = &Segments[i].sides[j];
1052                         if ((sidep->wall_num != -1) && (Walls[sidep->wall_num].clip_num != -1)) {
1053                                 //mprintf((0, "Checking Wall %d\n", Segments[i].sides[j].wall_num));
1054                                 if (WallAnims[Walls[sidep->wall_num].clip_num].flags & WCF_TMAP1) {
1055                                         //mprintf((0, "Fixing non-transparent door.\n"));
1056                                         sidep->tmap_num = WallAnims[Walls[sidep->wall_num].clip_num].frames[0];
1057                                         sidep->tmap_num2 = 0;
1058                                 }
1059                         }
1060                 }
1061
1062
1063         reset_walls();
1064
1065 #if 0
1066         Num_open_doors = game_fileinfo.doors_howmany;
1067 #endif // 0
1068         Num_open_doors = 0;
1069
1070         //go through all walls, killing references to invalid triggers
1071         for (i=0;i<Num_walls;i++)
1072                 if (Walls[i].trigger >= Num_triggers) {
1073                         mprintf((0,"Removing reference to invalid trigger %d from wall %d\n",Walls[i].trigger,i));
1074                         Walls[i].trigger = -1;  //kill trigger
1075                 }
1076
1077         //go through all triggers, killing unused ones
1078         for (i=0;i<Num_triggers;) {
1079                 int w;
1080
1081                 //      Find which wall this trigger is connected to.
1082                 for (w=0; w<Num_walls; w++)
1083                         if (Walls[w].trigger == i)
1084                                 break;
1085
1086         #ifdef EDITOR
1087                 if (w == Num_walls) {
1088                         mprintf((0,"Removing unreferenced trigger %d\n",i));
1089                         remove_trigger_num(i);
1090                 }
1091                 else
1092         #endif
1093                         i++;
1094         }
1095
1096         //      MK, 10/17/95: Make walls point back at the triggers that control them.
1097         //      Go through all triggers, stuffing controlling_trigger field in Walls.
1098         {       int t;
1099
1100         for (i=0; i<Num_walls; i++)
1101                 Walls[i].controlling_trigger = -1;
1102
1103         for (t=0; t<Num_triggers; t++) {
1104                 int     l;
1105                 for (l=0; l<Triggers[t].num_links; l++) {
1106                         int     seg_num, side_num, wall_num;
1107
1108                         seg_num = Triggers[t].seg[l];
1109                         side_num = Triggers[t].side[l];
1110                         wall_num = Segments[seg_num].sides[side_num].wall_num;
1111
1112                         // -- if (Walls[wall_num].controlling_trigger != -1)
1113                         // --   Int3();
1114
1115                         //check to see that if a trigger requires a wall that it has one,
1116                         //and if it requires a matcen that it has one
1117
1118                         if (Triggers[t].type == TT_MATCEN) {
1119                                 if (Segment2s[seg_num].special != SEGMENT_IS_ROBOTMAKER)
1120                                         Int3();         //matcen trigger doesn't point to matcen
1121                         }
1122                         else if (Triggers[t].type != TT_LIGHT_OFF && Triggers[t].type != TT_LIGHT_ON) { //light triggers don't require walls
1123                                 if (wall_num == -1)
1124                                         Int3(); //      This is illegal.  This trigger requires a wall
1125                                 else
1126                                         Walls[wall_num].controlling_trigger = t;
1127                         }
1128                 }
1129         }
1130         }
1131
1132         //fix old wall structs
1133         if (game_top_fileinfo_version < 17) {
1134                 int segnum,sidenum,wallnum;
1135
1136                 for (segnum=0; segnum<=Highest_segment_index; segnum++)
1137                         for (sidenum=0;sidenum<6;sidenum++)
1138                                 if ((wallnum=Segments[segnum].sides[sidenum].wall_num) != -1) {
1139                                         Walls[wallnum].segnum = segnum;
1140                                         Walls[wallnum].sidenum = sidenum;
1141                                 }
1142         }
1143
1144         #ifndef NDEBUG
1145         {
1146                 int     sidenum;
1147                 for (sidenum=0; sidenum<6; sidenum++) {
1148                         int     wallnum = Segments[Highest_segment_index].sides[sidenum].wall_num;
1149                         if (wallnum != -1)
1150                                 if ((Walls[wallnum].segnum != Highest_segment_index) || (Walls[wallnum].sidenum != sidenum))
1151                                         Int3(); //      Error.  Bogus walls in this segment.
1152                                                                 // Consult Yuan or Mike.
1153                 }
1154         }
1155         #endif
1156
1157         //create_local_segment_data();
1158
1159         fix_object_segs();
1160
1161         #ifndef NDEBUG
1162         dump_mine_info();
1163         #endif
1164
1165         if (game_top_fileinfo_version < GAME_VERSION
1166             && !(game_top_fileinfo_version == 25 && GAME_VERSION == 26))
1167                 return 1;               //means old version
1168         else
1169                 return 0;
1170 }
1171
1172
1173 int check_segment_connections(void);
1174
1175 extern void     set_ambient_sound_flags(void);
1176
1177 // ----------------------------------------------------------------------------
1178
1179 #define LEVEL_FILE_VERSION      8
1180 //1 -> 2  add palette name
1181 //2 -> 3  add control center explosion time
1182 //3 -> 4  add reactor strength
1183 //4 -> 5  killed hostage text stuff
1184 //5 -> 6  added Secret_return_segment and Secret_return_orient
1185 //6 -> 7  added flickering lights
1186 //7 -> 8  made version 8 to be not compatible with D2 1.0 & 1.1
1187
1188 #ifndef RELEASE
1189 char *Level_being_loaded=NULL;
1190 #endif
1191
1192 #ifdef COMPACT_SEGS
1193 extern void ncache_flush();
1194 #endif
1195
1196 extern int Slide_segs_computed;
1197 extern int d1_pig_present;
1198
1199 int no_old_level_file_error=0;
1200
1201 //loads a level (.LVL) file from disk
1202 //returns 0 if success, else error code
1203 int load_level(char * filename_passed)
1204 {
1205 #ifdef EDITOR
1206         int use_compiled_level=1;
1207 #endif
1208         CFILE * LoadFile;
1209         char filename[PATH_MAX];
1210         int sig, minedata_offset, gamedata_offset;
1211         int mine_err, game_err;
1212 #ifdef NETWORK
1213         int i;
1214 #endif
1215
1216         Slide_segs_computed = 0;
1217
1218 #ifdef NETWORK
1219    if (Game_mode & GM_NETWORK)
1220          {
1221           for (i=0;i<MAX_POWERUP_TYPES;i++)
1222                 {
1223                         MaxPowerupsAllowed[i]=0;
1224                         PowerupsInMine[i]=0;
1225                 }
1226          }
1227 #endif
1228
1229         #ifdef COMPACT_SEGS
1230         ncache_flush();
1231         #endif
1232
1233         #ifndef RELEASE
1234         Level_being_loaded = filename_passed;
1235         #endif
1236
1237         strcpy(filename,filename_passed);
1238
1239         #ifdef EDITOR
1240                 //if we have the editor, try the LVL first, no matter what was passed.
1241                 //if we don't have an LVL, try what was passed or RL2  
1242                 //if we don't have the editor, we just use what was passed
1243         
1244                 change_filename_extension(filename,filename_passed,".lvl");
1245                 use_compiled_level = 0;
1246         
1247                 if (!cfexist(filename))
1248                 {
1249                         char *p = strrchr(filename_passed, '.');
1250
1251                         if (stricmp(p, ".lvl"))
1252                                 strcpy(filename, filename_passed);      // set to what was passed
1253                         else
1254                                 change_filename_extension(filename, filename, ".rl2");
1255                         use_compiled_level = 1;
1256                 }               
1257         #endif
1258
1259         LoadFile = cfopen( filename, "rb" );
1260
1261         if (!LoadFile)  {
1262                 #ifdef EDITOR
1263                         mprintf((0,"Can't open level file <%s>\n", filename));
1264                         return 1;
1265                 #else
1266                         Error("Can't open file <%s>\n",filename);
1267                 #endif
1268         }
1269
1270         strcpy( Gamesave_current_filename, filename );
1271
1272 //      #ifdef NEWDEMO
1273 //      if ( Newdemo_state == ND_STATE_RECORDING )
1274 //              newdemo_record_start_demo();
1275 //      #endif
1276
1277         sig                      = cfile_read_int(LoadFile);
1278         Gamesave_current_version = cfile_read_int(LoadFile);
1279         mprintf((0, "Gamesave_current_version = %d\n", Gamesave_current_version));
1280         minedata_offset          = cfile_read_int(LoadFile);
1281         gamedata_offset          = cfile_read_int(LoadFile);
1282
1283         Assert(sig == MAKE_SIG('P','L','V','L'));
1284
1285         if (Gamesave_current_version >= 8) {    //read dummy data
1286                 cfile_read_int(LoadFile);
1287                 cfile_read_short(LoadFile);
1288                 cfile_read_byte(LoadFile);
1289         }
1290
1291         if (Gamesave_current_version < 5)
1292                 cfile_read_int(LoadFile);       //was hostagetext_offset
1293
1294         if (Gamesave_current_version > 1)
1295                 cfgets(Current_level_palette,sizeof(Current_level_palette),LoadFile);
1296         if (Gamesave_current_version <= 1 || Current_level_palette[0]==0) // descent 1 level
1297                 strcpy(Current_level_palette, DEFAULT_LEVEL_PALETTE);
1298
1299         if (Gamesave_current_version >= 3)
1300                 Base_control_center_explosion_time = cfile_read_int(LoadFile);
1301         else
1302                 Base_control_center_explosion_time = DEFAULT_CONTROL_CENTER_EXPLOSION_TIME;
1303
1304         if (Gamesave_current_version >= 4)
1305                 Reactor_strength = cfile_read_int(LoadFile);
1306         else
1307                 Reactor_strength = -1;  //use old defaults
1308
1309         if (Gamesave_current_version >= 7) {
1310                 int i;
1311
1312                 Num_flickering_lights = cfile_read_int(LoadFile);
1313                 Assert((Num_flickering_lights >= 0) && (Num_flickering_lights < MAX_FLICKERING_LIGHTS));
1314                 for (i = 0; i < Num_flickering_lights; i++)
1315                         flickering_light_read(&Flickering_lights[i], LoadFile);
1316         }
1317         else
1318                 Num_flickering_lights = 0;
1319
1320         if (Gamesave_current_version < 6) {
1321                 Secret_return_segment = 0;
1322                 Secret_return_orient.rvec.x = F1_0;
1323                 Secret_return_orient.rvec.y = 0;
1324                 Secret_return_orient.rvec.z = 0;
1325                 Secret_return_orient.fvec.x = 0;
1326                 Secret_return_orient.fvec.y = F1_0;
1327                 Secret_return_orient.fvec.z = 0;
1328                 Secret_return_orient.uvec.x = 0;
1329                 Secret_return_orient.uvec.y = 0;
1330                 Secret_return_orient.uvec.z = F1_0;
1331         } else {
1332                 Secret_return_segment = cfile_read_int(LoadFile);
1333                 Secret_return_orient.rvec.x = cfile_read_int(LoadFile);
1334                 Secret_return_orient.rvec.y = cfile_read_int(LoadFile);
1335                 Secret_return_orient.rvec.z = cfile_read_int(LoadFile);
1336                 Secret_return_orient.fvec.x = cfile_read_int(LoadFile);
1337                 Secret_return_orient.fvec.y = cfile_read_int(LoadFile);
1338                 Secret_return_orient.fvec.z = cfile_read_int(LoadFile);
1339                 Secret_return_orient.uvec.x = cfile_read_int(LoadFile);
1340                 Secret_return_orient.uvec.y = cfile_read_int(LoadFile);
1341                 Secret_return_orient.uvec.z = cfile_read_int(LoadFile);
1342         }
1343
1344         cfseek(LoadFile,minedata_offset,SEEK_SET);
1345         #ifdef EDITOR
1346         if (!use_compiled_level) {
1347                 mine_err = load_mine_data(LoadFile);
1348 #if 0 // get from d1src if needed
1349                 // Compress all uv coordinates in mine, improves texmap precision. --MK, 02/19/96
1350                 compress_uv_coordinates_all();
1351 #endif
1352         } else
1353         #endif
1354                 //NOTE LINK TO ABOVE!!
1355                 mine_err = load_mine_data_compiled(LoadFile);
1356
1357         if (mine_err == -1) {   //error!!
1358                 cfclose(LoadFile);
1359                 return 2;
1360         }
1361
1362         cfseek(LoadFile,gamedata_offset,SEEK_SET);
1363         game_err = load_game_data(LoadFile);
1364
1365         if (game_err == -1) {   //error!!
1366                 cfclose(LoadFile);
1367                 return 3;
1368         }
1369
1370         //======================== CLOSE FILE =============================
1371
1372         cfclose( LoadFile );
1373
1374         set_ambient_sound_flags();
1375
1376         #if 0   //def EDITOR
1377         write_game_text_file(filename);
1378         if (Errors_in_mine) {
1379                 if (is_real_level(filename)) {
1380                         char  ErrorMessage[200];
1381
1382                         sprintf( ErrorMessage, "Warning: %i errors in %s!\n", Errors_in_mine, Level_being_loaded );
1383                         stop_time();
1384                         gr_palette_load(gr_palette);
1385                         nm_messagebox( NULL, 1, "Continue", ErrorMessage );
1386                         start_time();
1387                 } else
1388                         mprintf((1, "Error: %i errors in %s.\n", Errors_in_mine, Level_being_loaded));
1389         }
1390         #endif
1391
1392         #ifdef EDITOR
1393         //If a Descent 1 level and the Descent 1 pig isn't present, pretend it's a Descent 2 level.
1394         if ((Function_mode == FMODE_EDITOR) && (Gamesave_current_version <= 3) && !d1_pig_present)
1395         {
1396                 if (!no_old_level_file_error)
1397                         Warning("A Descent 1 level was loaded,\n"
1398                                         "and there is no Descent 1 texture\n"
1399                                         "set available. Saving it will\n"
1400                                         "convert it to a Descent 2 level.");
1401
1402                 Gamesave_current_version = LEVEL_FILE_VERSION;
1403         }
1404         #endif
1405
1406         #ifdef EDITOR
1407         if (Function_mode == FMODE_EDITOR)
1408                 editor_status("Loaded NEW mine %s, \"%s\"",filename,Current_level_name);
1409         #endif
1410
1411         #if !defined(NDEBUG) && !defined(COMPACT_SEGS)
1412         if (check_segment_connections())
1413                 nm_messagebox( "ERROR", 1, "Ok", 
1414                                 "Connectivity errors detected in\n"
1415                                 "mine.  See monochrome screen for\n"
1416                                 "details, and contact Matt or Mike." );
1417         #endif
1418
1419         return 0;
1420 }
1421
1422 #ifdef EDITOR
1423 int get_level_name()
1424 {
1425 //NO_UI!!!      UI_WINDOW                               *NameWindow = NULL;
1426 //NO_UI!!!      UI_GADGET_INPUTBOX      *NameText;
1427 //NO_UI!!!      UI_GADGET_BUTTON                *QuitButton;
1428 //NO_UI!!!
1429 //NO_UI!!!      // Open a window with a quit button
1430 //NO_UI!!!      NameWindow = ui_open_window( 20, 20, 300, 110, WIN_DIALOG );
1431 //NO_UI!!!      QuitButton = ui_add_gadget_button( NameWindow, 150-24, 60, 48, 40, "Done", NULL );
1432 //NO_UI!!!
1433 //NO_UI!!!      ui_wprintf_at( NameWindow, 10, 12,"Please enter a name for this mine:" );
1434 //NO_UI!!!      NameText = ui_add_gadget_inputbox( NameWindow, 10, 30, LEVEL_NAME_LEN, LEVEL_NAME_LEN, Current_level_name );
1435 //NO_UI!!!
1436 //NO_UI!!!      NameWindow->keyboard_focus_gadget = (UI_GADGET *)NameText;
1437 //NO_UI!!!      QuitButton->hotkey = KEY_ENTER;
1438 //NO_UI!!!
1439 //NO_UI!!!      ui_gadget_calc_keys(NameWindow);
1440 //NO_UI!!!
1441 //NO_UI!!!      while (!QuitButton->pressed && last_keypress!=KEY_ENTER) {
1442 //NO_UI!!!              ui_mega_process();
1443 //NO_UI!!!              ui_window_do_gadgets(NameWindow);
1444 //NO_UI!!!      }
1445 //NO_UI!!!
1446 //NO_UI!!!      strcpy( Current_level_name, NameText->text );
1447 //NO_UI!!!
1448 //NO_UI!!!      if ( NameWindow!=NULL ) {
1449 //NO_UI!!!              ui_close_window( NameWindow );
1450 //NO_UI!!!              NameWindow = NULL;
1451 //NO_UI!!!      }
1452 //NO_UI!!!
1453
1454         newmenu_item m[2];
1455
1456         m[0].type = NM_TYPE_TEXT; m[0].text = "Please enter a name for this mine:";
1457         m[1].type = NM_TYPE_INPUT; m[1].text = Current_level_name; m[1].text_len = LEVEL_NAME_LEN;
1458
1459         return newmenu_do( NULL, "Enter mine name", 2, m, NULL ) >= 0;
1460
1461 }
1462 #endif
1463
1464
1465 #ifdef EDITOR
1466
1467 int     Errors_in_mine;
1468
1469 // -----------------------------------------------------------------------------
1470 int compute_num_delta_light_records(void)
1471 {
1472         int     i;
1473         int     total = 0;
1474
1475         for (i=0; i<Num_static_lights; i++) {
1476                 total += Dl_indices[i].count;
1477         }
1478
1479         return total;
1480
1481 }
1482
1483 // -----------------------------------------------------------------------------
1484 // Save game
1485 int save_game_data(PHYSFS_file *SaveFile)
1486 {
1487         short game_top_fileinfo_version = Gamesave_current_version >= 5 ? 31 : 25;
1488         int  player_offset, object_offset, walls_offset, doors_offset, triggers_offset, control_offset, matcen_offset; //, links_offset;
1489         int     dl_indices_offset, delta_light_offset;
1490         int offset_offset, end_offset;
1491         int num_delta_lights;
1492         int i;
1493
1494         //===================== SAVE FILE INFO ========================
1495
1496         PHYSFS_writeSLE16(SaveFile, 0x6705);    // signature
1497         PHYSFS_writeSLE16(SaveFile, game_top_fileinfo_version);
1498         PHYSFS_writeSLE32(SaveFile, sizeof(game_fileinfo));
1499         PHYSFS_write(SaveFile, Current_level_name, 15, 1);
1500         PHYSFS_writeSLE32(SaveFile, Current_level_num);
1501         offset_offset = PHYSFS_tell(SaveFile);  // write the offsets later
1502         PHYSFS_writeSLE32(SaveFile, -1);
1503         PHYSFS_writeSLE32(SaveFile, sizeof(player));
1504
1505 #define WRITE_HEADER_ENTRY(t, n) do { PHYSFS_writeSLE32(SaveFile, -1); PHYSFS_writeSLE32(SaveFile, n); PHYSFS_writeSLE32(SaveFile, sizeof(t)); } while(0)
1506
1507         WRITE_HEADER_ENTRY(object, Highest_object_index + 1);
1508         WRITE_HEADER_ENTRY(wall, Num_walls);
1509         WRITE_HEADER_ENTRY(active_door, Num_open_doors);
1510         WRITE_HEADER_ENTRY(trigger, Num_triggers);
1511         WRITE_HEADER_ENTRY(0, 0);               // links (removed by Parallax)
1512         WRITE_HEADER_ENTRY(control_center_triggers, 1);
1513         WRITE_HEADER_ENTRY(matcen_info, Num_robot_centers);
1514
1515         if (game_top_fileinfo_version >= 29)
1516         {
1517                 WRITE_HEADER_ENTRY(dl_index, Num_static_lights);
1518                 WRITE_HEADER_ENTRY(delta_light, num_delta_lights = compute_num_delta_light_records());
1519         }
1520
1521         // Write the mine name
1522         if (game_top_fileinfo_version >= 31)
1523                 PHYSFSX_printf(SaveFile, "%s\n", Current_level_name);
1524         else if (game_top_fileinfo_version >= 14)
1525                 PHYSFSX_writeString(SaveFile, Current_level_name);
1526
1527         if (game_top_fileinfo_version >= 19)
1528         {
1529                 PHYSFS_writeSLE16(SaveFile, N_polygon_models);
1530                 PHYSFS_write(SaveFile, Pof_names, sizeof(*Pof_names), N_polygon_models);
1531         }
1532
1533         //==================== SAVE PLAYER INFO ===========================
1534
1535         player_offset = PHYSFS_tell(SaveFile);
1536         PHYSFS_write(SaveFile, &Players[Player_num], sizeof(player), 1);        // not endian friendly, but not used either
1537
1538         //==================== SAVE OBJECT INFO ===========================
1539
1540         object_offset = PHYSFS_tell(SaveFile);
1541         //fwrite( &Objects, sizeof(object), game_fileinfo.object_howmany, SaveFile );
1542         {
1543                 for (i = 0; i <= Highest_object_index; i++)
1544                         write_object(&Objects[i], game_top_fileinfo_version, SaveFile);
1545         }
1546
1547         //==================== SAVE WALL INFO =============================
1548
1549         walls_offset = PHYSFS_tell(SaveFile);
1550         for (i = 0; i < Num_walls; i++)
1551                 wall_write(&Walls[i], game_top_fileinfo_version, SaveFile);
1552
1553         //==================== SAVE DOOR INFO =============================
1554
1555 #if 0
1556         doors_offset = PHYSFS_tell(SaveFile);
1557         for (i = 0; i < Num_open_doors; i++)
1558                 door_write(&ActiveDoors[i], game_top_fileinfo_version, SaveFile);
1559 #endif
1560
1561         //==================== SAVE TRIGGER INFO =============================
1562
1563         triggers_offset = PHYSFS_tell(SaveFile);
1564         for (i = 0; i < Num_triggers; i++)
1565                 trigger_write(&Triggers[i], game_top_fileinfo_version, SaveFile);
1566
1567         //================ SAVE CONTROL CENTER TRIGGER INFO ===============
1568
1569         control_offset = PHYSFS_tell(SaveFile);
1570         control_center_triggers_write(&ControlCenterTriggers, SaveFile);
1571
1572
1573         //================ SAVE MATERIALIZATION CENTER TRIGGER INFO ===============
1574
1575         matcen_offset = PHYSFS_tell(SaveFile);
1576         // mprintf((0, "Writing %i materialization centers\n", game_fileinfo.matcen_howmany));
1577         // { int i;
1578         // for (i=0; i<game_fileinfo.matcen_howmany; i++)
1579         //      mprintf((0, "   %i: robot_flags = %08x\n", i, RobotCenters[i].robot_flags));
1580         // }
1581         for (i = 0; i < Num_robot_centers; i++)
1582                 matcen_info_write(&RobotCenters[i], game_top_fileinfo_version, SaveFile);
1583
1584         //================ SAVE DELTA LIGHT INFO ===============
1585         if (game_top_fileinfo_version >= 29)
1586         {
1587                 dl_indices_offset = PHYSFS_tell(SaveFile);
1588                 for (i = 0; i < Num_static_lights; i++)
1589                         dl_index_write(&Dl_indices[i], SaveFile);
1590
1591                 delta_light_offset = PHYSFS_tell(SaveFile);
1592                 for (i = 0; i < num_delta_lights; i++)
1593                         delta_light_write(&Delta_lights[i], SaveFile);
1594         }
1595
1596         //============= SAVE OFFSETS ===============
1597
1598         end_offset = PHYSFS_tell(SaveFile);
1599
1600         // Update the offset fields
1601
1602 #define WRITE_OFFSET(o, n) do { PHYSFS_seek(SaveFile, offset_offset); PHYSFS_writeSLE32(SaveFile, o ## _offset); offset_offset += sizeof(int)*n; } while (0)
1603
1604         WRITE_OFFSET(player, 2);
1605         WRITE_OFFSET(object, 3);
1606         WRITE_OFFSET(walls, 3);
1607         WRITE_OFFSET(doors, 3);
1608         WRITE_OFFSET(triggers, 6);
1609         WRITE_OFFSET(control, 3);
1610         WRITE_OFFSET(matcen, 3);
1611         if (game_top_fileinfo_version >= 29)
1612         {
1613                 WRITE_OFFSET(dl_indices, 3);
1614                 WRITE_OFFSET(delta_light, 0);
1615         }
1616
1617         // Go back to end of data
1618         PHYSFS_seek(SaveFile, end_offset);
1619
1620         return 0;
1621 }
1622
1623 int save_mine_data(FILE * SaveFile);
1624
1625 // -----------------------------------------------------------------------------
1626 // Save game
1627 int save_level_sub(char * filename, int compiled_version)
1628 {
1629         PHYSFS_file * SaveFile;
1630         char temp_filename[PATH_MAX];
1631         int minedata_offset=0,gamedata_offset=0;
1632
1633 //      if ( !compiled_version )
1634         {
1635                 write_game_text_file(filename);
1636
1637                 if (Errors_in_mine) {
1638                         if (is_real_level(filename)) {
1639                                 char  ErrorMessage[200];
1640         
1641                                 sprintf( ErrorMessage, "Warning: %i errors in this mine!\n", Errors_in_mine );
1642                                 stop_time();
1643                                 gr_palette_load(gr_palette);
1644          
1645                                 if (nm_messagebox( NULL, 2, "Cancel Save", "Save", ErrorMessage )!=1)   {
1646                                         start_time();
1647                                         return 1;
1648                                 }
1649                                 start_time();
1650                         } else
1651                                 mprintf((1, "Error: %i errors in this mine.  See the 'txm' file.\n", Errors_in_mine));
1652                 }
1653 //              change_filename_extension(temp_filename,filename,".LVL");
1654         }
1655 //      else
1656         {
1657                 if (Gamesave_current_version <= 3)
1658                         change_filename_extension(temp_filename, filename, ".RDL");
1659                 else
1660                         change_filename_extension(temp_filename, filename, ".RL2");
1661         }
1662
1663         SaveFile = PHYSFSX_openWriteBuffered(temp_filename);
1664         if (!SaveFile)
1665         {
1666                 char ErrorMessage[256];
1667
1668                 char fname[20];
1669                 _splitpath( temp_filename, NULL, NULL, fname, NULL );
1670
1671                 sprintf( ErrorMessage, \
1672                         "ERROR: Cannot write to '%s'.\nYou probably need to check out a locked\nversion of the file. You should save\nthis under a different filename, and then\ncheck out a locked copy by typing\n\'co -l %s.lvl'\nat the DOS prompt.\n" 
1673                         , temp_filename, fname );
1674                 stop_time();
1675                 gr_palette_load(gr_palette);
1676                 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
1677                 start_time();
1678                 return 1;
1679         }
1680
1681         if (Current_level_name[0] == 0)
1682                 strcpy(Current_level_name,"Untitled");
1683
1684         clear_transient_objects(1);             //1 means clear proximity bombs
1685
1686         compress_objects();             //after this, Highest_object_index == num objects
1687
1688         //make sure player is in a segment
1689         if (update_object_seg(&Objects[Players[0].objnum]) == 0) {
1690                 if (ConsoleObject->segnum > Highest_segment_index)
1691                         ConsoleObject->segnum = 0;
1692                 compute_segment_center(&ConsoleObject->pos,&(Segments[ConsoleObject->segnum]));
1693         }
1694  
1695         fix_object_segs();
1696
1697         //Write the header
1698
1699         PHYSFS_writeSLE32(SaveFile, MAKE_SIG('P','L','V','L'));
1700         PHYSFS_writeSLE32(SaveFile, Gamesave_current_version);
1701
1702         //save placeholders
1703         PHYSFS_writeSLE32(SaveFile, minedata_offset);
1704         PHYSFS_writeSLE32(SaveFile, gamedata_offset);
1705
1706         //Now write the damn data
1707
1708         if (Gamesave_current_version >= 8)
1709         {
1710                 //write the version 8 data (to make file unreadable by 1.0 & 1.1)
1711                 PHYSFS_writeSLE32(SaveFile, GameTime);
1712                 PHYSFS_writeSLE16(SaveFile, FrameCount);
1713                 PHYSFSX_writeU8(SaveFile, FrameTime);
1714         }
1715
1716         if (Gamesave_current_version < 5)
1717                 PHYSFS_writeSLE32(SaveFile, -1);       //was hostagetext_offset
1718
1719         // Write the palette file name
1720         if (Gamesave_current_version > 1)
1721                 PHYSFSX_printf(SaveFile, "%s\n", Current_level_palette);
1722
1723         if (Gamesave_current_version >= 3)
1724                 PHYSFS_writeSLE32(SaveFile, Base_control_center_explosion_time);
1725         if (Gamesave_current_version >= 4)
1726                 PHYSFS_writeSLE32(SaveFile, Reactor_strength);
1727
1728         if (Gamesave_current_version >= 7)
1729         {
1730                 int i;
1731
1732                 PHYSFS_writeSLE32(SaveFile, Num_flickering_lights);
1733                 for (i = 0; i < Num_flickering_lights; i++)
1734                         flickering_light_write(&Flickering_lights[i], SaveFile);
1735         }
1736
1737         if (Gamesave_current_version >= 6)
1738         {
1739                 PHYSFS_writeSLE32(SaveFile, Secret_return_segment);
1740                 PHYSFSX_writeVector(SaveFile, &Secret_return_orient.rvec);
1741                 PHYSFSX_writeVector(SaveFile, &Secret_return_orient.fvec);
1742                 PHYSFSX_writeVector(SaveFile, &Secret_return_orient.uvec);
1743         }
1744
1745         minedata_offset = PHYSFS_tell(SaveFile);
1746 #if 0   // only save compiled mine data
1747         if ( !compiled_version )        
1748                 save_mine_data(SaveFile);
1749         else
1750 #endif
1751                 save_mine_data_compiled(SaveFile);
1752         gamedata_offset = PHYSFS_tell(SaveFile);
1753         save_game_data(SaveFile);
1754
1755         PHYSFS_seek(SaveFile, sizeof(int) + sizeof(Gamesave_current_version));
1756         PHYSFS_writeSLE32(SaveFile, minedata_offset);
1757         PHYSFS_writeSLE32(SaveFile, gamedata_offset);
1758
1759         if (Gamesave_current_version < 5)
1760                 PHYSFS_writeSLE32(SaveFile, PHYSFS_fileLength(SaveFile));
1761
1762         //==================== CLOSE THE FILE =============================
1763         PHYSFS_close(SaveFile);
1764
1765 //      if ( !compiled_version )
1766         {
1767                 if (Function_mode == FMODE_EDITOR)
1768                         editor_status("Saved mine %s, \"%s\"",filename,Current_level_name);
1769         }
1770
1771         return 0;
1772
1773 }
1774
1775 #if 0 //dunno - 3rd party stuff?
1776 extern void compress_uv_coordinates_all(void);
1777 #endif
1778
1779 int save_level(char * filename)
1780 {
1781         int r1;
1782
1783         // Save normal version...
1784         //save_level_sub(filename, 0);  // just save compiled one
1785
1786         // Save compiled version...
1787         r1 = save_level_sub(filename, 1);
1788
1789         return r1;
1790 }
1791
1792 #endif  //EDITOR
1793
1794 #ifndef NDEBUG
1795 void dump_mine_info(void)
1796 {
1797         int     segnum, sidenum;
1798         fix     min_u, max_u, min_v, max_v, min_l, max_l, max_sl;
1799
1800         min_u = F1_0*1000;
1801         min_v = min_u;
1802         min_l = min_u;
1803
1804         max_u = -min_u;
1805         max_v = max_u;
1806         max_l = max_u;
1807
1808         max_sl = 0;
1809
1810         for (segnum=0; segnum<=Highest_segment_index; segnum++) {
1811                 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
1812                         int     vertnum;
1813                         side    *sidep = &Segments[segnum].sides[sidenum];
1814
1815                         if (Segment2s[segnum].static_light > max_sl)
1816                                 max_sl = Segment2s[segnum].static_light;
1817
1818                         for (vertnum=0; vertnum<4; vertnum++) {
1819                                 if (sidep->uvls[vertnum].u < min_u)
1820                                         min_u = sidep->uvls[vertnum].u;
1821                                 else if (sidep->uvls[vertnum].u > max_u)
1822                                         max_u = sidep->uvls[vertnum].u;
1823
1824                                 if (sidep->uvls[vertnum].v < min_v)
1825                                         min_v = sidep->uvls[vertnum].v;
1826                                 else if (sidep->uvls[vertnum].v > max_v)
1827                                         max_v = sidep->uvls[vertnum].v;
1828
1829                                 if (sidep->uvls[vertnum].l < min_l)
1830                                         min_l = sidep->uvls[vertnum].l;
1831                                 else if (sidep->uvls[vertnum].l > max_l)
1832                                         max_l = sidep->uvls[vertnum].l;
1833                         }
1834
1835                 }
1836         }
1837
1838 //      mprintf((0, "Smallest uvl = %7.3f %7.3f %7.3f.  Largest uvl = %7.3f %7.3f %7.3f\n", f2fl(min_u), f2fl(min_v), f2fl(min_l), f2fl(max_u), f2fl(max_v), f2fl(max_l)));
1839 //      mprintf((0, "Static light maximum = %7.3f\n", f2fl(max_sl)));
1840 //      mprintf((0, "Number of walls: %i\n", Num_walls));
1841
1842 }
1843
1844 #endif
1845
1846 #ifdef EDITOR
1847
1848 //read in every level in mission and save out compiled version 
1849 void save_all_compiled_levels(void)
1850 {
1851         do_load_save_levels(1);
1852 }
1853
1854 //read in every level in mission
1855 void load_all_levels(void)
1856 {
1857         do_load_save_levels(0);
1858 }
1859
1860
1861 void do_load_save_levels(int save)
1862 {
1863         int level_num;
1864
1865         if (! SafetyCheck())
1866                 return;
1867
1868         no_old_level_file_error=1;
1869
1870         for (level_num=1;level_num<=Last_level;level_num++) {
1871                 load_level(Level_names[level_num-1]);
1872                 load_palette(Current_level_palette,1,1);                //don't change screen
1873                 if (save)
1874                         save_level_sub(Level_names[level_num-1],1);
1875         }
1876
1877         for (level_num=-1;level_num>=Last_secret_level;level_num--) {
1878                 load_level(Secret_level_names[-level_num-1]);
1879                 load_palette(Current_level_palette,1,1);                //don't change screen
1880                 if (save)
1881                         save_level_sub(Secret_level_names[-level_num-1],1);
1882         }
1883
1884         no_old_level_file_error=0;
1885
1886 }
1887
1888 #endif