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.
17 * Save game information
27 char gamesave_rcsid[] = "$Id: gamesave.c,v 1.8 2002-07-27 22:39:57 btb Exp $";
43 #include "editor/editor.h"
75 char Gamesave_current_filename[128];
77 #define GAME_VERSION 32
78 #define GAME_COMPATIBLE_VERSION 22
80 //version 28->29 add delta light support
81 //version 27->28 controlcen id now is reactor number, not model number
83 //version 29->30 changed trigger structure
84 //version 30->31 changed trigger structure some more
85 //version 31->32 change segment structure, make it 512 bytes w/o editor, add Segment2s array.
87 #define MENU_CURSOR_X_MIN MENU_X
88 #define MENU_CURSOR_X_MAX MENU_X+6
91 ushort fileinfo_signature;
92 ushort fileinfo_version;
94 } game_top_fileinfo; // Should be same as first two fields below...
97 ushort fileinfo_signature;
98 ushort fileinfo_version;
100 char mine_filename[15];
102 int player_offset; // Player info
104 int object_offset; // Object info
114 int triggers_howmany;
125 int dl_indices_offset;
126 int dl_indices_howmany;
127 int dl_indices_sizeof;
128 int delta_light_offset;
129 int delta_light_howmany;
130 int delta_light_sizeof;
133 // LINT: adding function prototypes
134 void read_object(object *obj, CFILE *f, int version);
135 void write_object(object *obj, FILE *f);
136 void do_load_save_levels(int save);
137 void dump_mine_info(void);
139 extern char MaxPowerupsAllowed[MAX_POWERUP_TYPES];
140 extern char PowerupsInMine[MAX_POWERUP_TYPES];
143 extern char mine_filename[];
144 extern int save_mine_data_compiled(FILE * SaveFile);
146 //--unused-- char mine_filename[128];
149 int Gamesave_num_org_robots = 0;
150 //--unused-- grs_bitmap * Gamesave_saved_bitmap = NULL;
153 // Return true if this level has a name of the form "level??"
154 // Note that a pathspec can appear at the beginning of the filename.
155 int is_real_level(char *filename)
157 int len = strlen(filename);
162 //mprintf((0, "String = [%s]\n", &filename[len-11]));
163 return !strnicmp(&filename[len-11], "level", 5);
168 void change_filename_extension( char *dest, char *src, char *new_ext )
177 for (i=1; i<strlen(dest); i++ )
178 if (dest[i]=='.'||dest[i]==' '||dest[i]==0)
183 dest[i+1]=new_ext[0];
184 dest[i+2]=new_ext[1];
185 dest[i+3]=new_ext[2];
191 //--unused-- vms_angvec zero_angles={0,0,0};
193 #define vm_angvec_zero(v) do {(v)->p=(v)->b=(v)->h=0;} while (0)
195 int Gamesave_num_players=0;
197 int N_save_pof_names;
198 char Save_pof_names[MAX_POLYGON_MODELS][FILENAME_LEN];
200 void check_and_fix_matrix(vms_matrix *m);
202 void verify_object( object * obj ) {
204 obj->lifeleft = IMMORTAL_TIME; //all loaded object are immortal, for now
206 if ( obj->type == OBJ_ROBOT ) {
207 Gamesave_num_org_robots++;
209 // Make sure valid id...
210 if ( obj->id >= N_robot_types )
211 obj->id = obj->id % N_robot_types;
213 // Make sure model number & size are correct...
214 if ( obj->render_type == RT_POLYOBJ ) {
215 Assert(Robot_info[obj->id].model_num != -1);
216 //if you fail this assert, it means that a robot in this level
217 //hasn't been loaded, possibly because he's marked as
218 //non-shareware. To see what robot number, print obj->id.
220 Assert(Robot_info[obj->id].always_0xabcd == 0xabcd);
221 //if you fail this assert, it means that the robot_ai for
222 //a robot in this level hasn't been loaded, possibly because
223 //it's marked as non-shareware. To see what robot number,
226 obj->rtype.pobj_info.model_num = Robot_info[obj->id].model_num;
227 obj->size = Polygon_models[obj->rtype.pobj_info.model_num].rad;
229 //@@Took out this ugly hack 1/12/96, because Mike has added code
230 //@@that should fix it in a better way.
231 //@@//this is a super-ugly hack. Since the baby stripe robots have
232 //@@//their firing point on their bounding sphere, the firing points
233 //@@//can poke through a wall if the robots are very close to it. So
234 //@@//we make their radii bigger so the guns can't get too close to
236 //@@if (Robot_info[obj->id].flags & RIF_BIG_RADIUS)
237 //@@ obj->size = (obj->size*3)/2;
239 //@@if (obj->control_type==CT_AI && Robot_info[obj->id].attack_type)
240 //@@ obj->size = obj->size*3/4;
243 if (obj->id == 65) //special "reactor" robots
244 obj->movement_type = MT_NONE;
246 if (obj->movement_type == MT_PHYSICS) {
247 obj->mtype.phys_info.mass = Robot_info[obj->id].mass;
248 obj->mtype.phys_info.drag = Robot_info[obj->id].drag;
251 else { //Robots taken care of above
253 if ( obj->render_type == RT_POLYOBJ ) {
255 char *name = Save_pof_names[obj->rtype.pobj_info.model_num];
257 for (i=0;i<N_polygon_models;i++)
258 if (!stricmp(Pof_names[i],name)) { //found it!
259 // mprintf((0,"Mapping <%s> to %d (was %d)\n",name,i,obj->rtype.pobj_info.model_num));
260 obj->rtype.pobj_info.model_num = i;
266 if ( obj->type == OBJ_POWERUP ) {
267 if ( obj->id >= N_powerup_types ) {
269 Assert( obj->render_type != RT_POLYOBJ );
271 obj->control_type = CT_POWERUP;
272 obj->size = Powerup_info[obj->id].size;
273 obj->ctype.powerup_info.creation_time = 0;
276 if (Game_mode & GM_NETWORK)
278 if (multi_powerup_is_4pack(obj->id))
280 PowerupsInMine[obj->id-1]+=4;
281 MaxPowerupsAllowed[obj->id-1]+=4;
283 PowerupsInMine[obj->id]++;
284 MaxPowerupsAllowed[obj->id]++;
285 mprintf ((0,"PowerupLimiter: ID=%d\n",obj->id));
286 if (obj->id>MAX_POWERUP_TYPES)
287 mprintf ((1,"POWERUP: Overwriting array bounds!! Get JL!\n"));
293 if ( obj->type == OBJ_WEAPON ) {
294 if ( obj->id >= N_weapon_types ) {
296 Assert( obj->render_type != RT_POLYOBJ );
299 if (obj->id == PMINE_ID) { //make sure pmines have correct values
301 obj->mtype.phys_info.mass = Weapon_info[obj->id].mass;
302 obj->mtype.phys_info.drag = Weapon_info[obj->id].drag;
303 obj->mtype.phys_info.flags |= PF_FREE_SPINNING;
305 // Make sure model number & size are correct...
306 Assert( obj->render_type == RT_POLYOBJ );
308 obj->rtype.pobj_info.model_num = Weapon_info[obj->id].model_num;
309 obj->size = Polygon_models[obj->rtype.pobj_info.model_num].rad;
313 if ( obj->type == OBJ_CNTRLCEN ) {
315 obj->render_type = RT_POLYOBJ;
316 obj->control_type = CT_CNTRLCEN;
318 //@@// Make model number is correct...
319 //@@for (i=0; i<Num_total_object_types; i++ )
320 //@@ if ( ObjType[i] == OL_CONTROL_CENTER ) {
321 //@@ obj->rtype.pobj_info.model_num = ObjId[i];
322 //@@ obj->shields = ObjStrength[i];
329 // Check, and set, strength of reactor
330 for (i=0; i<Num_total_object_types; i++ )
331 if ( ObjType[i]==OL_CONTROL_CENTER && ObjId[i] == obj->id ) {
332 obj->shields = ObjStrength[i];
335 Assert(i < Num_total_object_types); //make sure we found it
340 if ( obj->type == OBJ_PLAYER ) {
343 //Assert(obj == Player);
345 if ( obj == ConsoleObject )
346 init_player_object();
348 if (obj->render_type == RT_POLYOBJ) //recover from Matt's pof file matchup bug
349 obj->rtype.pobj_info.model_num = Player_ship->model_num;
351 //Make sure orient matrix is orthogonal
352 check_and_fix_matrix(&obj->orient);
354 obj->id = Gamesave_num_players++;
357 if (obj->type == OBJ_HOSTAGE) {
359 //@@if (obj->id > N_hostage_types)
362 obj->render_type = RT_HOSTAGE;
363 obj->control_type = CT_POWERUP;
368 //static gs_skip(int len,CFILE *file)
371 // cfseek(file,len,SEEK_CUR);
375 static void gs_write_int(int i,FILE *file)
377 if (fwrite( &i, sizeof(i), 1, file) != 1)
378 Error( "Error reading int in gamesave.c" );
382 static void gs_write_fix(fix f,FILE *file)
384 if (fwrite( &f, sizeof(f), 1, file) != 1)
385 Error( "Error reading fix in gamesave.c" );
389 static void gs_write_short(short s,FILE *file)
391 if (fwrite( &s, sizeof(s), 1, file) != 1)
392 Error( "Error reading short in gamesave.c" );
396 static void gs_write_fixang(fixang f,FILE *file)
398 if (fwrite( &f, sizeof(f), 1, file) != 1)
399 Error( "Error reading fixang in gamesave.c" );
403 static void gs_write_byte(byte b,FILE *file)
405 if (fwrite( &b, sizeof(b), 1, file) != 1)
406 Error( "Error reading byte in gamesave.c" );
410 static void gr_write_vector(vms_vector *v,FILE *file)
412 gs_write_fix(v->x,file);
413 gs_write_fix(v->y,file);
414 gs_write_fix(v->z,file);
417 static void gs_write_matrix(vms_matrix *m,FILE *file)
419 gr_write_vector(&m->rvec,file);
420 gr_write_vector(&m->uvec,file);
421 gr_write_vector(&m->fvec,file);
424 static void gs_write_angvec(vms_angvec *v,FILE *file)
426 gs_write_fixang(v->p,file);
427 gs_write_fixang(v->b,file);
428 gs_write_fixang(v->h,file);
434 extern int multi_powerup_is_4pack(int);
435 //reads one object of the given version from the given file
436 void read_object(object *obj,CFILE *f,int version)
439 obj->type = cfile_read_byte(f);
440 obj->id = cfile_read_byte(f);
442 if (obj->type == OBJ_CNTRLCEN && version<28)
443 obj->id = 0; //used to be only one kind of reactor
445 obj->control_type = cfile_read_byte(f);
446 obj->movement_type = cfile_read_byte(f);
447 obj->render_type = cfile_read_byte(f);
448 obj->flags = cfile_read_byte(f);
450 obj->segnum = cfile_read_short(f);
451 obj->attached_obj = -1;
453 cfile_read_vector(&obj->pos,f);
454 cfile_read_matrix(&obj->orient,f);
456 obj->size = cfile_read_fix(f);
457 obj->shields = cfile_read_fix(f);
459 cfile_read_vector(&obj->last_pos,f);
461 obj->contains_type = cfile_read_byte(f);
462 obj->contains_id = cfile_read_byte(f);
463 obj->contains_count = cfile_read_byte(f);
465 switch (obj->movement_type) {
469 cfile_read_vector(&obj->mtype.phys_info.velocity,f);
470 cfile_read_vector(&obj->mtype.phys_info.thrust,f);
472 obj->mtype.phys_info.mass = cfile_read_fix(f);
473 obj->mtype.phys_info.drag = cfile_read_fix(f);
474 obj->mtype.phys_info.brakes = cfile_read_fix(f);
476 cfile_read_vector(&obj->mtype.phys_info.rotvel,f);
477 cfile_read_vector(&obj->mtype.phys_info.rotthrust,f);
479 obj->mtype.phys_info.turnroll = cfile_read_fixang(f);
480 obj->mtype.phys_info.flags = cfile_read_short(f);
486 cfile_read_vector(&obj->mtype.spin_rate,f);
496 switch (obj->control_type) {
501 obj->ctype.ai_info.behavior = cfile_read_byte(f);
503 for (i=0;i<MAX_AI_FLAGS;i++)
504 obj->ctype.ai_info.flags[i] = cfile_read_byte(f);
506 obj->ctype.ai_info.hide_segment = cfile_read_short(f);
507 obj->ctype.ai_info.hide_index = cfile_read_short(f);
508 obj->ctype.ai_info.path_length = cfile_read_short(f);
509 obj->ctype.ai_info.cur_path_index = cfile_read_short(f);
512 cfile_read_short(f); // obj->ctype.ai_info.follow_path_start_seg =
513 cfile_read_short(f); // obj->ctype.ai_info.follow_path_end_seg =
521 obj->ctype.expl_info.spawn_time = cfile_read_fix(f);
522 obj->ctype.expl_info.delete_time = cfile_read_fix(f);
523 obj->ctype.expl_info.delete_objnum = cfile_read_short(f);
524 obj->ctype.expl_info.next_attach = obj->ctype.expl_info.prev_attach = obj->ctype.expl_info.attach_parent = -1;
530 //do I really need to read these? Are they even saved to disk?
532 obj->ctype.laser_info.parent_type = cfile_read_short(f);
533 obj->ctype.laser_info.parent_num = cfile_read_short(f);
534 obj->ctype.laser_info.parent_signature = cfile_read_int(f);
540 obj->ctype.light_info.intensity = cfile_read_fix(f);
546 obj->ctype.powerup_info.count = cfile_read_int(f);
548 obj->ctype.powerup_info.count = 1;
550 if (obj->id == POW_VULCAN_WEAPON)
551 obj->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT;
553 if (obj->id == POW_GAUSS_WEAPON)
554 obj->ctype.powerup_info.count = VULCAN_WEAPON_AMMO_AMOUNT;
556 if (obj->id == POW_OMEGA_WEAPON)
557 obj->ctype.powerup_info.count = MAX_OMEGA_CHARGE;
567 case CT_SLEW: //the player is generally saved as slew
581 switch (obj->render_type) {
590 obj->rtype.pobj_info.model_num = cfile_read_int(f);
592 for (i=0;i<MAX_SUBMODELS;i++)
593 cfile_read_angvec(&obj->rtype.pobj_info.anim_angles[i],f);
595 obj->rtype.pobj_info.subobj_flags = cfile_read_int(f);
597 tmo = cfile_read_int(f);
600 obj->rtype.pobj_info.tmap_override = tmo;
603 obj->rtype.pobj_info.tmap_override = -1;
605 int xlated_tmo = tmap_xlate_table[tmo];
606 if (xlated_tmo < 0) {
607 mprintf( (0, "Couldn't find texture for demo object, model_num = %d\n", obj->rtype.pobj_info.model_num));
611 obj->rtype.pobj_info.tmap_override = xlated_tmo;
615 obj->rtype.pobj_info.alt_textures = 0;
620 case RT_WEAPON_VCLIP:
625 obj->rtype.vclip_info.vclip_num = cfile_read_int(f);
626 obj->rtype.vclip_info.frametime = cfile_read_fix(f);
627 obj->rtype.vclip_info.framenum = cfile_read_byte(f);
643 //writes one object to the given file
644 void write_object(object *obj,FILE *f)
646 gs_write_byte(obj->type,f);
647 gs_write_byte(obj->id,f);
649 gs_write_byte(obj->control_type,f);
650 gs_write_byte(obj->movement_type,f);
651 gs_write_byte(obj->render_type,f);
652 gs_write_byte(obj->flags,f);
654 gs_write_short(obj->segnum,f);
656 gr_write_vector(&obj->pos,f);
657 gs_write_matrix(&obj->orient,f);
659 gs_write_fix(obj->size,f);
660 gs_write_fix(obj->shields,f);
662 gr_write_vector(&obj->last_pos,f);
664 gs_write_byte(obj->contains_type,f);
665 gs_write_byte(obj->contains_id,f);
666 gs_write_byte(obj->contains_count,f);
668 switch (obj->movement_type) {
672 gr_write_vector(&obj->mtype.phys_info.velocity,f);
673 gr_write_vector(&obj->mtype.phys_info.thrust,f);
675 gs_write_fix(obj->mtype.phys_info.mass,f);
676 gs_write_fix(obj->mtype.phys_info.drag,f);
677 gs_write_fix(obj->mtype.phys_info.brakes,f);
679 gr_write_vector(&obj->mtype.phys_info.rotvel,f);
680 gr_write_vector(&obj->mtype.phys_info.rotthrust,f);
682 gs_write_fixang(obj->mtype.phys_info.turnroll,f);
683 gs_write_short(obj->mtype.phys_info.flags,f);
689 gr_write_vector(&obj->mtype.spin_rate,f);
699 switch (obj->control_type) {
704 gs_write_byte(obj->ctype.ai_info.behavior,f);
706 for (i=0;i<MAX_AI_FLAGS;i++)
707 gs_write_byte(obj->ctype.ai_info.flags[i],f);
709 gs_write_short(obj->ctype.ai_info.hide_segment,f);
710 gs_write_short(obj->ctype.ai_info.hide_index,f);
711 gs_write_short(obj->ctype.ai_info.path_length,f);
712 gs_write_short(obj->ctype.ai_info.cur_path_index,f);
714 // -- unused! mk, 08/13/95 -- gs_write_short(obj->ctype.ai_info.follow_path_start_seg,f);
715 // -- unused! mk, 08/13/95 -- gs_write_short(obj->ctype.ai_info.follow_path_end_seg,f);
722 gs_write_fix(obj->ctype.expl_info.spawn_time,f);
723 gs_write_fix(obj->ctype.expl_info.delete_time,f);
724 gs_write_short(obj->ctype.expl_info.delete_objnum,f);
730 //do I really need to write these objects?
732 gs_write_short(obj->ctype.laser_info.parent_type,f);
733 gs_write_short(obj->ctype.laser_info.parent_num,f);
734 gs_write_int(obj->ctype.laser_info.parent_signature,f);
740 gs_write_fix(obj->ctype.light_info.intensity,f);
745 gs_write_int(obj->ctype.powerup_info.count,f);
753 case CT_SLEW: //the player is generally saved as slew
757 break; //control center object.
767 switch (obj->render_type) {
776 gs_write_int(obj->rtype.pobj_info.model_num,f);
778 for (i=0;i<MAX_SUBMODELS;i++)
779 gs_write_angvec(&obj->rtype.pobj_info.anim_angles[i],f);
781 gs_write_int(obj->rtype.pobj_info.subobj_flags,f);
783 gs_write_int(obj->rtype.pobj_info.tmap_override,f);
788 case RT_WEAPON_VCLIP:
793 gs_write_int(obj->rtype.vclip_info.vclip_num,f);
794 gs_write_fix(obj->rtype.vclip_info.frametime,f);
795 gs_write_byte(obj->rtype.vclip_info.framenum,f);
810 extern int remove_trigger_num(int trigger_num);
812 // -----------------------------------------------------------------------------
814 // Loads all the relevant data for a level.
815 // If level != -1, it loads the filename with extension changed to .min
816 // Otherwise it loads the appropriate level mine.
817 // returns 0=everything ok, 1=old version, -1=error
818 int load_game_data(CFILE *LoadFile)
823 start_offset = cftell(LoadFile);
825 //===================== READ FILE INFO ========================
827 // Set default values
828 game_fileinfo.level = -1;
829 game_fileinfo.player_offset = -1;
830 game_fileinfo.player_sizeof = sizeof(player);
831 game_fileinfo.object_offset = -1;
832 game_fileinfo.object_howmany = 0;
833 game_fileinfo.object_sizeof = sizeof(object);
834 game_fileinfo.walls_offset = -1;
835 game_fileinfo.walls_howmany = 0;
836 game_fileinfo.walls_sizeof = sizeof(wall);
837 game_fileinfo.doors_offset = -1;
838 game_fileinfo.doors_howmany = 0;
839 game_fileinfo.doors_sizeof = sizeof(active_door);
840 game_fileinfo.triggers_offset = -1;
841 game_fileinfo.triggers_howmany = 0;
842 game_fileinfo.triggers_sizeof = sizeof(trigger);
843 game_fileinfo.control_offset = -1;
844 game_fileinfo.control_howmany = 0;
845 game_fileinfo.control_sizeof = sizeof(control_center_triggers);
846 game_fileinfo.matcen_offset = -1;
847 game_fileinfo.matcen_howmany = 0;
848 game_fileinfo.matcen_sizeof = sizeof(matcen_info);
850 game_fileinfo.dl_indices_offset = -1;
851 game_fileinfo.dl_indices_howmany = 0;
852 game_fileinfo.dl_indices_sizeof = sizeof(dl_index);
854 game_fileinfo.delta_light_offset = -1;
855 game_fileinfo.delta_light_howmany = 0;
856 game_fileinfo.delta_light_sizeof = sizeof(delta_light);
858 // Read in game_top_fileinfo to get size of saved fileinfo.
860 if (cfseek( LoadFile, start_offset, SEEK_SET ))
861 Error( "Error seeking in gamesave.c" );
863 // if (cfread( &game_top_fileinfo, sizeof(game_top_fileinfo), 1, LoadFile) != 1)
864 // Error( "Error reading game_top_fileinfo in gamesave.c" );
866 game_top_fileinfo.fileinfo_signature = cfile_read_short(LoadFile);
867 game_top_fileinfo.fileinfo_version = cfile_read_short(LoadFile);
868 game_top_fileinfo.fileinfo_sizeof = cfile_read_int(LoadFile);
871 if (game_top_fileinfo.fileinfo_signature != 0x6705)
874 // Check version number
875 if (game_top_fileinfo.fileinfo_version < GAME_COMPATIBLE_VERSION )
878 // Now, Read in the fileinfo
879 if (cfseek( LoadFile, start_offset, SEEK_SET ))
880 Error( "Error seeking to game_fileinfo in gamesave.c" );
882 // if (cfread( &game_fileinfo, game_top_fileinfo.fileinfo_sizeof, 1, LoadFile )!=1)
883 // Error( "Error reading game_fileinfo in gamesave.c" );
885 game_fileinfo.fileinfo_signature = cfile_read_short(LoadFile);
886 game_fileinfo.fileinfo_version = cfile_read_short(LoadFile);
887 game_fileinfo.fileinfo_sizeof = cfile_read_int(LoadFile);
889 game_fileinfo.mine_filename[i] = cfile_read_byte(LoadFile);
890 game_fileinfo.level = cfile_read_int(LoadFile);
891 game_fileinfo.player_offset = cfile_read_int(LoadFile); // Player info
892 game_fileinfo.player_sizeof = cfile_read_int(LoadFile);
893 game_fileinfo.object_offset = cfile_read_int(LoadFile); // Object info
894 game_fileinfo.object_howmany = cfile_read_int(LoadFile);
895 game_fileinfo.object_sizeof = cfile_read_int(LoadFile);
896 game_fileinfo.walls_offset = cfile_read_int(LoadFile);
897 game_fileinfo.walls_howmany = cfile_read_int(LoadFile);
898 game_fileinfo.walls_sizeof = cfile_read_int(LoadFile);
899 game_fileinfo.doors_offset = cfile_read_int(LoadFile);
900 game_fileinfo.doors_howmany = cfile_read_int(LoadFile);
901 game_fileinfo.doors_sizeof = cfile_read_int(LoadFile);
902 game_fileinfo.triggers_offset = cfile_read_int(LoadFile);
903 game_fileinfo.triggers_howmany = cfile_read_int(LoadFile);
904 game_fileinfo.triggers_sizeof = cfile_read_int(LoadFile);
905 game_fileinfo.links_offset = cfile_read_int(LoadFile);
906 game_fileinfo.links_howmany = cfile_read_int(LoadFile);
907 game_fileinfo.links_sizeof = cfile_read_int(LoadFile);
908 game_fileinfo.control_offset = cfile_read_int(LoadFile);
909 game_fileinfo.control_howmany = cfile_read_int(LoadFile);
910 game_fileinfo.control_sizeof = cfile_read_int(LoadFile);
911 game_fileinfo.matcen_offset = cfile_read_int(LoadFile);
912 game_fileinfo.matcen_howmany = cfile_read_int(LoadFile);
913 game_fileinfo.matcen_sizeof = cfile_read_int(LoadFile);
915 if (game_top_fileinfo.fileinfo_version >= 29) {
916 game_fileinfo.dl_indices_offset = cfile_read_int(LoadFile);
917 game_fileinfo.dl_indices_howmany = cfile_read_int(LoadFile);
918 game_fileinfo.dl_indices_sizeof = cfile_read_int(LoadFile);
920 game_fileinfo.delta_light_offset = cfile_read_int(LoadFile);
921 game_fileinfo.delta_light_howmany = cfile_read_int(LoadFile);
922 game_fileinfo.delta_light_sizeof = cfile_read_int(LoadFile);
925 if (game_top_fileinfo.fileinfo_version >= 14) { //load mine filename
926 //@@char *p=Current_level_name;
927 //@@//must do read one char at a time, since no cfgets()
928 //@@do *p = cfgetc(LoadFile); while (*p++!=0);
930 cfgets(Current_level_name,sizeof(Current_level_name),LoadFile);
932 if (Current_level_name[strlen(Current_level_name)-1] == '\n')
933 Current_level_name[strlen(Current_level_name)-1] = 0;
936 Current_level_name[0]=0;
938 if (game_top_fileinfo.fileinfo_version >= 19) { //load pof names
939 // cfread(&N_save_pof_names,2,1,LoadFile);
940 N_save_pof_names = cfile_read_short(LoadFile);
941 cfread(Save_pof_names,N_save_pof_names,FILENAME_LEN,LoadFile);
944 //===================== READ PLAYER INFO ==========================
945 Object_next_signature = 0;
947 //===================== READ OBJECT INFO ==========================
949 Gamesave_num_org_robots = 0;
950 Gamesave_num_players = 0;
952 if (game_fileinfo.object_offset > -1) {
953 if (cfseek( LoadFile, game_fileinfo.object_offset, SEEK_SET ))
954 Error( "Error seeking to object_offset in gamesave.c" );
956 for (i=0;i<game_fileinfo.object_howmany;i++) {
958 read_object(&Objects[i],LoadFile,game_top_fileinfo.fileinfo_version);
960 Objects[i].signature = Object_next_signature++;
961 verify_object( &Objects[i] );
966 //===================== READ WALL INFO ============================
968 if (game_fileinfo.walls_offset > -1)
971 if (!cfseek( LoadFile, game_fileinfo.walls_offset,SEEK_SET )) {
972 for (i=0;i<game_fileinfo.walls_howmany;i++) {
974 if (game_top_fileinfo.fileinfo_version >= 20)
975 wall_read(&Walls[i], LoadFile); // v20 walls and up.
976 else if (game_top_fileinfo.fileinfo_version >= 17) {
979 v19_wall_read(&w, LoadFile);
981 Walls[i].segnum = w.segnum;
982 Walls[i].sidenum = w.sidenum;
983 Walls[i].linked_wall = w.linked_wall;
985 Walls[i].type = w.type;
986 Walls[i].flags = w.flags;
987 Walls[i].hps = w.hps;
988 Walls[i].trigger = w.trigger;
989 Walls[i].clip_num = w.clip_num;
990 Walls[i].keys = w.keys;
992 Walls[i].state = WALL_DOOR_CLOSED;
996 v16_wall_read(&w, LoadFile);
998 Walls[i].segnum = Walls[i].sidenum = Walls[i].linked_wall = -1;
1000 Walls[i].type = w.type;
1001 Walls[i].flags = w.flags;
1002 Walls[i].hps = w.hps;
1003 Walls[i].trigger = w.trigger;
1004 Walls[i].clip_num = w.clip_num;
1005 Walls[i].keys = w.keys;
1012 //===================== READ DOOR INFO ============================
1014 if (game_fileinfo.doors_offset > -1)
1016 if (!cfseek( LoadFile, game_fileinfo.doors_offset,SEEK_SET )) {
1018 for (i=0;i<game_fileinfo.doors_howmany;i++) {
1020 if (game_top_fileinfo.fileinfo_version >= 20)
1021 active_door_read(&ActiveDoors[i], LoadFile); // version 20 and up
1026 v19_door_read(&d, LoadFile);
1028 ActiveDoors[i].n_parts = d.n_parts;
1030 for (p=0;p<d.n_parts;p++) {
1033 cseg = Segments[d.seg[p]].children[d.side[p]];
1034 cside = find_connect_side(&Segments[d.seg[p]],&Segments[cseg]);
1036 ActiveDoors[i].front_wallnum[p] = Segments[d.seg[p]].sides[d.side[p]].wall_num;
1037 ActiveDoors[i].back_wallnum[p] = Segments[cseg].sides[cside].wall_num;
1045 //==================== READ TRIGGER INFO ==========================
1048 // for MACINTOSH -- assume all triggers >= verion 31 triggers.
1050 if (game_fileinfo.triggers_offset > -1)
1052 if (!cfseek( LoadFile, game_fileinfo.triggers_offset,SEEK_SET )) {
1053 for (i=0;i<game_fileinfo.triggers_howmany;i++)
1054 if (game_top_fileinfo.fileinfo_version < 31) {
1060 if (game_top_fileinfo.fileinfo_version < 30) {
1064 v29_trigger_read(&trig29, LoadFile);
1066 trig.flags = trig29.flags;
1067 trig.num_links = trig29.num_links;
1068 trig.num_links = trig29.num_links;
1069 trig.value = trig29.value;
1070 trig.time = trig29.time;
1072 for (t=0;t<trig.num_links;t++) {
1073 trig.seg[t] = trig29.seg[t];
1074 trig.side[t] = trig29.side[t];
1078 v30_trigger_read(&trig, LoadFile);
1080 //Assert(trig.flags & TRIGGER_ON);
1081 trig.flags &= ~TRIGGER_ON;
1083 if (trig.flags & TRIGGER_CONTROL_DOORS)
1084 type = TT_OPEN_DOOR;
1085 else if (trig.flags & TRIGGER_SHIELD_DAMAGE)
1087 else if (trig.flags & TRIGGER_ENERGY_DRAIN)
1089 else if (trig.flags & TRIGGER_EXIT)
1091 else if (trig.flags & TRIGGER_ONE_SHOT)
1093 else if (trig.flags & TRIGGER_MATCEN)
1095 else if (trig.flags & TRIGGER_ILLUSION_OFF)
1096 type = TT_ILLUSION_OFF;
1097 else if (trig.flags & TRIGGER_SECRET_EXIT)
1098 type = TT_SECRET_EXIT;
1099 else if (trig.flags & TRIGGER_ILLUSION_ON)
1100 type = TT_ILLUSION_ON;
1101 else if (trig.flags & TRIGGER_UNLOCK_DOORS)
1102 type = TT_UNLOCK_DOOR;
1103 else if (trig.flags & TRIGGER_OPEN_WALL)
1104 type = TT_OPEN_WALL;
1105 else if (trig.flags & TRIGGER_CLOSE_WALL)
1106 type = TT_CLOSE_WALL;
1107 else if (trig.flags & TRIGGER_ILLUSORY_WALL)
1108 type = TT_ILLUSORY_WALL;
1112 Triggers[i].type = type;
1113 Triggers[i].flags = 0;
1114 Triggers[i].num_links = trig.num_links;
1115 Triggers[i].num_links = trig.num_links;
1116 Triggers[i].value = trig.value;
1117 Triggers[i].time = trig.time;
1119 for (t=0;t<trig.num_links;t++) {
1120 Triggers[i].seg[t] = trig.seg[t];
1121 Triggers[i].side[t] = trig.side[t];
1125 trigger_read(&Triggers[i], LoadFile);
1129 //================ READ CONTROL CENTER TRIGGER INFO ===============
1131 if (game_fileinfo.control_offset > -1)
1132 if (!cfseek( LoadFile, game_fileinfo.control_offset,SEEK_SET ))
1133 for (i=0;i<game_fileinfo.control_howmany;i++)
1134 control_center_triggers_read(&ControlCenterTriggers, LoadFile);
1137 //================ READ MATERIALOGRIFIZATIONATORS INFO ===============
1139 if (game_fileinfo.matcen_offset > -1)
1142 if (!cfseek( LoadFile, game_fileinfo.matcen_offset,SEEK_SET )) {
1143 // mprintf((0, "Reading %i materialization centers.\n", game_fileinfo.matcen_howmany));
1144 for (i=0;i<game_fileinfo.matcen_howmany;i++) {
1145 if (game_top_fileinfo.fileinfo_version < 27) {
1148 old_matcen_info_read(&m, LoadFile);
1150 RobotCenters[i].robot_flags[0] = m.robot_flags;
1151 RobotCenters[i].robot_flags[1] = 0;
1152 RobotCenters[i].hit_points = m.hit_points;
1153 RobotCenters[i].interval = m.interval;
1154 RobotCenters[i].segnum = m.segnum;
1155 RobotCenters[i].fuelcen_num = m.fuelcen_num;
1158 matcen_info_read(&RobotCenters[i], LoadFile);
1160 // Set links in RobotCenters to Station array
1162 for (j=0; j<=Highest_segment_index; j++)
1163 if (Segment2s[j].special == SEGMENT_IS_ROBOTMAKER)
1164 if (Segment2s[j].matcen_num == i)
1165 RobotCenters[i].fuelcen_num = Segment2s[j].value;
1167 // mprintf((0, " %i: flags = %08x\n", i, RobotCenters[i].robot_flags));
1173 //================ READ DL_INDICES INFO ===============
1175 Num_static_lights = 0;
1177 if (game_fileinfo.dl_indices_offset > -1) {
1180 if (!cfseek( LoadFile, game_fileinfo.dl_indices_offset, SEEK_SET )) {
1181 Num_static_lights = game_fileinfo.dl_indices_howmany;
1182 for (i=0; i<game_fileinfo.dl_indices_howmany; i++) {
1183 if (game_top_fileinfo.fileinfo_version < 29) {
1184 mprintf((0, "Warning: Old mine version. Not reading Dl_indices info.\n"));
1185 Int3(); //shouldn't be here!!!
1187 dl_index_read(&Dl_indices[i], LoadFile);
1192 // Indicate that no light has been subtracted from any vertices.
1193 clear_light_subtracted();
1195 //================ READ DELTA LIGHT INFO ===============
1197 if (game_fileinfo.delta_light_offset > -1) {
1200 if (!cfseek( LoadFile, game_fileinfo.delta_light_offset, SEEK_SET )) {
1201 for (i=0; i<game_fileinfo.delta_light_howmany; i++) {
1202 if (game_top_fileinfo.fileinfo_version < 29) {
1203 mprintf((0, "Warning: Old mine version. Not reading delta light info.\n"));
1205 delta_light_read(&Delta_lights[i], LoadFile);
1210 //========================= UPDATE VARIABLES ======================
1212 reset_objects(game_fileinfo.object_howmany);
1214 for (i=0; i<MAX_OBJECTS; i++) {
1215 Objects[i].next = Objects[i].prev = -1;
1216 if (Objects[i].type != OBJ_NONE) {
1217 int objsegnum = Objects[i].segnum;
1219 if (objsegnum > Highest_segment_index) //bogus object
1220 Objects[i].type = OBJ_NONE;
1222 Objects[i].segnum = -1; //avoid Assert()
1223 obj_link(i,objsegnum);
1228 clear_transient_objects(1); //1 means clear proximity bombs
1230 // Make sure non-transparent doors are set correctly.
1231 for (i=0; i< Num_segments; i++)
1232 for (j=0;j<MAX_SIDES_PER_SEGMENT;j++) {
1233 side *sidep = &Segments[i].sides[j];
1234 if ((sidep->wall_num != -1) && (Walls[sidep->wall_num].clip_num != -1)) {
1235 //mprintf((0, "Checking Wall %d\n", Segments[i].sides[j].wall_num));
1236 if (WallAnims[Walls[sidep->wall_num].clip_num].flags & WCF_TMAP1) {
1237 //mprintf((0, "Fixing non-transparent door.\n"));
1238 sidep->tmap_num = WallAnims[Walls[sidep->wall_num].clip_num].frames[0];
1239 sidep->tmap_num2 = 0;
1245 Num_walls = game_fileinfo.walls_howmany;
1248 Num_open_doors = game_fileinfo.doors_howmany;
1249 Num_triggers = game_fileinfo.triggers_howmany;
1251 //go through all walls, killing references to invalid triggers
1252 for (i=0;i<Num_walls;i++)
1253 if (Walls[i].trigger >= Num_triggers) {
1254 mprintf((0,"Removing reference to invalid trigger %d from wall %d\n",Walls[i].trigger,i));
1255 Walls[i].trigger = -1; //kill trigger
1258 //go through all triggers, killing unused ones
1259 for (i=0;i<Num_triggers;) {
1262 // Find which wall this trigger is connected to.
1263 for (w=0; w<Num_walls; w++)
1264 if (Walls[w].trigger == i)
1268 if (w == Num_walls) {
1269 mprintf((0,"Removing unreferenced trigger %d\n",i));
1270 remove_trigger_num(i);
1277 // MK, 10/17/95: Make walls point back at the triggers that control them.
1278 // Go through all triggers, stuffing controlling_trigger field in Walls.
1281 for (i=0; i<Num_walls; i++)
1282 Walls[i].controlling_trigger = -1;
1284 for (t=0; t<Num_triggers; t++) {
1286 for (l=0; l<Triggers[t].num_links; l++) {
1287 int seg_num, side_num, wall_num;
1289 seg_num = Triggers[t].seg[l];
1290 side_num = Triggers[t].side[l];
1291 wall_num = Segments[seg_num].sides[side_num].wall_num;
1293 // -- if (Walls[wall_num].controlling_trigger != -1)
1296 //check to see that if a trigger requires a wall that it has one,
1297 //and if it requires a matcen that it has one
1299 if (Triggers[t].type == TT_MATCEN) {
1300 if (Segment2s[seg_num].special != SEGMENT_IS_ROBOTMAKER)
1301 Int3(); //matcen trigger doesn't point to matcen
1303 else if (Triggers[t].type != TT_LIGHT_OFF && Triggers[t].type != TT_LIGHT_ON) { //light triggers don't require walls
1305 Int3(); // This is illegal. This trigger requires a wall
1307 Walls[wall_num].controlling_trigger = t;
1313 Num_robot_centers = game_fileinfo.matcen_howmany;
1315 //fix old wall structs
1316 if (game_top_fileinfo.fileinfo_version < 17) {
1317 int segnum,sidenum,wallnum;
1319 for (segnum=0; segnum<=Highest_segment_index; segnum++)
1320 for (sidenum=0;sidenum<6;sidenum++)
1321 if ((wallnum=Segments[segnum].sides[sidenum].wall_num) != -1) {
1322 Walls[wallnum].segnum = segnum;
1323 Walls[wallnum].sidenum = sidenum;
1330 for (sidenum=0; sidenum<6; sidenum++) {
1331 int wallnum = Segments[Highest_segment_index].sides[sidenum].wall_num;
1333 if ((Walls[wallnum].segnum != Highest_segment_index) || (Walls[wallnum].sidenum != sidenum))
1334 Int3(); // Error. Bogus walls in this segment.
1335 // Consult Yuan or Mike.
1340 //create_local_segment_data();
1348 if (game_top_fileinfo.fileinfo_version < GAME_VERSION && !(game_top_fileinfo.fileinfo_version==25 && GAME_VERSION==26))
1349 return 1; //means old version
1355 int check_segment_connections(void);
1357 extern void set_ambient_sound_flags(void);
1359 // -----------------------------------------------------------------------------
1360 //loads from an already-open file
1361 // returns 0=everything ok, 1=old version, -1=error
1362 int load_mine_data(CFILE *LoadFile);
1363 int load_mine_data_compiled(CFILE *LoadFile);
1365 #define LEVEL_FILE_VERSION 8
1366 //1 -> 2 add palette name
1367 //2 -> 3 add control center explosion time
1368 //3 -> 4 add reactor strength
1369 //4 -> 5 killed hostage text stuff
1370 //5 -> 6 added Secret_return_segment and Secret_return_orient
1371 //6 -> 7 added flickering lights
1372 //7 -> 8 made version 8 to be not compatible with D2 1.0 & 1.1
1375 char *Level_being_loaded=NULL;
1379 extern void ncache_flush();
1382 extern int HoardEquipped();
1384 extern int Slide_segs_computed;
1386 int no_old_level_file_error=0;
1388 //loads a level (.LVL) file from disk
1389 //returns 0 if success, else error code
1390 int load_level(char * filename_passed)
1393 int use_compiled_level=1;
1397 int sig,version,minedata_offset,gamedata_offset;
1398 int mine_err,game_err;
1403 Slide_segs_computed = 0;
1406 if (Game_mode & GM_NETWORK)
1408 for (i=0;i<MAX_POWERUP_TYPES;i++)
1410 MaxPowerupsAllowed[i]=0;
1411 PowerupsInMine[i]=0;
1421 Level_being_loaded = filename_passed;
1424 strcpy(filename,filename_passed);
1428 //if we have the editor, try the LVL first, no matter what was passed.
1429 //if we don't have an LVL, try RDL
1430 //if we don't have the editor, we just use what was passed
1432 change_filename_extension(filename,filename_passed,".LVL");
1433 use_compiled_level = 0;
1435 if (!cfexist(filename)) {
1436 change_filename_extension(filename,filename,".RL2");
1437 use_compiled_level = 1;
1441 LoadFile = cfopen( filename, "rb" );
1445 mprintf((0,"Can't open level file <%s>\n", filename));
1448 Error("Can't open file <%s>\n",filename);
1452 strcpy( Gamesave_current_filename, filename );
1455 // if ( Newdemo_state == ND_STATE_RECORDING )
1456 // newdemo_record_start_demo();
1459 sig = cfile_read_int(LoadFile);
1460 version = cfile_read_int(LoadFile);
1461 minedata_offset = cfile_read_int(LoadFile);
1462 gamedata_offset = cfile_read_int(LoadFile);
1464 Assert(sig == MAKE_SIG('P','L','V','L'));
1466 if (version >= 8) { //read dummy data
1468 if (HoardEquipped())
1470 cfile_read_int(LoadFile);
1471 cfile_read_short(LoadFile);
1472 cfile_read_byte(LoadFile);
1476 // NOTE LINK TO ABOVE!
1477 Error("This level requires the Vertigo Enhanced version of D2.");
1482 cfile_read_int(LoadFile); //was hostagetext_offset
1485 cfgets(Current_level_palette,sizeof(Current_level_palette),LoadFile);
1486 if (Current_level_palette[strlen(Current_level_palette)-1] == '\n')
1487 Current_level_palette[strlen(Current_level_palette)-1] = 0;
1491 Base_control_center_explosion_time = cfile_read_int(LoadFile);
1493 Base_control_center_explosion_time = DEFAULT_CONTROL_CENTER_EXPLOSION_TIME;
1496 Reactor_strength = cfile_read_int(LoadFile);
1498 Reactor_strength = -1; //use old defaults
1503 Num_flickering_lights = cfile_read_int(LoadFile);
1504 Assert((Num_flickering_lights >= 0) && (Num_flickering_lights < MAX_FLICKERING_LIGHTS));
1505 for (i = 0; i < Num_flickering_lights; i++)
1506 flickering_light_read(&Flickering_lights[i], LoadFile);
1509 Num_flickering_lights = 0;
1511 if (version <= 1 || Current_level_palette[0]==0)
1512 strcpy(Current_level_palette,"groupa.256");
1515 Secret_return_segment = 0;
1516 Secret_return_orient.rvec.x = F1_0; Secret_return_orient.rvec.y = 0; Secret_return_orient.rvec.z = 0;
1517 Secret_return_orient.fvec.x = 0; Secret_return_orient.fvec.y = F1_0; Secret_return_orient.fvec.z = 0;
1518 Secret_return_orient.uvec.x = 0; Secret_return_orient.uvec.y = 0; Secret_return_orient.uvec.z = F1_0;
1520 Secret_return_segment = cfile_read_int(LoadFile);
1521 Secret_return_orient.rvec.x = cfile_read_int(LoadFile);
1522 Secret_return_orient.rvec.y = cfile_read_int(LoadFile);
1523 Secret_return_orient.rvec.z = cfile_read_int(LoadFile);
1524 Secret_return_orient.fvec.x = cfile_read_int(LoadFile);
1525 Secret_return_orient.fvec.y = cfile_read_int(LoadFile);
1526 Secret_return_orient.fvec.z = cfile_read_int(LoadFile);
1527 Secret_return_orient.uvec.x = cfile_read_int(LoadFile);
1528 Secret_return_orient.uvec.y = cfile_read_int(LoadFile);
1529 Secret_return_orient.uvec.z = cfile_read_int(LoadFile);
1532 cfseek(LoadFile,minedata_offset,SEEK_SET);
1534 if (!use_compiled_level) {
1535 mine_err = load_mine_data(LoadFile);
1536 #if 0 //dunno - 3rd party stuff?
1537 // Compress all uv coordinates in mine, improves texmap precision. --MK, 02/19/96
1538 compress_uv_coordinates_all();
1542 //NOTE LINK TO ABOVE!!
1543 mine_err = load_mine_data_compiled(LoadFile);
1545 if (mine_err == -1) { //error!!
1550 cfseek(LoadFile,gamedata_offset,SEEK_SET);
1551 game_err = load_game_data(LoadFile);
1553 if (game_err == -1) { //error!!
1558 //======================== CLOSE FILE =============================
1560 cfclose( LoadFile );
1562 set_ambient_sound_flags();
1565 write_game_text_file(filename);
1566 if (Errors_in_mine) {
1567 if (is_real_level(filename)) {
1568 char ErrorMessage[200];
1570 sprintf( ErrorMessage, "Warning: %i errors in %s!\n", Errors_in_mine, Level_being_loaded );
1572 gr_palette_load(gr_palette);
1573 nm_messagebox( NULL, 1, "Continue", ErrorMessage );
1576 mprintf((1, "Error: %i errors in %s.\n", Errors_in_mine, Level_being_loaded));
1581 //If an old version, ask the use if he wants to save as new version
1582 if (!no_old_level_file_error && (Function_mode == FMODE_EDITOR) && (((LEVEL_FILE_VERSION>3) && version<LEVEL_FILE_VERSION) || mine_err==1 || game_err==1)) {
1583 char ErrorMessage[200];
1585 sprintf( ErrorMessage,
1586 "You just loaded a old version\n"
1587 "level. Would you like to save\n"
1588 "it as a current version level?");
1591 gr_palette_load(gr_palette);
1592 if (nm_messagebox( NULL, 2, "Don't Save", "Save", ErrorMessage )==1)
1593 save_level(filename);
1599 if (Function_mode == FMODE_EDITOR)
1600 editor_status("Loaded NEW mine %s, \"%s\"",filename,Current_level_name);
1604 if (check_segment_connections())
1605 nm_messagebox( "ERROR", 1, "Ok",
1606 "Connectivity errors detected in\n"
1607 "mine. See monochrome screen for\n"
1608 "details, and contact Matt or Mike." );
1615 void get_level_name()
1617 //NO_UI!!! UI_WINDOW *NameWindow = NULL;
1618 //NO_UI!!! UI_GADGET_INPUTBOX *NameText;
1619 //NO_UI!!! UI_GADGET_BUTTON *QuitButton;
1621 //NO_UI!!! // Open a window with a quit button
1622 //NO_UI!!! NameWindow = ui_open_window( 20, 20, 300, 110, WIN_DIALOG );
1623 //NO_UI!!! QuitButton = ui_add_gadget_button( NameWindow, 150-24, 60, 48, 40, "Done", NULL );
1625 //NO_UI!!! ui_wprintf_at( NameWindow, 10, 12,"Please enter a name for this mine:" );
1626 //NO_UI!!! NameText = ui_add_gadget_inputbox( NameWindow, 10, 30, LEVEL_NAME_LEN, LEVEL_NAME_LEN, Current_level_name );
1628 //NO_UI!!! NameWindow->keyboard_focus_gadget = (UI_GADGET *)NameText;
1629 //NO_UI!!! QuitButton->hotkey = KEY_ENTER;
1631 //NO_UI!!! ui_gadget_calc_keys(NameWindow);
1633 //NO_UI!!! while (!QuitButton->pressed && last_keypress!=KEY_ENTER) {
1634 //NO_UI!!! ui_mega_process();
1635 //NO_UI!!! ui_window_do_gadgets(NameWindow);
1638 //NO_UI!!! strcpy( Current_level_name, NameText->text );
1640 //NO_UI!!! if ( NameWindow!=NULL ) {
1641 //NO_UI!!! ui_close_window( NameWindow );
1642 //NO_UI!!! NameWindow = NULL;
1648 m[0].type = NM_TYPE_TEXT; m[0].text = "Please enter a name for this mine:";
1649 m[1].type = NM_TYPE_INPUT; m[1].text = Current_level_name; m[1].text_len = LEVEL_NAME_LEN;
1651 newmenu_do( NULL, "Enter mine name", 2, m, NULL );
1661 // -----------------------------------------------------------------------------
1662 int compute_num_delta_light_records(void)
1667 for (i=0; i<Num_static_lights; i++) {
1668 total += Dl_indices[i].count;
1675 // -----------------------------------------------------------------------------
1677 int save_game_data(FILE * SaveFile)
1679 int player_offset, object_offset, walls_offset, doors_offset, triggers_offset, control_offset, matcen_offset; //, links_offset;
1680 int dl_indices_offset, delta_light_offset;
1681 int start_offset,end_offset;
1683 start_offset = ftell(SaveFile);
1685 //===================== SAVE FILE INFO ========================
1687 game_fileinfo.fileinfo_signature = 0x6705;
1688 game_fileinfo.fileinfo_version = GAME_VERSION;
1689 game_fileinfo.level = Current_level_num;
1690 game_fileinfo.fileinfo_sizeof = sizeof(game_fileinfo);
1691 game_fileinfo.player_offset = -1;
1692 game_fileinfo.player_sizeof = sizeof(player);
1693 game_fileinfo.object_offset = -1;
1694 game_fileinfo.object_howmany = Highest_object_index+1;
1695 game_fileinfo.object_sizeof = sizeof(object);
1696 game_fileinfo.walls_offset = -1;
1697 game_fileinfo.walls_howmany = Num_walls;
1698 game_fileinfo.walls_sizeof = sizeof(wall);
1699 game_fileinfo.doors_offset = -1;
1700 game_fileinfo.doors_howmany = Num_open_doors;
1701 game_fileinfo.doors_sizeof = sizeof(active_door);
1702 game_fileinfo.triggers_offset = -1;
1703 game_fileinfo.triggers_howmany = Num_triggers;
1704 game_fileinfo.triggers_sizeof = sizeof(trigger);
1705 game_fileinfo.control_offset = -1;
1706 game_fileinfo.control_howmany = 1;
1707 game_fileinfo.control_sizeof = sizeof(control_center_triggers);
1708 game_fileinfo.matcen_offset = -1;
1709 game_fileinfo.matcen_howmany = Num_robot_centers;
1710 game_fileinfo.matcen_sizeof = sizeof(matcen_info);
1712 game_fileinfo.dl_indices_offset = -1;
1713 game_fileinfo.dl_indices_howmany = Num_static_lights;
1714 game_fileinfo.dl_indices_sizeof = sizeof(dl_index);
1716 game_fileinfo.delta_light_offset = -1;
1717 game_fileinfo.delta_light_howmany = compute_num_delta_light_records();
1718 game_fileinfo.delta_light_sizeof = sizeof(delta_light);
1720 // Write the fileinfo
1721 fwrite( &game_fileinfo, sizeof(game_fileinfo), 1, SaveFile );
1723 // Write the mine name
1724 fprintf(SaveFile,"%s\n",Current_level_name);
1726 fwrite(&N_polygon_models,2,1,SaveFile);
1727 fwrite(Pof_names,N_polygon_models,sizeof(*Pof_names),SaveFile);
1729 //==================== SAVE PLAYER INFO ===========================
1731 player_offset = ftell(SaveFile);
1732 fwrite( &Players[Player_num], sizeof(player), 1, SaveFile );
1734 //==================== SAVE OBJECT INFO ===========================
1736 object_offset = ftell(SaveFile);
1737 //fwrite( &Objects, sizeof(object), game_fileinfo.object_howmany, SaveFile );
1740 for (i=0;i<game_fileinfo.object_howmany;i++)
1741 write_object(&Objects[i],SaveFile);
1744 //==================== SAVE WALL INFO =============================
1746 walls_offset = ftell(SaveFile);
1747 fwrite( Walls, sizeof(wall), game_fileinfo.walls_howmany, SaveFile );
1749 //==================== SAVE DOOR INFO =============================
1751 doors_offset = ftell(SaveFile);
1752 fwrite( ActiveDoors, sizeof(active_door), game_fileinfo.doors_howmany, SaveFile );
1754 //==================== SAVE TRIGGER INFO =============================
1756 triggers_offset = ftell(SaveFile);
1757 fwrite( Triggers, sizeof(trigger), game_fileinfo.triggers_howmany, SaveFile );
1759 //================ SAVE CONTROL CENTER TRIGGER INFO ===============
1761 control_offset = ftell(SaveFile);
1762 fwrite( &ControlCenterTriggers, sizeof(control_center_triggers), 1, SaveFile );
1765 //================ SAVE MATERIALIZATION CENTER TRIGGER INFO ===============
1767 matcen_offset = ftell(SaveFile);
1768 // mprintf((0, "Writing %i materialization centers\n", game_fileinfo.matcen_howmany));
1770 // for (i=0; i<game_fileinfo.matcen_howmany; i++)
1771 // mprintf((0, " %i: robot_flags = %08x\n", i, RobotCenters[i].robot_flags));
1773 fwrite( RobotCenters, sizeof(matcen_info), game_fileinfo.matcen_howmany, SaveFile );
1775 //================ SAVE DELTA LIGHT INFO ===============
1776 dl_indices_offset = ftell(SaveFile);
1777 fwrite( Dl_indices, sizeof(dl_index), game_fileinfo.dl_indices_howmany, SaveFile );
1779 delta_light_offset = ftell(SaveFile);
1780 fwrite( Delta_lights, sizeof(delta_light), game_fileinfo.delta_light_howmany, SaveFile );
1782 //============= REWRITE FILE INFO, TO SAVE OFFSETS ===============
1784 // Update the offset fields
1785 game_fileinfo.player_offset = player_offset;
1786 game_fileinfo.object_offset = object_offset;
1787 game_fileinfo.walls_offset = walls_offset;
1788 game_fileinfo.doors_offset = doors_offset;
1789 game_fileinfo.triggers_offset = triggers_offset;
1790 game_fileinfo.control_offset = control_offset;
1791 game_fileinfo.matcen_offset = matcen_offset;
1792 game_fileinfo.dl_indices_offset = dl_indices_offset;
1793 game_fileinfo.delta_light_offset = delta_light_offset;
1796 end_offset = ftell(SaveFile);
1798 // Write the fileinfo
1799 fseek( SaveFile, start_offset, SEEK_SET ); // Move to TOF
1800 fwrite( &game_fileinfo, sizeof(game_fileinfo), 1, SaveFile );
1802 // Go back to end of data
1803 fseek(SaveFile,end_offset,SEEK_SET);
1808 int save_mine_data(FILE * SaveFile);
1810 // -----------------------------------------------------------------------------
1812 int save_level_sub(char * filename, int compiled_version)
1815 char temp_filename[128];
1816 int sig = MAKE_SIG('P','L','V','L'),version=LEVEL_FILE_VERSION;
1817 int minedata_offset=0,gamedata_offset=0;
1819 if ( !compiled_version ) {
1820 write_game_text_file(filename);
1822 if (Errors_in_mine) {
1823 if (is_real_level(filename)) {
1824 char ErrorMessage[200];
1826 sprintf( ErrorMessage, "Warning: %i errors in this mine!\n", Errors_in_mine );
1828 gr_palette_load(gr_palette);
1830 if (nm_messagebox( NULL, 2, "Cancel Save", "Save", ErrorMessage )!=1) {
1836 mprintf((1, "Error: %i errors in this mine. See the 'txm' file.\n", Errors_in_mine));
1838 change_filename_extension(temp_filename,filename,".LVL");
1842 // macs are using the regular hog/rl2 files for shareware
1843 #if defined(SHAREWARE) && !defined(MACINTOSH)
1844 change_filename_extension(temp_filename,filename,".SL2");
1846 change_filename_extension(temp_filename,filename,".RL2");
1850 SaveFile = fopen( temp_filename, "wb" );
1853 char ErrorMessage[256];
1856 _splitpath( temp_filename, NULL, NULL, fname, NULL );
1858 sprintf( ErrorMessage, \
1859 "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"
1860 , temp_filename, fname );
1862 gr_palette_load(gr_palette);
1863 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
1868 if (Current_level_name[0] == 0)
1869 strcpy(Current_level_name,"Untitled");
1871 clear_transient_objects(1); //1 means clear proximity bombs
1873 compress_objects(); //after this, Highest_object_index == num objects
1875 //make sure player is in a segment
1876 if (update_object_seg(&Objects[Players[0].objnum]) == 0) {
1877 if (ConsoleObject->segnum > Highest_segment_index)
1878 ConsoleObject->segnum = 0;
1879 compute_segment_center(&ConsoleObject->pos,&(Segments[ConsoleObject->segnum]));
1886 gs_write_int(sig,SaveFile);
1887 gs_write_int(version,SaveFile);
1890 gs_write_int(minedata_offset,SaveFile);
1891 gs_write_int(gamedata_offset,SaveFile);
1893 //Now write the damn data
1895 //write the version 8 data (to make file unreadable by 1.0 & 1.1)
1896 gs_write_int(GameTime,SaveFile);
1897 gs_write_short(FrameCount,SaveFile);
1898 gs_write_byte(FrameTime,SaveFile);
1900 // Write the palette file name
1901 fprintf(SaveFile,"%s\n",Current_level_palette);
1903 gs_write_int(Base_control_center_explosion_time,SaveFile);
1904 gs_write_int(Reactor_strength,SaveFile);
1906 gs_write_int(Num_flickering_lights,SaveFile);
1907 fwrite(Flickering_lights,sizeof(*Flickering_lights),Num_flickering_lights,SaveFile);
1909 gs_write_int(Secret_return_segment, SaveFile);
1910 gs_write_int(Secret_return_orient.rvec.x, SaveFile);
1911 gs_write_int(Secret_return_orient.rvec.y, SaveFile);
1912 gs_write_int(Secret_return_orient.rvec.z, SaveFile);
1913 gs_write_int(Secret_return_orient.fvec.x, SaveFile);
1914 gs_write_int(Secret_return_orient.fvec.y, SaveFile);
1915 gs_write_int(Secret_return_orient.fvec.z, SaveFile);
1916 gs_write_int(Secret_return_orient.uvec.x, SaveFile);
1917 gs_write_int(Secret_return_orient.uvec.y, SaveFile);
1918 gs_write_int(Secret_return_orient.uvec.z, SaveFile);
1920 minedata_offset = ftell(SaveFile);
1921 if ( !compiled_version )
1922 save_mine_data(SaveFile);
1924 save_mine_data_compiled(SaveFile);
1925 gamedata_offset = ftell(SaveFile);
1926 save_game_data(SaveFile);
1928 fseek(SaveFile,sizeof(sig)+sizeof(version),SEEK_SET);
1929 gs_write_int(minedata_offset,SaveFile);
1930 gs_write_int(gamedata_offset,SaveFile);
1932 //==================== CLOSE THE FILE =============================
1935 if ( !compiled_version ) {
1936 if (Function_mode == FMODE_EDITOR)
1937 editor_status("Saved mine %s, \"%s\"",filename,Current_level_name);
1944 #if 0 //dunno - 3rd party stuff?
1945 extern void compress_uv_coordinates_all(void);
1948 int save_level(char * filename)
1952 // Save normal version...
1953 r1 = save_level_sub(filename, 0);
1955 // Save compiled version...
1956 save_level_sub(filename, 1);
1964 void dump_mine_info(void)
1966 int segnum, sidenum;
1967 fix min_u, max_u, min_v, max_v, min_l, max_l, max_sl;
1979 for (segnum=0; segnum<=Highest_segment_index; segnum++) {
1980 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
1982 side *sidep = &Segments[segnum].sides[sidenum];
1984 if (Segment2s[segnum].static_light > max_sl)
1985 max_sl = Segment2s[segnum].static_light;
1987 for (vertnum=0; vertnum<4; vertnum++) {
1988 if (sidep->uvls[vertnum].u < min_u)
1989 min_u = sidep->uvls[vertnum].u;
1990 else if (sidep->uvls[vertnum].u > max_u)
1991 max_u = sidep->uvls[vertnum].u;
1993 if (sidep->uvls[vertnum].v < min_v)
1994 min_v = sidep->uvls[vertnum].v;
1995 else if (sidep->uvls[vertnum].v > max_v)
1996 max_v = sidep->uvls[vertnum].v;
1998 if (sidep->uvls[vertnum].l < min_l)
1999 min_l = sidep->uvls[vertnum].l;
2000 else if (sidep->uvls[vertnum].l > max_l)
2001 max_l = sidep->uvls[vertnum].l;
2007 // 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)));
2008 // mprintf((0, "Static light maximum = %7.3f\n", f2fl(max_sl)));
2009 // mprintf((0, "Number of walls: %i\n", Num_walls));
2017 //read in every level in mission and save out compiled version
2018 void save_all_compiled_levels(void)
2020 do_load_save_levels(1);
2023 //read in every level in mission
2024 void load_all_levels(void)
2026 do_load_save_levels(0);
2030 void do_load_save_levels(int save)
2034 if (! SafetyCheck())
2037 no_old_level_file_error=1;
2039 for (level_num=1;level_num<=Last_level;level_num++) {
2040 load_level(Level_names[level_num-1]);
2041 load_palette(Current_level_palette,1,1); //don't change screen
2043 save_level_sub(Level_names[level_num-1],1);
2046 for (level_num=-1;level_num>=Last_secret_level;level_num--) {
2047 load_level(Secret_level_names[-level_num-1]);
2048 load_palette(Current_level_palette,1,1); //don't change screen
2050 save_level_sub(Secret_level_names[-level_num-1],1);
2053 no_old_level_file_error=0;