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.
19 char gamesave_rcsid[] = "$Id: gamesave.c,v 1.5 2001-10-25 02:19:31 bradleyb Exp $";
35 #include "editor/editor.h"
66 char Gamesave_current_filename[128];
68 #define GAME_VERSION 32
69 #define GAME_COMPATIBLE_VERSION 22
71 //version 28->29 add delta light support
72 //version 27->28 controlcen id now is reactor number, not model number
74 //version 29->30 changed trigger structure
75 //version 30->31 changed trigger structure some more
76 //version 31->32 change segment structure, make it 512 bytes w/o editor, add Segment2s array.
78 #define MENU_CURSOR_X_MIN MENU_X
79 #define MENU_CURSOR_X_MAX MENU_X+6
81 //Start old wall structures
83 typedef struct v16_wall {
84 byte type; // What kind of special wall.
85 byte flags; // Flags for the wall.
86 fix hps; // "Hit points" of the wall.
87 byte trigger; // Which trigger is associated with the wall.
88 byte clip_num; // Which animation associated with the wall.
92 typedef struct v19_wall {
93 int segnum,sidenum; // Seg & side for this wall
94 byte type; // What kind of special wall.
95 byte flags; // Flags for the wall.
96 fix hps; // "Hit points" of the wall.
97 byte trigger; // Which trigger is associated with the wall.
98 byte clip_num; // Which animation associated with the wall.
100 int linked_wall; // number of linked wall
103 typedef struct v19_door {
104 int n_parts; // for linked walls
105 short seg[2]; // Segment pointer of door.
106 short side[2]; // Side number of door.
107 short type[2]; // What kind of door animation.
108 fix open; // How long it has been open.
111 //End old wall structures
113 //old trigger structs
115 typedef struct v29_trigger {
122 short seg[MAX_WALLS_PER_LINK];
123 short side[MAX_WALLS_PER_LINK];
126 typedef struct v30_trigger {
129 byte pad; //keep alignment
132 short seg[MAX_WALLS_PER_LINK];
133 short side[MAX_WALLS_PER_LINK];
136 //flags for V30 & below triggers
137 #define TRIGGER_CONTROL_DOORS 1 // Control Trigger
138 #define TRIGGER_SHIELD_DAMAGE 2 // Shield Damage Trigger
139 #define TRIGGER_ENERGY_DRAIN 4 // Energy Drain Trigger
140 #define TRIGGER_EXIT 8 // End of level Trigger
141 #define TRIGGER_ON 16 // Whether Trigger is active
142 #define TRIGGER_ONE_SHOT 32 // If Trigger can only be triggered once
143 #define TRIGGER_MATCEN 64 // Trigger for materialization centers
144 #define TRIGGER_ILLUSION_OFF 128 // Switch Illusion OFF trigger
145 #define TRIGGER_SECRET_EXIT 256 // Exit to secret level
146 #define TRIGGER_ILLUSION_ON 512 // Switch Illusion ON trigger
147 #define TRIGGER_UNLOCK_DOORS 1024 // Unlocks a door
148 #define TRIGGER_OPEN_WALL 2048 // Makes a wall open
149 #define TRIGGER_CLOSE_WALL 4096 // Makes a wall closed
150 #define TRIGGER_ILLUSORY_WALL 8192 // Makes a wall illusory
153 ushort fileinfo_signature;
154 ushort fileinfo_version;
156 } game_top_fileinfo; // Should be same as first two fields below...
159 ushort fileinfo_signature;
160 ushort fileinfo_version;
162 char mine_filename[15];
164 int player_offset; // Player info
166 int object_offset; // Object info
176 int triggers_howmany;
187 int dl_indices_offset;
188 int dl_indices_howmany;
189 int dl_indices_sizeof;
190 int delta_light_offset;
191 int delta_light_howmany;
192 int delta_light_sizeof;
195 // LINT: adding function prototypes
196 void read_object(object *obj, CFILE *f, int version);
197 void write_object(object *obj, FILE *f);
198 void do_load_save_levels(int save);
199 void dump_mine_info(void);
201 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
202 extern char PowerupsInMine[MAX_POWERUP_TYPES];
205 extern char mine_filename[];
206 extern int save_mine_data_compiled(FILE * SaveFile);
208 //--unused-- char mine_filename[128];
211 int Gamesave_num_org_robots = 0;
212 //--unused-- grs_bitmap * Gamesave_saved_bitmap = NULL;
215 // Return true if this level has a name of the form "level??"
216 // Note that a pathspec can appear at the beginning of the filename.
217 int is_real_level(char *filename)
219 int len = strlen(filename);
224 //mprintf((0, "String = [%s]\n", &filename[len-11]));
225 return !strnicmp(&filename[len-11], "level", 5);
230 void change_filename_extension( char *dest, char *src, char *new_ext )
239 for (i=1; i<strlen(dest); i++ )
240 if (dest[i]=='.'||dest[i]==' '||dest[i]==0)
245 dest[i+1]=new_ext[0];
246 dest[i+2]=new_ext[1];
247 dest[i+3]=new_ext[2];
253 //--unused-- vms_angvec zero_angles={0,0,0};
255 #define vm_angvec_zero(v) do {(v)->p=(v)->b=(v)->h=0;} while (0)
257 int Gamesave_num_players=0;
259 int N_save_pof_names;
260 char Save_pof_names[MAX_POLYGON_MODELS][FILENAME_LEN];
262 void check_and_fix_matrix(vms_matrix *m);
264 void verify_object( object * obj ) {
266 obj->lifeleft = IMMORTAL_TIME; //all loaded object are immortal, for now
268 if ( obj->type == OBJ_ROBOT ) {
269 Gamesave_num_org_robots++;
271 // Make sure valid id...
272 if ( obj->id >= N_robot_types )
273 obj->id = obj->id % N_robot_types;
275 // Make sure model number & size are correct...
276 if ( obj->render_type == RT_POLYOBJ ) {
277 Assert(Robot_info[obj->id].model_num != -1);
278 //if you fail this assert, it means that a robot in this level
279 //hasn't been loaded, possibly because he's marked as
280 //non-shareware. To see what robot number, print obj->id.
282 Assert(Robot_info[obj->id].always_0xabcd == 0xabcd);
283 //if you fail this assert, it means that the robot_ai for
284 //a robot in this level hasn't been loaded, possibly because
285 //it's marked as non-shareware. To see what robot number,
288 obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
289 obj->size = Polygon_models[obj->rtype.pobj_info.model_num].rad;
291 //@@Took out this ugly hack 1/12/96, because Mike has added code
292 //@@that should fix it in a better way.
293 //@@//this is a super-ugly hack. Since the baby stripe robots have
294 //@@//their firing point on their bounding sphere, the firing points
295 //@@//can poke through a wall if the robots are very close to it. So
296 //@@//we make their radii bigger so the guns can't get too close to
298 //@@if (Robot_info[obj->id].flags & RIF_BIG_RADIUS)
299 //@@ obj->size = (obj->size*3)/2;
301 //@@if (obj->control_type==CT_AI && Robot_info[obj->id].attack_type)
302 //@@ obj->size = obj->size*3/4;
305 if (obj->id == 65) //special "reactor" robots
306 obj->movement_type = MT_NONE;
308 if (obj->movement_type == MT_PHYSICS) {
309 obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
310 obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
313 else { //Robots taken care of above
315 if ( obj->render_type == RT_POLYOBJ ) {
317 char *name = Save_pof_names[obj->rtype.pobj_info.model_num];
319 for (i=0;i<N_polygon_models;i++)
320 if (!stricmp(Pof_names[i],name)) { //found it!
321 // mprintf((0,"Mapping <%s> to %d (was %d)\n",name,i,obj->rtype.pobj_info.model_num));
322 obj->rtype.pobj_info.model_num = i;
328 if ( obj->type == OBJ_POWERUP ) {
329 if ( obj->id >= N_powerup_types ) {
331 Assert( obj->render_type != RT_POLYOBJ );
333 obj->control_type = CT_POWERUP;
334 obj->size = Powerup_info[obj->id].size;
335 obj->ctype.powerup_info.creation_time = 0;
338 if (Game_mode & GM_NETWORK)
340 if (multi_powerup_is_4pack(obj->id))
342 PowerupsInMine[obj->id-1]+=4;
343 MaxPowerupsAllowed[obj->id-1]+=4;
345 PowerupsInMine[obj->id]++;
346 MaxPowerupsAllowed[obj->id]++;
347 mprintf ((0,"PowerupLimiter: ID=%d\n",obj->id));
348 if (obj->id>MAX_POWERUP_TYPES)
349 mprintf ((1,"POWERUP: Overwriting array bounds!! Get JL!\n"));
355 if ( obj->type == OBJ_WEAPON ) {
356 if ( obj->id >= N_weapon_types ) {
358 Assert( obj->render_type != RT_POLYOBJ );
361 if (obj->id == PMINE_ID) { //make sure pmines have correct values
363 obj->mtype.phys_info.mass = Weapon_info[obj->id].mass;
364 obj->mtype.phys_info.drag = Weapon_info[obj->id].drag;
365 obj->mtype.phys_info.flags |= PF_FREE_SPINNING;
367 // Make sure model number & size are correct...
368 Assert( obj->render_type == RT_POLYOBJ );
370 obj->rtype.pobj_info.model_num = Weapon_info[obj->id].model_num;
371 obj->size = Polygon_models[obj->rtype.pobj_info.model_num].rad;
375 if ( obj->type == OBJ_CNTRLCEN ) {
377 obj->render_type = RT_POLYOBJ;
378 obj->control_type = CT_CNTRLCEN;
380 //@@// Make model number is correct...
381 //@@for (i=0; i<Num_total_object_types; i++ )
382 //@@ if ( ObjType[i] == OL_CONTROL_CENTER ) {
383 //@@ obj->rtype.pobj_info.model_num = ObjId[i];
384 //@@ obj->shields = ObjStrength[i];
391 // Check, and set, strength of reactor
392 for (i=0; i<Num_total_object_types; i++ )
393 if ( ObjType[i]==OL_CONTROL_CENTER && ObjId[i] == obj->id ) {
394 obj->shields = ObjStrength[i];
397 Assert(i < Num_total_object_types); //make sure we found it
402 if ( obj->type == OBJ_PLAYER ) {
405 //Assert(obj == Player);
407 if ( obj == ConsoleObject )
408 init_player_object();
410 if (obj->render_type == RT_POLYOBJ) //recover from Matt's pof file matchup bug
411 obj->rtype.pobj_info.model_num = Player_ship->model_num;
413 //Make sure orient matrix is orthogonal
414 check_and_fix_matrix(&obj->orient);
416 obj->id = Gamesave_num_players++;
419 if (obj->type == OBJ_HOSTAGE) {
421 //@@if (obj->id > N_hostage_types)
424 obj->render_type = RT_HOSTAGE;
425 obj->control_type = CT_POWERUP;
430 static int read_int(CFILE *file)
434 if (cfread( &i, sizeof(i), 1, file) != 1)
435 Error( "Error reading int in gamesave.c" );
441 static fix read_fix(CFILE *file)
445 if (cfread( &f, sizeof(f), 1, file) != 1)
446 Error( "Error reading fix in gamesave.c" );
448 f = (fix)INTEL_INT((int)f);
452 static short read_short(CFILE *file)
456 if (cfread( &s, sizeof(s), 1, file) != 1)
457 Error( "Error reading short in gamesave.c" );
463 static short read_fixang(CFILE *file)
467 if (cfread( &f, sizeof(f), 1, file) != 1)
468 Error( "Error reading fixang in gamesave.c" );
470 f = (fixang)INTEL_SHORT((short)f);
474 static byte read_byte(CFILE *file)
478 if (cfread( &b, sizeof(b), 1, file) != 1)
479 Error( "Error reading byte in gamesave.c" );
484 static void read_vector(vms_vector *v,CFILE *file)
486 v->x = read_fix(file);
487 v->y = read_fix(file);
488 v->z = read_fix(file);
491 static void read_matrix(vms_matrix *m,CFILE *file)
493 read_vector(&m->rvec,file);
494 read_vector(&m->uvec,file);
495 read_vector(&m->fvec,file);
498 static void read_angvec(vms_angvec *v,CFILE *file)
500 v->p = read_fixang(file);
501 v->b = read_fixang(file);
502 v->h = read_fixang(file);
505 //static gs_skip(int len,CFILE *file)
508 // cfseek(file,len,SEEK_CUR);
512 static void gs_write_int(int i,FILE *file)
514 if (fwrite( &i, sizeof(i), 1, file) != 1)
515 Error( "Error reading int in gamesave.c" );
519 static void gs_write_fix(fix f,FILE *file)
521 if (fwrite( &f, sizeof(f), 1, file) != 1)
522 Error( "Error reading fix in gamesave.c" );
526 static void gs_write_short(short s,FILE *file)
528 if (fwrite( &s, sizeof(s), 1, file) != 1)
529 Error( "Error reading short in gamesave.c" );
533 static void gs_write_fixang(fixang f,FILE *file)
535 if (fwrite( &f, sizeof(f), 1, file) != 1)
536 Error( "Error reading fixang in gamesave.c" );
540 static void gs_write_byte(byte b,FILE *file)
542 if (fwrite( &b, sizeof(b), 1, file) != 1)
543 Error( "Error reading byte in gamesave.c" );
547 static void gr_write_vector(vms_vector *v,FILE *file)
549 gs_write_fix(v->x,file);
550 gs_write_fix(v->y,file);
551 gs_write_fix(v->z,file);
554 static void gs_write_matrix(vms_matrix *m,FILE *file)
556 gr_write_vector(&m->rvec,file);
557 gr_write_vector(&m->uvec,file);
558 gr_write_vector(&m->fvec,file);
561 static void gs_write_angvec(vms_angvec *v,FILE *file)
563 gs_write_fixang(v->p,file);
564 gs_write_fixang(v->b,file);
565 gs_write_fixang(v->h,file);
571 extern int multi_powerup_is_4pack(int);
572 //reads one object of the given version from the given file
573 void read_object(object *obj,CFILE *f,int version)
576 obj->type = read_byte(f);
577 obj->id = read_byte(f);
579 if (obj->type == OBJ_CNTRLCEN && version<28)
580 obj->id = 0; //used to be only one kind of reactor
582 obj->control_type = read_byte(f);
583 obj->movement_type = read_byte(f);
584 obj->render_type = read_byte(f);
585 obj->flags = read_byte(f);
587 obj->segnum = read_short(f);
588 obj->attached_obj = -1;
590 read_vector(&obj->pos,f);
591 read_matrix(&obj->orient,f);
593 obj->size = read_fix(f);
594 obj->shields = read_fix(f);
596 read_vector(&obj->last_pos,f);
598 obj->contains_type = read_byte(f);
599 obj->contains_id = read_byte(f);
600 obj->contains_count = read_byte(f);
602 switch (obj->movement_type) {
606 read_vector(&obj->mtype.phys_info.velocity,f);
607 read_vector(&obj->mtype.phys_info.thrust,f);
609 obj->mtype.phys_info.mass = read_fix(f);
610 obj->mtype.phys_info.drag = read_fix(f);
611 obj->mtype.phys_info.brakes = read_fix(f);
613 read_vector(&obj->mtype.phys_info.rotvel,f);
614 read_vector(&obj->mtype.phys_info.rotthrust,f);
616 obj->mtype.phys_info.turnroll = read_fixang(f);
617 obj->mtype.phys_info.flags = read_short(f);
623 read_vector(&obj->mtype.spin_rate,f);
633 switch (obj->control_type) {
638 obj->ctype.ai_info.behavior = read_byte(f);
640 for (i=0;i<MAX_AI_FLAGS;i++)
641 obj->ctype.ai_info.flags[i] = read_byte(f);
643 obj->ctype.ai_info.hide_segment = read_short(f);
644 obj->ctype.ai_info.hide_index = read_short(f);
645 obj->ctype.ai_info.path_length = read_short(f);
646 obj->ctype.ai_info.cur_path_index = read_short(f);
649 read_short(f); // obj->ctype.ai_info.follow_path_start_seg =
650 read_short(f); // obj->ctype.ai_info.follow_path_end_seg =
658 obj->ctype.expl_info.spawn_time = read_fix(f);
659 obj->ctype.expl_info.delete_time = read_fix(f);
660 obj->ctype.expl_info.delete_objnum = read_short(f);
661 obj->ctype.expl_info.next_attach = obj->ctype.expl_info.prev_attach = obj->ctype.expl_info.attach_parent = -1;
667 //do I really need to read these? Are they even saved to disk?
669 obj->ctype.laser_info.parent_type = read_short(f);
670 obj->ctype.laser_info.parent_num = read_short(f);
671 obj->ctype.laser_info.parent_signature = read_int(f);
677 obj->ctype.light_info.intensity = read_fix(f);
683 obj->ctype.powerup_info.count = read_int(f);
685 obj->ctype.powerup_info.count = 1;
687 if (obj->id == POW_VULCAN_WEAPON)
688 obj->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT;
690 if (obj->id == POW_GAUSS_WEAPON)
691 obj->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT;
693 if (obj->id == POW_OMEGA_WEAPON)
694 obj->ctype.powerup_info.count = MAX_OMEGA_CHARGE;
704 case CT_SLEW: //the player is generally saved as slew
718 switch (obj->render_type) {
727 obj->rtype.pobj_info.model_num = read_int(f);
729 for (i=0;i<MAX_SUBMODELS;i++)
730 read_angvec(&obj->rtype.pobj_info.anim_angles[i],f);
732 obj->rtype.pobj_info.subobj_flags = read_int(f);
737 obj->rtype.pobj_info.tmap_override = tmo;
740 obj->rtype.pobj_info.tmap_override = -1;
742 int xlated_tmo = tmap_xlate_table[tmo];
743 if (xlated_tmo < 0) {
744 mprintf( (0, "Couldn't find texture for demo object, model_num = %d\n", obj->rtype.pobj_info.model_num));
748 obj->rtype.pobj_info.tmap_override = xlated_tmo;
752 obj->rtype.pobj_info.alt_textures = 0;
757 case RT_WEAPON_VCLIP:
762 obj->rtype.vclip_info.vclip_num = read_int(f);
763 obj->rtype.vclip_info.frametime = read_fix(f);
764 obj->rtype.vclip_info.framenum = read_byte(f);
780 //writes one object to the given file
781 void write_object(object *obj,FILE *f)
783 gs_write_byte(obj->type,f);
784 gs_write_byte(obj->id,f);
786 gs_write_byte(obj->control_type,f);
787 gs_write_byte(obj->movement_type,f);
788 gs_write_byte(obj->render_type,f);
789 gs_write_byte(obj->flags,f);
791 gs_write_short(obj->segnum,f);
793 gr_write_vector(&obj->pos,f);
794 gs_write_matrix(&obj->orient,f);
796 gs_write_fix(obj->size,f);
797 gs_write_fix(obj->shields,f);
799 gr_write_vector(&obj->last_pos,f);
801 gs_write_byte(obj->contains_type,f);
802 gs_write_byte(obj->contains_id,f);
803 gs_write_byte(obj->contains_count,f);
805 switch (obj->movement_type) {
809 gr_write_vector(&obj->mtype.phys_info.velocity,f);
810 gr_write_vector(&obj->mtype.phys_info.thrust,f);
812 gs_write_fix(obj->mtype.phys_info.mass,f);
813 gs_write_fix(obj->mtype.phys_info.drag,f);
814 gs_write_fix(obj->mtype.phys_info.brakes,f);
816 gr_write_vector(&obj->mtype.phys_info.rotvel,f);
817 gr_write_vector(&obj->mtype.phys_info.rotthrust,f);
819 gs_write_fixang(obj->mtype.phys_info.turnroll,f);
820 gs_write_short(obj->mtype.phys_info.flags,f);
826 gr_write_vector(&obj->mtype.spin_rate,f);
836 switch (obj->control_type) {
841 gs_write_byte(obj->ctype.ai_info.behavior,f);
843 for (i=0;i<MAX_AI_FLAGS;i++)
844 gs_write_byte(obj->ctype.ai_info.flags[i],f);
846 gs_write_short(obj->ctype.ai_info.hide_segment,f);
847 gs_write_short(obj->ctype.ai_info.hide_index,f);
848 gs_write_short(obj->ctype.ai_info.path_length,f);
849 gs_write_short(obj->ctype.ai_info.cur_path_index,f);
851 // -- unused! mk, 08/13/95 -- gs_write_short(obj->ctype.ai_info.follow_path_start_seg,f);
852 // -- unused! mk, 08/13/95 -- gs_write_short(obj->ctype.ai_info.follow_path_end_seg,f);
859 gs_write_fix(obj->ctype.expl_info.spawn_time,f);
860 gs_write_fix(obj->ctype.expl_info.delete_time,f);
861 gs_write_short(obj->ctype.expl_info.delete_objnum,f);
867 //do I really need to write these objects?
869 gs_write_short(obj->ctype.laser_info.parent_type,f);
870 gs_write_short(obj->ctype.laser_info.parent_num,f);
871 gs_write_int(obj->ctype.laser_info.parent_signature,f);
877 gs_write_fix(obj->ctype.light_info.intensity,f);
882 gs_write_int(obj->ctype.powerup_info.count,f);
890 case CT_SLEW: //the player is generally saved as slew
894 break; //control center object.
904 switch (obj->render_type) {
913 gs_write_int(obj->rtype.pobj_info.model_num,f);
915 for (i=0;i<MAX_SUBMODELS;i++)
916 gs_write_angvec(&obj->rtype.pobj_info.anim_angles[i],f);
918 gs_write_int(obj->rtype.pobj_info.subobj_flags,f);
920 gs_write_int(obj->rtype.pobj_info.tmap_override,f);
925 case RT_WEAPON_VCLIP:
930 gs_write_int(obj->rtype.vclip_info.vclip_num,f);
931 gs_write_fix(obj->rtype.vclip_info.frametime,f);
932 gs_write_byte(obj->rtype.vclip_info.framenum,f);
948 int robot_flags; // Up to 32 different robots
949 fix hit_points; // How hard it is to destroy this particular matcen
950 fix interval; // Interval between materialogrifizations
951 short segnum; // Segment this is attached to.
952 short fuelcen_num; // Index in fuelcen array.
955 extern int remove_trigger_num(int trigger_num);
957 // -----------------------------------------------------------------------------
959 // Loads all the relevant data for a level.
960 // If level != -1, it loads the filename with extension changed to .min
961 // Otherwise it loads the appropriate level mine.
962 // returns 0=everything ok, 1=old version, -1=error
963 int load_game_data(CFILE *LoadFile)
968 start_offset = cftell(LoadFile);
970 //===================== READ FILE INFO ========================
972 // Set default values
973 game_fileinfo.level = -1;
974 game_fileinfo.player_offset = -1;
975 game_fileinfo.player_sizeof = sizeof(player);
976 game_fileinfo.object_offset = -1;
977 game_fileinfo.object_howmany = 0;
978 game_fileinfo.object_sizeof = sizeof(object);
979 game_fileinfo.walls_offset = -1;
980 game_fileinfo.walls_howmany = 0;
981 game_fileinfo.walls_sizeof = sizeof(wall);
982 game_fileinfo.doors_offset = -1;
983 game_fileinfo.doors_howmany = 0;
984 game_fileinfo.doors_sizeof = sizeof(active_door);
985 game_fileinfo.triggers_offset = -1;
986 game_fileinfo.triggers_howmany = 0;
987 game_fileinfo.triggers_sizeof = sizeof(trigger);
988 game_fileinfo.control_offset = -1;
989 game_fileinfo.control_howmany = 0;
990 game_fileinfo.control_sizeof = sizeof(control_center_triggers);
991 game_fileinfo.matcen_offset = -1;
992 game_fileinfo.matcen_howmany = 0;
993 game_fileinfo.matcen_sizeof = sizeof(matcen_info);
995 game_fileinfo.dl_indices_offset = -1;
996 game_fileinfo.dl_indices_howmany = 0;
997 game_fileinfo.dl_indices_sizeof = sizeof(dl_index);
999 game_fileinfo.delta_light_offset = -1;
1000 game_fileinfo.delta_light_howmany = 0;
1001 game_fileinfo.delta_light_sizeof = sizeof(delta_light);
1003 // Read in game_top_fileinfo to get size of saved fileinfo.
1005 if (cfseek( LoadFile, start_offset, SEEK_SET ))
1006 Error( "Error seeking in gamesave.c" );
1008 // if (cfread( &game_top_fileinfo, sizeof(game_top_fileinfo), 1, LoadFile) != 1)
1009 // Error( "Error reading game_top_fileinfo in gamesave.c" );
1011 game_top_fileinfo.fileinfo_signature = read_short(LoadFile);
1012 game_top_fileinfo.fileinfo_version = read_short(LoadFile);
1013 game_top_fileinfo.fileinfo_sizeof = read_int(LoadFile);
1016 if (game_top_fileinfo.fileinfo_signature != 0x6705)
1019 // Check version number
1020 if (game_top_fileinfo.fileinfo_version < GAME_COMPATIBLE_VERSION )
1023 // Now, Read in the fileinfo
1024 if (cfseek( LoadFile, start_offset, SEEK_SET ))
1025 Error( "Error seeking to game_fileinfo in gamesave.c" );
1027 // if (cfread( &game_fileinfo, game_top_fileinfo.fileinfo_sizeof, 1, LoadFile )!=1)
1028 // Error( "Error reading game_fileinfo in gamesave.c" );
1030 game_fileinfo.fileinfo_signature = read_short(LoadFile);
1031 game_fileinfo.fileinfo_version = read_short(LoadFile);
1032 game_fileinfo.fileinfo_sizeof = read_int(LoadFile);
1034 game_fileinfo.mine_filename[i] = read_byte(LoadFile);
1035 game_fileinfo.level = read_int(LoadFile);
1036 game_fileinfo.player_offset = read_int(LoadFile); // Player info
1037 game_fileinfo.player_sizeof = read_int(LoadFile);
1038 game_fileinfo.object_offset = read_int(LoadFile); // Object info
1039 game_fileinfo.object_howmany = read_int(LoadFile);
1040 game_fileinfo.object_sizeof = read_int(LoadFile);
1041 game_fileinfo.walls_offset = read_int(LoadFile);
1042 game_fileinfo.walls_howmany = read_int(LoadFile);
1043 game_fileinfo.walls_sizeof = read_int(LoadFile);
1044 game_fileinfo.doors_offset = read_int(LoadFile);
1045 game_fileinfo.doors_howmany = read_int(LoadFile);
1046 game_fileinfo.doors_sizeof = read_int(LoadFile);
1047 game_fileinfo.triggers_offset = read_int(LoadFile);
1048 game_fileinfo.triggers_howmany = read_int(LoadFile);
1049 game_fileinfo.triggers_sizeof = read_int(LoadFile);
1050 game_fileinfo.links_offset = read_int(LoadFile);
1051 game_fileinfo.links_howmany = read_int(LoadFile);
1052 game_fileinfo.links_sizeof = read_int(LoadFile);
1053 game_fileinfo.control_offset = read_int(LoadFile);
1054 game_fileinfo.control_howmany = read_int(LoadFile);
1055 game_fileinfo.control_sizeof = read_int(LoadFile);
1056 game_fileinfo.matcen_offset = read_int(LoadFile);
1057 game_fileinfo.matcen_howmany = read_int(LoadFile);
1058 game_fileinfo.matcen_sizeof = read_int(LoadFile);
1060 if (game_top_fileinfo.fileinfo_version >= 29) {
1061 game_fileinfo.dl_indices_offset = read_int(LoadFile);
1062 game_fileinfo.dl_indices_howmany = read_int(LoadFile);
1063 game_fileinfo.dl_indices_sizeof = read_int(LoadFile);
1065 game_fileinfo.delta_light_offset = read_int(LoadFile);
1066 game_fileinfo.delta_light_howmany = read_int(LoadFile);
1067 game_fileinfo.delta_light_sizeof = read_int(LoadFile);
1070 if (game_top_fileinfo.fileinfo_version >= 14) { //load mine filename
1071 //@@char *p=Current_level_name;
1072 //@@//must do read one char at a time, since no cfgets()
1073 //@@do *p = cfgetc(LoadFile); while (*p++!=0);
1075 cfgets(Current_level_name,sizeof(Current_level_name),LoadFile);
1077 if (Current_level_name[strlen(Current_level_name)-1] == '\n')
1078 Current_level_name[strlen(Current_level_name)-1] = 0;
1081 Current_level_name[0]=0;
1083 if (game_top_fileinfo.fileinfo_version >= 19) { //load pof names
1084 // cfread(&N_save_pof_names,2,1,LoadFile);
1085 N_save_pof_names = read_short(LoadFile);
1086 cfread(Save_pof_names,N_save_pof_names,FILENAME_LEN,LoadFile);
1089 //===================== READ PLAYER INFO ==========================
1090 Object_next_signature = 0;
1092 //===================== READ OBJECT INFO ==========================
1094 Gamesave_num_org_robots = 0;
1095 Gamesave_num_players = 0;
1097 if (game_fileinfo.object_offset > -1) {
1098 if (cfseek( LoadFile, game_fileinfo.object_offset, SEEK_SET ))
1099 Error( "Error seeking to object_offset in gamesave.c" );
1101 for (i=0;i<game_fileinfo.object_howmany;i++) {
1103 read_object(&Objects[i],LoadFile,game_top_fileinfo.fileinfo_version);
1105 Objects[i].signature = Object_next_signature++;
1106 verify_object( &Objects[i] );
1111 //===================== READ WALL INFO ============================
1113 if (game_fileinfo.walls_offset > -1)
1116 if (!cfseek( LoadFile, game_fileinfo.walls_offset,SEEK_SET )) {
1117 for (i=0;i<game_fileinfo.walls_howmany;i++) {
1119 if (game_top_fileinfo.fileinfo_version >= 20) {
1121 Assert(sizeof(Walls[i]) == game_fileinfo.walls_sizeof);
1123 // code to correctly read wall structure on mac. I'm assuming only v20 walls
1126 if (cfread(&Walls[i], game_fileinfo.walls_sizeof, 1,LoadFile)!=1)
1127 Error( "Error reading Walls[%d] in gamesave.c", i);
1129 Walls[i].segnum = read_int(LoadFile);
1130 Walls[i].sidenum = read_int(LoadFile);
1131 Walls[i].hps = read_fix(LoadFile);
1132 Walls[i].linked_wall = read_int(LoadFile);
1133 Walls[i].type = read_byte(LoadFile);
1134 Walls[i].flags = read_byte(LoadFile);
1135 Walls[i].state = read_byte(LoadFile);
1136 Walls[i].trigger = read_byte(LoadFile);
1137 Walls[i].clip_num = read_byte(LoadFile);
1138 Walls[i].keys = read_byte(LoadFile);
1139 Walls[i].controlling_trigger = read_byte(LoadFile);
1140 Walls[i].cloak_value = read_byte(LoadFile);
1143 else if (game_top_fileinfo.fileinfo_version >= 17) {
1146 Assert(sizeof(w) == game_fileinfo.walls_sizeof);
1148 if (cfread(&w, game_fileinfo.walls_sizeof, 1,LoadFile)!=1)
1149 Error( "Error reading Walls[%d] in gamesave.c", i);
1151 Walls[i].segnum = w.segnum;
1152 Walls[i].sidenum = w.sidenum;
1153 Walls[i].linked_wall = w.linked_wall;
1155 Walls[i].type = w.type;
1156 Walls[i].flags = w.flags;
1157 Walls[i].hps = w.hps;
1158 Walls[i].trigger = w.trigger;
1159 Walls[i].clip_num = w.clip_num;
1160 Walls[i].keys = w.keys;
1162 Walls[i].state = WALL_DOOR_CLOSED;
1167 Assert(sizeof(w) == game_fileinfo.walls_sizeof);
1169 if (cfread(&w, game_fileinfo.walls_sizeof, 1,LoadFile)!=1)
1170 Error( "Error reading Walls[%d] in gamesave.c", i);
1172 Walls[i].segnum = Walls[i].sidenum = Walls[i].linked_wall = -1;
1174 Walls[i].type = w.type;
1175 Walls[i].flags = w.flags;
1176 Walls[i].hps = w.hps;
1177 Walls[i].trigger = w.trigger;
1178 Walls[i].clip_num = w.clip_num;
1179 Walls[i].keys = w.keys;
1186 //===================== READ DOOR INFO ============================
1188 if (game_fileinfo.doors_offset > -1)
1190 if (!cfseek( LoadFile, game_fileinfo.doors_offset,SEEK_SET )) {
1192 for (i=0;i<game_fileinfo.doors_howmany;i++) {
1194 if (game_top_fileinfo.fileinfo_version >= 20) {
1196 Assert(sizeof(ActiveDoors[i]) == game_fileinfo.doors_sizeof);
1198 // code to read doors for mac -- assume version 20 and greater for doors
1200 if (cfread(&ActiveDoors[i], game_fileinfo.doors_sizeof,1,LoadFile)!=1)
1201 Error( "Error reading ActiveDoors[%d] in gamesave.c", i);
1203 ActiveDoors[i].n_parts = read_int(LoadFile);
1204 ActiveDoors[i].front_wallnum[0] = read_short(LoadFile);
1205 ActiveDoors[i].front_wallnum[1] = read_short(LoadFile);
1206 ActiveDoors[i].back_wallnum[0] = read_short(LoadFile);
1207 ActiveDoors[i].back_wallnum[1] = read_short(LoadFile);
1208 ActiveDoors[i].time = read_fix(LoadFile);
1215 Assert(sizeof(d) == game_fileinfo.doors_sizeof);
1217 if (cfread(&d, game_fileinfo.doors_sizeof, 1,LoadFile)!=1)
1218 Error( "Error reading Doors[%d] in gamesave.c", i);
1220 ActiveDoors[i].n_parts = d.n_parts;
1222 for (p=0;p<d.n_parts;p++) {
1225 cseg = Segments[d.seg[p]].children[d.side[p]];
1226 cside = find_connect_side(&Segments[d.seg[p]],&Segments[cseg]);
1228 ActiveDoors[i].front_wallnum[p] = Segments[d.seg[p]].sides[d.side[p]].wall_num;
1229 ActiveDoors[i].back_wallnum[p] = Segments[cseg].sides[cside].wall_num;
1237 //==================== READ TRIGGER INFO ==========================
1240 // for MACINTOSH -- assume all triggers >= verion 31 triggers.
1242 if (game_fileinfo.triggers_offset > -1)
1244 if (!cfseek( LoadFile, game_fileinfo.triggers_offset,SEEK_SET )) {
1245 for (i=0;i<game_fileinfo.triggers_howmany;i++)
1246 if (game_top_fileinfo.fileinfo_version < 31) {
1252 if (game_top_fileinfo.fileinfo_version < 30) {
1256 if (cfread(&trig29, game_fileinfo.triggers_sizeof,1,LoadFile)!=1)
1257 Error( "Error reading Triggers[%d] in gamesave.c", i);
1259 trig.flags = trig29.flags;
1260 trig.num_links = trig29.num_links;
1261 trig.num_links = trig29.num_links;
1262 trig.value = trig29.value;
1263 trig.time = trig29.time;
1265 for (t=0;t<trig.num_links;t++) {
1266 trig.seg[t] = trig29.seg[t];
1267 trig.side[t] = trig29.side[t];
1271 if (cfread(&trig, game_fileinfo.triggers_sizeof,1,LoadFile)!=1)
1272 Error( "Error reading Triggers[%d] in gamesave.c", i);
1274 //Assert(trig.flags & TRIGGER_ON);
1275 trig.flags &= ~TRIGGER_ON;
1277 if (trig.flags & TRIGGER_CONTROL_DOORS)
1278 type = TT_OPEN_DOOR;
1279 else if (trig.flags & TRIGGER_SHIELD_DAMAGE)
1281 else if (trig.flags & TRIGGER_ENERGY_DRAIN)
1283 else if (trig.flags & TRIGGER_EXIT)
1285 else if (trig.flags & TRIGGER_ONE_SHOT)
1287 else if (trig.flags & TRIGGER_MATCEN)
1289 else if (trig.flags & TRIGGER_ILLUSION_OFF)
1290 type = TT_ILLUSION_OFF;
1291 else if (trig.flags & TRIGGER_SECRET_EXIT)
1292 type = TT_SECRET_EXIT;
1293 else if (trig.flags & TRIGGER_ILLUSION_ON)
1294 type = TT_ILLUSION_ON;
1295 else if (trig.flags & TRIGGER_UNLOCK_DOORS)
1296 type = TT_UNLOCK_DOOR;
1297 else if (trig.flags & TRIGGER_OPEN_WALL)
1298 type = TT_OPEN_WALL;
1299 else if (trig.flags & TRIGGER_CLOSE_WALL)
1300 type = TT_CLOSE_WALL;
1301 else if (trig.flags & TRIGGER_ILLUSORY_WALL)
1302 type = TT_ILLUSORY_WALL;
1306 Triggers[i].type = type;
1307 Triggers[i].flags = 0;
1308 Triggers[i].num_links = trig.num_links;
1309 Triggers[i].num_links = trig.num_links;
1310 Triggers[i].value = trig.value;
1311 Triggers[i].time = trig.time;
1313 for (t=0;t<trig.num_links;t++) {
1314 Triggers[i].seg[t] = trig.seg[t];
1315 Triggers[i].side[t] = trig.side[t];
1320 if (cfread(&Triggers[i], game_fileinfo.triggers_sizeof,1,LoadFile)!=1)
1321 Error( "Error reading Triggers[%d] in gamesave.c", i);
1323 Triggers[i].type = read_byte(LoadFile);
1324 Triggers[i].flags = read_byte(LoadFile);
1325 Triggers[i].num_links = read_byte(LoadFile);
1326 Triggers[i].pad = read_byte(LoadFile);
1327 Triggers[i].value = read_fix(LoadFile);
1328 Triggers[i].time = read_fix(LoadFile);
1329 for (j=0; j<MAX_WALLS_PER_LINK; j++ )
1330 Triggers[i].seg[j] = read_short(LoadFile);
1331 for (j=0; j<MAX_WALLS_PER_LINK; j++ )
1332 Triggers[i].side[j] = read_short(LoadFile);
1338 //================ READ CONTROL CENTER TRIGGER INFO ===============
1340 if (game_fileinfo.control_offset > -1)
1342 if (!cfseek( LoadFile, game_fileinfo.control_offset,SEEK_SET )) {
1343 for (i=0;i<game_fileinfo.control_howmany;i++)
1345 if (cfread(&ControlCenterTriggers, game_fileinfo.control_sizeof,1,LoadFile)!=1)
1346 Error( "Error reading ControlCenterTriggers in gamesave.c");
1348 ControlCenterTriggers.num_links = read_short(LoadFile);
1349 for (j=0; j<MAX_CONTROLCEN_LINKS; j++ )
1350 ControlCenterTriggers.seg[j] = read_short( LoadFile );
1351 for (j=0; j<MAX_CONTROLCEN_LINKS; j++ )
1352 ControlCenterTriggers.side[j] = read_short( LoadFile );
1358 //================ READ MATERIALOGRIFIZATIONATORS INFO ===============
1360 if (game_fileinfo.matcen_offset > -1)
1363 if (!cfseek( LoadFile, game_fileinfo.matcen_offset,SEEK_SET )) {
1364 // mprintf((0, "Reading %i materialization centers.\n", game_fileinfo.matcen_howmany));
1365 for (i=0;i<game_fileinfo.matcen_howmany;i++) {
1366 if (game_top_fileinfo.fileinfo_version < 27) {
1368 Assert(game_fileinfo.matcen_sizeof == sizeof(m));
1369 if (cfread(&m, game_fileinfo.matcen_sizeof,1,LoadFile)!=1)
1370 Error( "Error reading RobotCenters in gamesave.c");
1371 RobotCenters[i].robot_flags[0] = m.robot_flags;
1372 RobotCenters[i].robot_flags[1] = 0;
1373 RobotCenters[i].hit_points = m.hit_points;
1374 RobotCenters[i].interval = m.interval;
1375 RobotCenters[i].segnum = m.segnum;
1376 RobotCenters[i].fuelcen_num = m.fuelcen_num;
1379 Assert(game_fileinfo.matcen_sizeof == sizeof(RobotCenters[i]));
1381 if (cfread(&RobotCenters[i], game_fileinfo.matcen_sizeof,1,LoadFile)!=1)
1382 Error( "Error reading RobotCenters in gamesave.c");
1384 RobotCenters[i].robot_flags[0] = read_int(LoadFile);
1385 RobotCenters[i].robot_flags[1] = read_int(LoadFile);
1386 RobotCenters[i].hit_points = read_fix(LoadFile);
1387 RobotCenters[i].interval = read_fix(LoadFile);
1388 RobotCenters[i].segnum = read_short(LoadFile);
1389 RobotCenters[i].fuelcen_num = read_short(LoadFile);
1393 // Set links in RobotCenters to Station array
1395 for (j=0; j<=Highest_segment_index; j++)
1396 if (Segment2s[j].special == SEGMENT_IS_ROBOTMAKER)
1397 if (Segment2s[j].matcen_num == i)
1398 RobotCenters[i].fuelcen_num = Segment2s[j].value;
1400 // mprintf((0, " %i: flags = %08x\n", i, RobotCenters[i].robot_flags));
1406 //================ READ DL_INDICES INFO ===============
1408 Num_static_lights = 0;
1410 if (game_fileinfo.dl_indices_offset > -1) {
1413 if (!cfseek( LoadFile, game_fileinfo.dl_indices_offset, SEEK_SET )) {
1414 Num_static_lights = game_fileinfo.dl_indices_howmany;
1415 for (i=0; i<game_fileinfo.dl_indices_howmany; i++) {
1416 if (game_top_fileinfo.fileinfo_version < 29) {
1417 mprintf((0, "Warning: Old mine version. Not reading Dl_indices info.\n"));
1418 Int3(); //shouldn't be here!!!
1421 if (cfread(&Dl_indices[i], game_fileinfo.dl_indices_sizeof, 1, LoadFile) != 1)
1422 Error( "Error reading Dl_indices in gamesave.c");
1424 Dl_indices[i].segnum = read_short(LoadFile);
1425 Dl_indices[i].sidenum = read_byte(LoadFile);
1426 Dl_indices[i].count = read_byte(LoadFile);
1427 Dl_indices[i].index = read_short(LoadFile);
1435 // Indicate that no light has been subtracted from any vertices.
1436 clear_light_subtracted();
1438 //================ READ DELTA LIGHT INFO ===============
1440 if (game_fileinfo.delta_light_offset > -1) {
1443 if (!cfseek( LoadFile, game_fileinfo.delta_light_offset, SEEK_SET )) {
1444 for (i=0; i<game_fileinfo.delta_light_howmany; i++) {
1445 if (game_top_fileinfo.fileinfo_version < 29) {
1446 mprintf((0, "Warning: Old mine version. Not reading delta light info.\n"));
1449 if (cfread(&Delta_lights[i], game_fileinfo.delta_light_sizeof, 1, LoadFile) != 1)
1450 Error( "Error reading Delta Lights in gamesave.c");
1452 Delta_lights[i].segnum = read_short(LoadFile);
1453 Delta_lights[i].sidenum = read_byte(LoadFile);
1454 Delta_lights[i].dummy = read_byte(LoadFile);
1455 Delta_lights[i].vert_light[0] = read_byte(LoadFile);
1456 Delta_lights[i].vert_light[1] = read_byte(LoadFile);
1457 Delta_lights[i].vert_light[2] = read_byte(LoadFile);
1458 Delta_lights[i].vert_light[3] = read_byte(LoadFile);
1466 //========================= UPDATE VARIABLES ======================
1468 reset_objects(game_fileinfo.object_howmany);
1470 for (i=0; i<MAX_OBJECTS; i++) {
1471 Objects[i].next = Objects[i].prev = -1;
1472 if (Objects[i].type != OBJ_NONE) {
1473 int objsegnum = Objects[i].segnum;
1475 if (objsegnum > Highest_segment_index) //bogus object
1476 Objects[i].type = OBJ_NONE;
1478 Objects[i].segnum = -1; //avoid Assert()
1479 obj_link(i,objsegnum);
1484 clear_transient_objects(1); //1 means clear proximity bombs
1486 // Make sure non-transparent doors are set correctly.
1487 for (i=0; i< Num_segments; i++)
1488 for (j=0;j<MAX_SIDES_PER_SEGMENT;j++) {
1489 side *sidep = &Segments[i].sides[j];
1490 if ((sidep->wall_num != -1) && (Walls[sidep->wall_num].clip_num != -1)) {
1491 //mprintf((0, "Checking Wall %d\n", Segments[i].sides[j].wall_num));
1492 if (WallAnims[Walls[sidep->wall_num].clip_num].flags & WCF_TMAP1) {
1493 //mprintf((0, "Fixing non-transparent door.\n"));
1494 sidep->tmap_num = WallAnims[Walls[sidep->wall_num].clip_num].frames[0];
1495 sidep->tmap_num2 = 0;
1501 Num_walls = game_fileinfo.walls_howmany;
1504 Num_open_doors = game_fileinfo.doors_howmany;
1505 Num_triggers = game_fileinfo.triggers_howmany;
1507 //go through all walls, killing references to invalid triggers
1508 for (i=0;i<Num_walls;i++)
1509 if (Walls[i].trigger >= Num_triggers) {
1510 mprintf((0,"Removing reference to invalid trigger %d from wall %d\n",Walls[i].trigger,i));
1511 Walls[i].trigger = -1; //kill trigger
1514 //go through all triggers, killing unused ones
1515 for (i=0;i<Num_triggers;) {
1518 // Find which wall this trigger is connected to.
1519 for (w=0; w<Num_walls; w++)
1520 if (Walls[w].trigger == i)
1524 if (w == Num_walls) {
1525 mprintf((0,"Removing unreferenced trigger %d\n",i));
1526 remove_trigger_num(i);
1533 // MK, 10/17/95: Make walls point back at the triggers that control them.
1534 // Go through all triggers, stuffing controlling_trigger field in Walls.
1537 for (i=0; i<Num_walls; i++)
1538 Walls[i].controlling_trigger = -1;
1540 for (t=0; t<Num_triggers; t++) {
1542 for (l=0; l<Triggers[t].num_links; l++) {
1543 int seg_num, side_num, wall_num;
1545 seg_num = Triggers[t].seg[l];
1546 side_num = Triggers[t].side[l];
1547 wall_num = Segments[seg_num].sides[side_num].wall_num;
1549 // -- if (Walls[wall_num].controlling_trigger != -1)
1552 //check to see that if a trigger requires a wall that it has one,
1553 //and if it requires a matcen that it has one
1555 if (Triggers[t].type == TT_MATCEN) {
1556 if (Segment2s[seg_num].special != SEGMENT_IS_ROBOTMAKER)
1557 Int3(); //matcen trigger doesn't point to matcen
1559 else if (Triggers[t].type != TT_LIGHT_OFF && Triggers[t].type != TT_LIGHT_ON) { //light triggers don't require walls
1561 Int3(); // This is illegal. This trigger requires a wall
1563 Walls[wall_num].controlling_trigger = t;
1569 Num_robot_centers = game_fileinfo.matcen_howmany;
1571 //fix old wall structs
1572 if (game_top_fileinfo.fileinfo_version < 17) {
1573 int segnum,sidenum,wallnum;
1575 for (segnum=0; segnum<=Highest_segment_index; segnum++)
1576 for (sidenum=0;sidenum<6;sidenum++)
1577 if ((wallnum=Segments[segnum].sides[sidenum].wall_num) != -1) {
1578 Walls[wallnum].segnum = segnum;
1579 Walls[wallnum].sidenum = sidenum;
1586 for (sidenum=0; sidenum<6; sidenum++) {
1587 int wallnum = Segments[Highest_segment_index].sides[sidenum].wall_num;
1589 if ((Walls[wallnum].segnum != Highest_segment_index) || (Walls[wallnum].sidenum != sidenum))
1590 Int3(); // Error. Bogus walls in this segment.
1591 // Consult Yuan or Mike.
1596 //create_local_segment_data();
1604 if (game_top_fileinfo.fileinfo_version < GAME_VERSION && !(game_top_fileinfo.fileinfo_version==25 && GAME_VERSION==26))
1605 return 1; //means old version
1611 int check_segment_connections(void);
1613 extern void set_ambient_sound_flags(void);
1615 // -----------------------------------------------------------------------------
1616 //loads from an already-open file
1617 // returns 0=everything ok, 1=old version, -1=error
1618 int load_mine_data(CFILE *LoadFile);
1619 int load_mine_data_compiled(CFILE *LoadFile);
1621 #define LEVEL_FILE_VERSION 8
1622 //1 -> 2 add palette name
1623 //2 -> 3 add control center explosion time
1624 //3 -> 4 add reactor strength
1625 //4 -> 5 killed hostage text stuff
1626 //5 -> 6 added Secret_return_segment and Secret_return_orient
1627 //6 -> 7 added flickering lights
1628 //7 -> 8 made version 8 to be not compatible with D2 1.0 & 1.1
1631 char *Level_being_loaded=NULL;
1635 extern void ncache_flush();
1638 extern int HoardEquipped();
1640 extern int Slide_segs_computed;
1642 int no_old_level_file_error=0;
1644 //loads a level (.LVL) file from disk
1645 //returns 0 if success, else error code
1646 int load_level(char * filename_passed)
1649 int use_compiled_level=1;
1653 int version,minedata_offset,gamedata_offset;
1654 int mine_err,game_err;
1660 Slide_segs_computed = 0;
1663 if (Game_mode & GM_NETWORK)
1665 for (i=0;i<MAX_POWERUP_TYPES;i++)
1667 MaxPowerupsAllowed[i]=0;
1668 PowerupsInMine[i]=0;
1678 Level_being_loaded = filename_passed;
1681 strcpy(filename,filename_passed);
1685 //if we have the editor, try the LVL first, no matter what was passed.
1686 //if we don't have an LVL, try RDL
1687 //if we don't have the editor, we just use what was passed
1689 change_filename_extension(filename,filename_passed,".LVL");
1690 use_compiled_level = 0;
1692 if (!cfexist(filename)) {
1693 change_filename_extension(filename,filename,".RL2");
1694 use_compiled_level = 1;
1698 LoadFile = cfopen( filename, "rb" );
1702 mprintf((0,"Can't open level file <%s>\n", filename));
1705 Error("Can't open file <%s>\n",filename);
1709 strcpy( Gamesave_current_filename, filename );
1712 // if ( Newdemo_state == ND_STATE_RECORDING )
1713 // newdemo_record_start_demo();
1716 cfread(sig, 1, 4, LoadFile);
1717 version = read_int(LoadFile);
1718 minedata_offset = read_int(LoadFile);
1719 gamedata_offset = read_int(LoadFile);
1721 Assert((sig[0] == 'L') && (sig[1] == 'V') && (sig[2]=='L') && (sig[3] == 'P'));
1723 if (version >= 8) { //read dummy data
1725 if (HoardEquipped())
1728 read_short(LoadFile);
1729 read_byte(LoadFile);
1733 // NOTE LINK TO ABOVE!
1734 Error("This level requires the Vertigo Enhanced version of D2.");
1739 read_int(LoadFile); //was hostagetext_offset
1742 cfgets(Current_level_palette,sizeof(Current_level_palette),LoadFile);
1743 if (Current_level_palette[strlen(Current_level_palette)-1] == '\n')
1744 Current_level_palette[strlen(Current_level_palette)-1] = 0;
1748 Base_control_center_explosion_time = read_int(LoadFile);
1750 Base_control_center_explosion_time = DEFAULT_CONTROL_CENTER_EXPLOSION_TIME;
1753 Reactor_strength = read_int(LoadFile);
1755 Reactor_strength = -1; //use old defaults
1758 Num_flickering_lights = read_int(LoadFile);
1760 Assert((Num_flickering_lights >= 0) && (Num_flickering_lights < MAX_FLICKERING_LIGHTS));
1761 for (i = 0; i < Num_flickering_lights; i++)
1763 Flickering_lights[i].segnum = read_short(LoadFile);
1764 Flickering_lights[i].sidenum = read_short(LoadFile);
1765 Flickering_lights[i].mask = read_int(LoadFile);
1766 Flickering_lights[i].timer = read_fix(LoadFile);
1767 Flickering_lights[i].delay = read_fix(LoadFile);
1770 cfread(Flickering_lights,sizeof(*Flickering_lights),Num_flickering_lights,LoadFile);
1774 Num_flickering_lights = 0;
1776 if (version <= 1 || Current_level_palette[0]==0)
1777 strcpy(Current_level_palette,"groupa.256");
1780 Secret_return_segment = 0;
1781 Secret_return_orient.rvec.x = F1_0; Secret_return_orient.rvec.y = 0; Secret_return_orient.rvec.z = 0;
1782 Secret_return_orient.fvec.x = 0; Secret_return_orient.fvec.y = F1_0; Secret_return_orient.fvec.z = 0;
1783 Secret_return_orient.uvec.x = 0; Secret_return_orient.uvec.y = 0; Secret_return_orient.uvec.z = F1_0;
1785 Secret_return_segment = read_int(LoadFile);
1786 Secret_return_orient.rvec.x = read_int(LoadFile);
1787 Secret_return_orient.rvec.y = read_int(LoadFile);
1788 Secret_return_orient.rvec.z = read_int(LoadFile);
1789 Secret_return_orient.fvec.x = read_int(LoadFile);
1790 Secret_return_orient.fvec.y = read_int(LoadFile);
1791 Secret_return_orient.fvec.z = read_int(LoadFile);
1792 Secret_return_orient.uvec.x = read_int(LoadFile);
1793 Secret_return_orient.uvec.y = read_int(LoadFile);
1794 Secret_return_orient.uvec.z = read_int(LoadFile);
1797 cfseek(LoadFile,minedata_offset,SEEK_SET);
1799 if (!use_compiled_level) {
1800 mine_err = load_mine_data(LoadFile);
1801 #if 0 //dunno - 3rd party stuff?
1802 // Compress all uv coordinates in mine, improves texmap precision. --MK, 02/19/96
1803 compress_uv_coordinates_all();
1807 //NOTE LINK TO ABOVE!!
1808 mine_err = load_mine_data_compiled(LoadFile);
1810 if (mine_err == -1) { //error!!
1815 cfseek(LoadFile,gamedata_offset,SEEK_SET);
1816 game_err = load_game_data(LoadFile);
1818 if (game_err == -1) { //error!!
1823 //======================== CLOSE FILE =============================
1825 cfclose( LoadFile );
1827 set_ambient_sound_flags();
1830 write_game_text_file(filename);
1831 if (Errors_in_mine) {
1832 if (is_real_level(filename)) {
1833 char ErrorMessage[200];
1835 sprintf( ErrorMessage, "Warning: %i errors in %s!\n", Errors_in_mine, Level_being_loaded );
1837 gr_palette_load(gr_palette);
1838 nm_messagebox( NULL, 1, "Continue", ErrorMessage );
1841 mprintf((1, "Error: %i errors in %s.\n", Errors_in_mine, Level_being_loaded));
1846 //If an old version, ask the use if he wants to save as new version
1847 if (!no_old_level_file_error && (Function_mode == FMODE_EDITOR) && (((LEVEL_FILE_VERSION>3) && version<LEVEL_FILE_VERSION) || mine_err==1 || game_err==1)) {
1848 char ErrorMessage[200];
1850 sprintf( ErrorMessage,
1851 "You just loaded a old version\n"
1852 "level. Would you like to save\n"
1853 "it as a current version level?");
1856 gr_palette_load(gr_palette);
1857 if (nm_messagebox( NULL, 2, "Don't Save", "Save", ErrorMessage )==1)
1858 save_level(filename);
1864 if (Function_mode == FMODE_EDITOR)
1865 editor_status("Loaded NEW mine %s, \"%s\"",filename,Current_level_name);
1869 if (check_segment_connections())
1870 nm_messagebox( "ERROR", 1, "Ok",
1871 "Connectivity errors detected in\n"
1872 "mine. See monochrome screen for\n"
1873 "details, and contact Matt or Mike." );
1880 void get_level_name()
1882 //NO_UI!!! UI_WINDOW *NameWindow = NULL;
1883 //NO_UI!!! UI_GADGET_INPUTBOX *NameText;
1884 //NO_UI!!! UI_GADGET_BUTTON *QuitButton;
1886 //NO_UI!!! // Open a window with a quit button
1887 //NO_UI!!! NameWindow = ui_open_window( 20, 20, 300, 110, WIN_DIALOG );
1888 //NO_UI!!! QuitButton = ui_add_gadget_button( NameWindow, 150-24, 60, 48, 40, "Done", NULL );
1890 //NO_UI!!! ui_wprintf_at( NameWindow, 10, 12,"Please enter a name for this mine:" );
1891 //NO_UI!!! NameText = ui_add_gadget_inputbox( NameWindow, 10, 30, LEVEL_NAME_LEN, LEVEL_NAME_LEN, Current_level_name );
1893 //NO_UI!!! NameWindow->keyboard_focus_gadget = (UI_GADGET *)NameText;
1894 //NO_UI!!! QuitButton->hotkey = KEY_ENTER;
1896 //NO_UI!!! ui_gadget_calc_keys(NameWindow);
1898 //NO_UI!!! while (!QuitButton->pressed && last_keypress!=KEY_ENTER) {
1899 //NO_UI!!! ui_mega_process();
1900 //NO_UI!!! ui_window_do_gadgets(NameWindow);
1903 //NO_UI!!! strcpy( Current_level_name, NameText->text );
1905 //NO_UI!!! if ( NameWindow!=NULL ) {
1906 //NO_UI!!! ui_close_window( NameWindow );
1907 //NO_UI!!! NameWindow = NULL;
1913 m[0].type = NM_TYPE_TEXT; m[0].text = "Please enter a name for this mine:";
1914 m[1].type = NM_TYPE_INPUT; m[1].text = Current_level_name; m[1].text_len = LEVEL_NAME_LEN;
1916 newmenu_do( NULL, "Enter mine name", 2, m, NULL );
1926 // -----------------------------------------------------------------------------
1927 int compute_num_delta_light_records(void)
1932 for (i=0; i<Num_static_lights; i++) {
1933 total += Dl_indices[i].count;
1940 // -----------------------------------------------------------------------------
1942 int save_game_data(FILE * SaveFile)
1944 int player_offset, object_offset, walls_offset, doors_offset, triggers_offset, control_offset, matcen_offset; //, links_offset;
1945 int dl_indices_offset, delta_light_offset;
1946 int start_offset,end_offset;
1948 start_offset = ftell(SaveFile);
1950 //===================== SAVE FILE INFO ========================
1952 game_fileinfo.fileinfo_signature = 0x6705;
1953 game_fileinfo.fileinfo_version = GAME_VERSION;
1954 game_fileinfo.level = Current_level_num;
1955 game_fileinfo.fileinfo_sizeof = sizeof(game_fileinfo);
1956 game_fileinfo.player_offset = -1;
1957 game_fileinfo.player_sizeof = sizeof(player);
1958 game_fileinfo.object_offset = -1;
1959 game_fileinfo.object_howmany = Highest_object_index+1;
1960 game_fileinfo.object_sizeof = sizeof(object);
1961 game_fileinfo.walls_offset = -1;
1962 game_fileinfo.walls_howmany = Num_walls;
1963 game_fileinfo.walls_sizeof = sizeof(wall);
1964 game_fileinfo.doors_offset = -1;
1965 game_fileinfo.doors_howmany = Num_open_doors;
1966 game_fileinfo.doors_sizeof = sizeof(active_door);
1967 game_fileinfo.triggers_offset = -1;
1968 game_fileinfo.triggers_howmany = Num_triggers;
1969 game_fileinfo.triggers_sizeof = sizeof(trigger);
1970 game_fileinfo.control_offset = -1;
1971 game_fileinfo.control_howmany = 1;
1972 game_fileinfo.control_sizeof = sizeof(control_center_triggers);
1973 game_fileinfo.matcen_offset = -1;
1974 game_fileinfo.matcen_howmany = Num_robot_centers;
1975 game_fileinfo.matcen_sizeof = sizeof(matcen_info);
1977 game_fileinfo.dl_indices_offset = -1;
1978 game_fileinfo.dl_indices_howmany = Num_static_lights;
1979 game_fileinfo.dl_indices_sizeof = sizeof(dl_index);
1981 game_fileinfo.delta_light_offset = -1;
1982 game_fileinfo.delta_light_howmany = compute_num_delta_light_records();
1983 game_fileinfo.delta_light_sizeof = sizeof(delta_light);
1985 // Write the fileinfo
1986 fwrite( &game_fileinfo, sizeof(game_fileinfo), 1, SaveFile );
1988 // Write the mine name
1989 fprintf(SaveFile,"%s\n",Current_level_name);
1991 fwrite(&N_polygon_models,2,1,SaveFile);
1992 fwrite(Pof_names,N_polygon_models,sizeof(*Pof_names),SaveFile);
1994 //==================== SAVE PLAYER INFO ===========================
1996 player_offset = ftell(SaveFile);
1997 fwrite( &Players[Player_num], sizeof(player), 1, SaveFile );
1999 //==================== SAVE OBJECT INFO ===========================
2001 object_offset = ftell(SaveFile);
2002 //fwrite( &Objects, sizeof(object), game_fileinfo.object_howmany, SaveFile );
2005 for (i=0;i<game_fileinfo.object_howmany;i++)
2006 write_object(&Objects[i],SaveFile);
2009 //==================== SAVE WALL INFO =============================
2011 walls_offset = ftell(SaveFile);
2012 fwrite( Walls, sizeof(wall), game_fileinfo.walls_howmany, SaveFile );
2014 //==================== SAVE DOOR INFO =============================
2016 doors_offset = ftell(SaveFile);
2017 fwrite( ActiveDoors, sizeof(active_door), game_fileinfo.doors_howmany, SaveFile );
2019 //==================== SAVE TRIGGER INFO =============================
2021 triggers_offset = ftell(SaveFile);
2022 fwrite( Triggers, sizeof(trigger), game_fileinfo.triggers_howmany, SaveFile );
2024 //================ SAVE CONTROL CENTER TRIGGER INFO ===============
2026 control_offset = ftell(SaveFile);
2027 fwrite( &ControlCenterTriggers, sizeof(control_center_triggers), 1, SaveFile );
2030 //================ SAVE MATERIALIZATION CENTER TRIGGER INFO ===============
2032 matcen_offset = ftell(SaveFile);
2033 // mprintf((0, "Writing %i materialization centers\n", game_fileinfo.matcen_howmany));
2035 // for (i=0; i<game_fileinfo.matcen_howmany; i++)
2036 // mprintf((0, " %i: robot_flags = %08x\n", i, RobotCenters[i].robot_flags));
2038 fwrite( RobotCenters, sizeof(matcen_info), game_fileinfo.matcen_howmany, SaveFile );
2040 //================ SAVE DELTA LIGHT INFO ===============
2041 dl_indices_offset = ftell(SaveFile);
2042 fwrite( Dl_indices, sizeof(dl_index), game_fileinfo.dl_indices_howmany, SaveFile );
2044 delta_light_offset = ftell(SaveFile);
2045 fwrite( Delta_lights, sizeof(delta_light), game_fileinfo.delta_light_howmany, SaveFile );
2047 //============= REWRITE FILE INFO, TO SAVE OFFSETS ===============
2049 // Update the offset fields
2050 game_fileinfo.player_offset = player_offset;
2051 game_fileinfo.object_offset = object_offset;
2052 game_fileinfo.walls_offset = walls_offset;
2053 game_fileinfo.doors_offset = doors_offset;
2054 game_fileinfo.triggers_offset = triggers_offset;
2055 game_fileinfo.control_offset = control_offset;
2056 game_fileinfo.matcen_offset = matcen_offset;
2057 game_fileinfo.dl_indices_offset = dl_indices_offset;
2058 game_fileinfo.delta_light_offset = delta_light_offset;
2061 end_offset = ftell(SaveFile);
2063 // Write the fileinfo
2064 fseek( SaveFile, start_offset, SEEK_SET ); // Move to TOF
2065 fwrite( &game_fileinfo, sizeof(game_fileinfo), 1, SaveFile );
2067 // Go back to end of data
2068 fseek(SaveFile,end_offset,SEEK_SET);
2073 int save_mine_data(FILE * SaveFile);
2075 // -----------------------------------------------------------------------------
2077 int save_level_sub(char * filename, int compiled_version)
2080 char temp_filename[128];
2081 u_int32_t sig = 0x504c564c; /* 'PLVL' */
2082 int version=LEVEL_FILE_VERSION;
2083 int minedata_offset=0,gamedata_offset=0;
2085 if ( !compiled_version ) {
2086 write_game_text_file(filename);
2088 if (Errors_in_mine) {
2089 if (is_real_level(filename)) {
2090 char ErrorMessage[200];
2092 sprintf( ErrorMessage, "Warning: %i errors in this mine!\n", Errors_in_mine );
2094 gr_palette_load(gr_palette);
2096 if (nm_messagebox( NULL, 2, "Cancel Save", "Save", ErrorMessage )!=1) {
2102 mprintf((1, "Error: %i errors in this mine. See the 'txm' file.\n", Errors_in_mine));
2104 change_filename_extension(temp_filename,filename,".LVL");
2108 // macs are using the regular hog/rl2 files for shareware
2109 #if defined(SHAREWARE) && !defined(MACINTOSH)
2110 change_filename_extension(temp_filename,filename,".SL2");
2112 change_filename_extension(temp_filename,filename,".RL2");
2116 SaveFile = fopen( temp_filename, "wb" );
2119 char ErrorMessage[256];
2122 _splitpath( temp_filename, NULL, NULL, fname, NULL );
2124 sprintf( ErrorMessage, \
2125 "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"
2126 , temp_filename, fname );
2128 gr_palette_load(gr_palette);
2129 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
2134 if (Current_level_name[0] == 0)
2135 strcpy(Current_level_name,"Untitled");
2137 clear_transient_objects(1); //1 means clear proximity bombs
2139 compress_objects(); //after this, Highest_object_index == num objects
2141 //make sure player is in a segment
2142 if (update_object_seg(&Objects[Players[0].objnum]) == 0) {
2143 if (ConsoleObject->segnum > Highest_segment_index)
2144 ConsoleObject->segnum = 0;
2145 compute_segment_center(&ConsoleObject->pos,&(Segments[ConsoleObject->segnum]));
2152 gs_write_int(sig,SaveFile);
2153 gs_write_int(version,SaveFile);
2156 gs_write_int(minedata_offset,SaveFile);
2157 gs_write_int(gamedata_offset,SaveFile);
2159 //Now write the damn data
2161 //write the version 8 data (to make file unreadable by 1.0 & 1.1)
2162 gs_write_int(GameTime,SaveFile);
2163 gs_write_short(FrameCount,SaveFile);
2164 gs_write_byte(FrameTime,SaveFile);
2166 // Write the palette file name
2167 fprintf(SaveFile,"%s\n",Current_level_palette);
2169 gs_write_int(Base_control_center_explosion_time,SaveFile);
2170 gs_write_int(Reactor_strength,SaveFile);
2172 gs_write_int(Num_flickering_lights,SaveFile);
2173 fwrite(Flickering_lights,sizeof(*Flickering_lights),Num_flickering_lights,SaveFile);
2175 gs_write_int(Secret_return_segment, SaveFile);
2176 gs_write_int(Secret_return_orient.rvec.x, SaveFile);
2177 gs_write_int(Secret_return_orient.rvec.y, SaveFile);
2178 gs_write_int(Secret_return_orient.rvec.z, SaveFile);
2179 gs_write_int(Secret_return_orient.fvec.x, SaveFile);
2180 gs_write_int(Secret_return_orient.fvec.y, SaveFile);
2181 gs_write_int(Secret_return_orient.fvec.z, SaveFile);
2182 gs_write_int(Secret_return_orient.uvec.x, SaveFile);
2183 gs_write_int(Secret_return_orient.uvec.y, SaveFile);
2184 gs_write_int(Secret_return_orient.uvec.z, SaveFile);
2186 minedata_offset = ftell(SaveFile);
2187 if ( !compiled_version )
2188 save_mine_data(SaveFile);
2190 save_mine_data_compiled(SaveFile);
2191 gamedata_offset = ftell(SaveFile);
2192 save_game_data(SaveFile);
2194 fseek(SaveFile,sizeof(sig)+sizeof(version),SEEK_SET);
2195 gs_write_int(minedata_offset,SaveFile);
2196 gs_write_int(gamedata_offset,SaveFile);
2198 //==================== CLOSE THE FILE =============================
2201 if ( !compiled_version ) {
2202 if (Function_mode == FMODE_EDITOR)
2203 editor_status("Saved mine %s, \"%s\"",filename,Current_level_name);
2210 #if 0 //dunno - 3rd party stuff?
2211 extern void compress_uv_coordinates_all(void);
2214 int save_level(char * filename)
2218 // Save normal version...
2219 r1 = save_level_sub(filename, 0);
2221 // Save compiled version...
2222 save_level_sub(filename, 1);
2230 void dump_mine_info(void)
2232 int segnum, sidenum;
2233 fix min_u, max_u, min_v, max_v, min_l, max_l, max_sl;
2245 for (segnum=0; segnum<=Highest_segment_index; segnum++) {
2246 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
2248 side *sidep = &Segments[segnum].sides[sidenum];
2250 if (Segment2s[segnum].static_light > max_sl)
2251 max_sl = Segment2s[segnum].static_light;
2253 for (vertnum=0; vertnum<4; vertnum++) {
2254 if (sidep->uvls[vertnum].u < min_u)
2255 min_u = sidep->uvls[vertnum].u;
2256 else if (sidep->uvls[vertnum].u > max_u)
2257 max_u = sidep->uvls[vertnum].u;
2259 if (sidep->uvls[vertnum].v < min_v)
2260 min_v = sidep->uvls[vertnum].v;
2261 else if (sidep->uvls[vertnum].v > max_v)
2262 max_v = sidep->uvls[vertnum].v;
2264 if (sidep->uvls[vertnum].l < min_l)
2265 min_l = sidep->uvls[vertnum].l;
2266 else if (sidep->uvls[vertnum].l > max_l)
2267 max_l = sidep->uvls[vertnum].l;
2273 // 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)));
2274 // mprintf((0, "Static light maximum = %7.3f\n", f2fl(max_sl)));
2275 // mprintf((0, "Number of walls: %i\n", Num_walls));
2283 //read in every level in mission and save out compiled version
2284 void save_all_compiled_levels(void)
2286 do_load_save_levels(1);
2289 //read in every level in mission
2290 void load_all_levels(void)
2292 do_load_save_levels(0);
2296 void do_load_save_levels(int save)
2300 if (! SafetyCheck())
2303 no_old_level_file_error=1;
2305 for (level_num=1;level_num<=Last_level;level_num++) {
2306 load_level(Level_names[level_num-1]);
2307 load_palette(Current_level_palette,1,1); //don't change screen
2309 save_level_sub(Level_names[level_num-1],1);
2312 for (level_num=-1;level_num>=Last_secret_level;level_num--) {
2313 load_level(Secret_level_names[-level_num-1]);
2314 load_palette(Current_level_palette,1,1); //don't change screen
2316 save_level_sub(Secret_level_names[-level_num-1],1);
2319 no_old_level_file_error=0;