2006-03-20 16:43:15 +00:00
/*
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
SOFTWARE CORPORATION ( " PARALLAX " ) . PARALLAX , IN DISTRIBUTING THE CODE TO
END - USERS , AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN , GRANTS A
ROYALTY - FREE , PERPETUAL LICENSE TO SUCH END - USERS FOR USE BY SUCH END - USERS
IN USING , DISPLAYING , AND CREATING DERIVATIVE WORKS THEREOF , SO LONG AS
SUCH USE , DISPLAY OR CREATION IS FOR NON - COMMERCIAL , ROYALTY OR REVENUE
FREE PURPOSES . IN NO EVENT SHALL THE END - USER USE THE COMPUTER CODE
CONTAINED HEREIN FOR REVENUE - BEARING PURPOSES . THE END - USER UNDERSTANDS
2010-12-24 04:26:24 +00:00
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE .
2006-03-20 16:43:15 +00:00
COPYRIGHT 1993 - 1998 PARALLAX SOFTWARE CORPORATION . ALL RIGHTS RESERVED .
*/
2008-04-06 20:23:28 +00:00
2006-03-20 16:43:15 +00:00
/*
*
2008-01-23 17:25:09 +00:00
* Save game information
2006-03-20 16:43:15 +00:00
*
*/
# include <stdio.h>
# include <string.h>
2010-12-24 04:26:24 +00:00
# include "pstypes.h"
# include "strutil.h"
2008-04-06 20:23:28 +00:00
# include "console.h"
2006-03-20 16:43:15 +00:00
# include "key.h"
# include "gr.h"
# include "palette.h"
# include "newmenu.h"
# include "inferno.h"
# ifdef EDITOR
# include "editor/editor.h"
2010-12-24 04:26:24 +00:00
# include "editor/eswitch.h"
2006-03-20 16:43:15 +00:00
# endif
# include "error.h"
# include "object.h"
# include "game.h"
# include "screens.h"
# include "wall.h"
# include "gamemine.h"
# include "robot.h"
# include "bm.h"
# include "menu.h"
# include "switch.h"
# include "fuelcen.h"
2008-01-13 00:58:49 +00:00
# include "cntrlcen.h"
2006-03-20 16:43:15 +00:00
# include "powerup.h"
# include "hostage.h"
# include "weapon.h"
# include "newdemo.h"
# include "gameseq.h"
# include "automap.h"
# include "polyobj.h"
# include "text.h"
# include "gamefont.h"
# include "gamesave.h"
2008-01-19 01:13:47 +00:00
# include "textures.h"
2011-01-14 14:12:39 +00:00
# include "multi.h"
2010-12-24 04:26:24 +00:00
# include "makesig.h"
2006-03-20 16:43:15 +00:00
# ifndef NDEBUG
void dump_mine_info ( void ) ;
# endif
# ifdef EDITOR
# ifdef SHAREWARE
char * Shareware_level_names [ NUM_SHAREWARE_LEVELS ] = {
" level01.sdl " ,
" level02.sdl " ,
" level03.sdl " ,
" level04.sdl " ,
" level05.sdl " ,
" level06.sdl " ,
" level07.sdl "
} ;
# else
char * Shareware_level_names [ NUM_SHAREWARE_LEVELS ] = {
" level01.rdl " ,
" level02.rdl " ,
" level03.rdl " ,
" level04.rdl " ,
" level05.rdl " ,
" level06.rdl " ,
" level07.rdl "
} ;
# endif
char * Registered_level_names [ NUM_REGISTERED_LEVELS ] = {
" level08.rdl " ,
" level09.rdl " ,
" level10.rdl " ,
" level11.rdl " ,
" level12.rdl " ,
" level13.rdl " ,
" level14.rdl " ,
" level15.rdl " ,
" level16.rdl " ,
" level17.rdl " ,
" level18.rdl " ,
" level19.rdl " ,
" level20.rdl " ,
" level21.rdl " ,
" level22.rdl " ,
" level23.rdl " ,
" level24.rdl " ,
" level25.rdl " ,
" level26.rdl " ,
" level27.rdl " ,
" levels1.rdl " ,
" levels2.rdl " ,
" levels3.rdl "
} ;
# endif
2008-01-19 01:13:47 +00:00
char Gamesave_current_filename [ PATH_MAX ] ;
int Gamesave_current_version ;
2006-03-20 16:43:15 +00:00
# define GAME_VERSION 25
# define GAME_COMPATIBLE_VERSION 22
# define MENU_CURSOR_X_MIN MENU_X
# define MENU_CURSOR_X_MAX MENU_X+6
# define HOSTAGE_DATA_VERSION 0
2010-12-24 04:26:24 +00:00
# ifdef EDITOR
2006-03-20 16:43:15 +00:00
struct {
2010-12-24 04:26:24 +00:00
ushort fileinfo_signature ;
ushort fileinfo_version ;
int fileinfo_sizeof ;
} game_top_fileinfo ; // Should be same as first two fields below...
2006-03-20 16:43:15 +00:00
struct {
2010-12-24 04:26:24 +00:00
ushort fileinfo_signature ;
ushort fileinfo_version ;
int fileinfo_sizeof ;
char mine_filename [ 15 ] ;
int level ;
int player_offset ; // Player info
int player_sizeof ;
int object_offset ; // Object info
int object_howmany ;
int object_sizeof ;
int walls_offset ;
int walls_howmany ;
int walls_sizeof ;
int doors_offset ;
int doors_howmany ;
int doors_sizeof ;
int triggers_offset ;
int triggers_howmany ;
int triggers_sizeof ;
int links_offset ;
int links_howmany ;
int links_sizeof ;
int control_offset ;
int control_howmany ;
int control_sizeof ;
int matcen_offset ;
int matcen_howmany ;
int matcen_sizeof ;
} game_fileinfo ;
# endif // EDITOR
// LINT: adding function prototypes
2011-06-01 07:59:51 +00:00
void read_object ( object * obj , PHYSFS_file * f , int version ) ;
2010-12-24 04:26:24 +00:00
# ifdef EDITOR
void write_object ( object * obj , PHYSFS_file * f ) ;
void do_load_save_levels ( int save ) ;
# endif
# ifndef NDEBUG
void dump_mine_info ( void ) ;
# endif
extern char MaxPowerupsAllowed [ MAX_POWERUP_TYPES ] ;
extern char PowerupsInMine [ MAX_POWERUP_TYPES ] ;
2006-03-20 16:43:15 +00:00
# ifdef EDITOR
extern char mine_filename [ ] ;
2010-12-24 04:26:24 +00:00
extern int save_mine_data_compiled ( PHYSFS_file * SaveFile ) ;
2006-03-20 16:43:15 +00:00
//--unused-- #else
//--unused-- char mine_filename[128];
# endif
int Gamesave_num_org_robots = 0 ;
//--unused-- grs_bitmap * Gamesave_saved_bitmap = NULL;
# ifdef EDITOR
2010-12-24 04:26:24 +00:00
// Return true if this level has a name of the form "level??"
// Note that a pathspec can appear at the beginning of the filename.
2006-03-20 16:43:15 +00:00
int is_real_level ( char * filename )
{
2010-12-24 04:26:24 +00:00
int len = strlen ( filename ) ;
2006-03-20 16:43:15 +00:00
if ( len < 6 )
return 0 ;
2008-04-24 14:27:54 +00:00
return ! strnicmp ( & filename [ len - 11 ] , " level " , 5 ) ;
2006-03-20 16:43:15 +00:00
}
# endif
//--unused-- vms_angvec zero_angles={0,0,0};
# define vm_angvec_zero(v) do {(v)->p=(v)->b=(v)->h=0;} while (0)
int Gamesave_num_players = 0 ;
int N_save_pof_names = 25 ;
2008-01-19 01:13:47 +00:00
# define MAX_POLYGON_MODELS_NEW 167
2010-12-24 04:26:24 +00:00
char Save_pof_names [ MAX_POLYGON_MODELS_NEW ] [ FILENAME_LEN ] ;
2008-01-19 01:13:47 +00:00
static int convert_vclip ( int vc ) {
if ( vc < 0 )
return vc ;
if ( ( vc < VCLIP_MAXNUM ) & & ( Vclip [ vc ] . num_frames > = 0 ) )
return vc ;
return 0 ;
}
static int convert_wclip ( int wc ) {
return ( wc < Num_wall_anims ) ? wc : wc % Num_wall_anims ;
}
int convert_tmap ( int tmap )
{
return ( tmap > = NumTextures ) ? tmap % NumTextures : tmap ;
}
static int convert_polymod ( int polymod ) {
return ( polymod > = N_polygon_models ) ? polymod % N_polygon_models : polymod ;
}
2006-03-20 16:43:15 +00:00
void check_and_fix_matrix ( vms_matrix * m ) ;
void verify_object ( object * obj ) {
obj - > lifeleft = IMMORTAL_TIME ; //all loaded object are immortal, for now
if ( obj - > type = = OBJ_ROBOT ) {
Gamesave_num_org_robots + + ;
// Make sure valid id...
if ( obj - > id > = N_robot_types )
obj - > id = obj - > id % N_robot_types ;
2010-12-24 04:26:24 +00:00
// Make sure model number & size are correct...
2006-03-20 16:43:15 +00:00
if ( obj - > render_type = = RT_POLYOBJ ) {
obj - > rtype . pobj_info . model_num = Robot_info [ obj - > id ] . model_num ;
obj - > size = Polygon_models [ obj - > rtype . pobj_info . model_num ] . rad ;
//@@if (obj->control_type==CT_AI && Robot_info[obj->id].attack_type)
//@@ obj->size = obj->size*3/4;
}
if ( obj - > movement_type = = MT_PHYSICS ) {
obj - > mtype . phys_info . mass = Robot_info [ obj - > id ] . mass ;
obj - > mtype . phys_info . drag = Robot_info [ obj - > id ] . drag ;
}
}
else { //Robots taken care of above
if ( obj - > render_type = = RT_POLYOBJ ) {
int i ;
char * name = Save_pof_names [ obj - > rtype . pobj_info . model_num ] ;
for ( i = 0 ; i < N_polygon_models ; i + + )
2008-04-24 14:27:54 +00:00
if ( ! stricmp ( Pof_names [ i ] , name ) ) { //found it!
2006-03-20 16:43:15 +00:00
obj - > rtype . pobj_info . model_num = i ;
break ;
}
}
}
if ( obj - > type = = OBJ_POWERUP ) {
if ( obj - > id > = N_powerup_types ) {
obj - > id = 0 ;
Assert ( obj - > render_type ! = RT_POLYOBJ ) ;
}
obj - > control_type = CT_POWERUP ;
obj - > size = Powerup_info [ obj - > id ] . size ;
2011-01-14 13:29:36 +00:00
if ( Game_mode & GM_NETWORK )
{
if ( multi_powerup_is_4pack ( obj - > id ) )
{
PowerupsInMine [ obj - > id - 1 ] + = 4 ;
MaxPowerupsAllowed [ obj - > id - 1 ] + = 4 ;
}
else
{
PowerupsInMine [ obj - > id ] + + ;
MaxPowerupsAllowed [ obj - > id ] + + ;
}
}
2006-03-20 16:43:15 +00:00
}
if ( obj - > type = = OBJ_WEAPON ) {
if ( obj - > id > = N_weapon_types ) {
obj - > id = 0 ;
Assert ( obj - > render_type ! = RT_POLYOBJ ) ;
}
}
2010-12-24 04:26:24 +00:00
if ( obj - > type = = OBJ_CNTRLCEN ) {
2006-03-20 16:43:15 +00:00
int i ;
obj - > render_type = RT_POLYOBJ ;
obj - > control_type = CT_CNTRLCEN ;
// Make model number is correct...
for ( i = 0 ; i < Num_total_object_types ; i + + )
if ( ObjType [ i ] = = OL_CONTROL_CENTER ) {
obj - > rtype . pobj_info . model_num = ObjId [ i ] ;
obj - > shields = ObjStrength [ i ] ;
break ;
}
}
if ( obj - > type = = OBJ_PLAYER ) {
//int i;
//Assert(obj == Player);
if ( obj = = ConsoleObject )
init_player_object ( ) ;
else
if ( obj - > render_type = = RT_POLYOBJ ) //recover from Matt's pof file matchup bug
obj - > rtype . pobj_info . model_num = Player_ship - > model_num ;
//Make sure orient matrix is orthogonal
check_and_fix_matrix ( & obj - > orient ) ;
obj - > id = Gamesave_num_players + + ;
}
if ( obj - > type = = OBJ_HOSTAGE ) {
if ( obj - > id > N_hostage_types )
obj - > id = 0 ;
obj - > render_type = RT_HOSTAGE ;
obj - > control_type = CT_POWERUP ;
}
}
2011-06-01 07:59:51 +00:00
//static gs_skip(int len,PHYSFS_file *file)
2006-03-20 16:43:15 +00:00
//{
//
2011-06-01 07:59:51 +00:00
// PHYSFSX_fseek(file,len,SEEK_CUR);
2006-03-20 16:43:15 +00:00
//}
//reads one object of the given version from the given file
2011-06-01 07:59:51 +00:00
void read_object ( object * obj , PHYSFS_file * f , int version )
2006-03-20 16:43:15 +00:00
{
2010-12-24 04:26:24 +00:00
2011-06-01 07:59:51 +00:00
obj - > type = PHYSFSX_readByte ( f ) ;
obj - > id = PHYSFSX_readByte ( f ) ;
2006-03-20 16:43:15 +00:00
2008-01-19 01:13:47 +00:00
if ( obj - > type = = OBJ_ROBOT & & obj - > id > 23 ) {
obj - > id = obj - > id % 24 ;
}
2011-06-01 07:59:51 +00:00
obj - > control_type = PHYSFSX_readByte ( f ) ;
obj - > movement_type = PHYSFSX_readByte ( f ) ;
obj - > render_type = PHYSFSX_readByte ( f ) ;
obj - > flags = PHYSFSX_readByte ( f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
obj - > segnum = PHYSFSX_readShort ( f ) ;
2010-12-24 04:26:24 +00:00
obj - > attached_obj = - 1 ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
PHYSFSX_readVector ( & obj - > pos , f ) ;
PHYSFSX_readMatrix ( & obj - > orient , f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
obj - > size = PHYSFSX_readFix ( f ) ;
obj - > shields = PHYSFSX_readFix ( f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
PHYSFSX_readVector ( & obj - > last_pos , f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
obj - > contains_type = PHYSFSX_readByte ( f ) ;
obj - > contains_id = PHYSFSX_readByte ( f ) ;
obj - > contains_count = PHYSFSX_readByte ( f ) ;
2006-03-20 16:43:15 +00:00
switch ( obj - > movement_type ) {
case MT_PHYSICS :
2011-06-01 07:59:51 +00:00
PHYSFSX_readVector ( & obj - > mtype . phys_info . velocity , f ) ;
PHYSFSX_readVector ( & obj - > mtype . phys_info . thrust , f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
obj - > mtype . phys_info . mass = PHYSFSX_readFix ( f ) ;
obj - > mtype . phys_info . drag = PHYSFSX_readFix ( f ) ;
obj - > mtype . phys_info . brakes = PHYSFSX_readFix ( f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
PHYSFSX_readVector ( & obj - > mtype . phys_info . rotvel , f ) ;
PHYSFSX_readVector ( & obj - > mtype . phys_info . rotthrust , f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
obj - > mtype . phys_info . turnroll = PHYSFSX_readFixAng ( f ) ;
obj - > mtype . phys_info . flags = PHYSFSX_readShort ( f ) ;
2006-03-20 16:43:15 +00:00
break ;
case MT_SPINNING :
2011-06-01 07:59:51 +00:00
PHYSFSX_readVector ( & obj - > mtype . spin_rate , f ) ;
2006-03-20 16:43:15 +00:00
break ;
case MT_NONE :
break ;
default :
Int3 ( ) ;
}
switch ( obj - > control_type ) {
case CT_AI : {
int i ;
2011-06-01 07:59:51 +00:00
obj - > ctype . ai_info . behavior = PHYSFSX_readByte ( f ) ;
2006-03-20 16:43:15 +00:00
for ( i = 0 ; i < MAX_AI_FLAGS ; i + + )
2011-06-01 07:59:51 +00:00
obj - > ctype . ai_info . flags [ i ] = PHYSFSX_readByte ( f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
obj - > ctype . ai_info . hide_segment = PHYSFSX_readShort ( f ) ;
obj - > ctype . ai_info . hide_index = PHYSFSX_readShort ( f ) ;
obj - > ctype . ai_info . path_length = PHYSFSX_readShort ( f ) ;
obj - > ctype . ai_info . cur_path_index = PHYSFSX_readShort ( f ) ;
2006-03-20 16:43:15 +00:00
2008-01-19 01:13:47 +00:00
if ( version < = 25 ) {
2011-06-01 07:59:51 +00:00
obj - > ctype . ai_info . follow_path_start_seg = PHYSFSX_readShort ( f ) ;
obj - > ctype . ai_info . follow_path_end_seg = PHYSFSX_readShort ( f ) ;
2008-01-19 01:13:47 +00:00
}
2010-12-24 04:26:24 +00:00
2006-03-20 16:43:15 +00:00
break ;
}
case CT_EXPLOSION :
2011-06-01 07:59:51 +00:00
obj - > ctype . expl_info . spawn_time = PHYSFSX_readFix ( f ) ;
obj - > ctype . expl_info . delete_time = PHYSFSX_readFix ( f ) ;
obj - > ctype . expl_info . delete_objnum = PHYSFSX_readShort ( f ) ;
2006-03-20 16:43:15 +00:00
obj - > ctype . expl_info . next_attach = obj - > ctype . expl_info . prev_attach = obj - > ctype . expl_info . attach_parent = - 1 ;
break ;
case CT_WEAPON :
//do I really need to read these? Are they even saved to disk?
2011-06-01 07:59:51 +00:00
obj - > ctype . laser_info . parent_type = PHYSFSX_readShort ( f ) ;
obj - > ctype . laser_info . parent_num = PHYSFSX_readShort ( f ) ;
obj - > ctype . laser_info . parent_signature = PHYSFSX_readInt ( f ) ;
2006-03-20 16:43:15 +00:00
break ;
case CT_LIGHT :
2011-06-01 07:59:51 +00:00
obj - > ctype . light_info . intensity = PHYSFSX_readFix ( f ) ;
2006-03-20 16:43:15 +00:00
break ;
case CT_POWERUP :
if ( version > = 25 )
2011-06-01 07:59:51 +00:00
obj - > ctype . powerup_info . count = PHYSFSX_readInt ( f ) ;
2006-03-20 16:43:15 +00:00
else
obj - > ctype . powerup_info . count = 1 ;
if ( obj - > id = = POW_VULCAN_WEAPON )
obj - > ctype . powerup_info . count = VULCAN_WEAPON_AMMO_AMOUNT ;
break ;
case CT_NONE :
case CT_FLYING :
case CT_DEBRIS :
break ;
case CT_SLEW : //the player is generally saved as slew
break ;
case CT_CNTRLCEN :
break ;
case CT_MORPH :
case CT_FLYTHROUGH :
case CT_REPAIRCEN :
default :
Int3 ( ) ;
}
switch ( obj - > render_type ) {
case RT_NONE :
break ;
case RT_MORPH :
case RT_POLYOBJ : {
int i , tmo ;
2011-06-01 07:59:51 +00:00
obj - > rtype . pobj_info . model_num = convert_polymod ( PHYSFSX_readInt ( f ) ) ;
2006-03-20 16:43:15 +00:00
for ( i = 0 ; i < MAX_SUBMODELS ; i + + )
2011-06-01 07:59:51 +00:00
PHYSFSX_readAngleVec ( & obj - > rtype . pobj_info . anim_angles [ i ] , f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
obj - > rtype . pobj_info . subobj_flags = PHYSFSX_readInt ( f ) ;
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
tmo = PHYSFSX_readInt ( f ) ;
2006-03-20 16:43:15 +00:00
# ifndef EDITOR
2008-01-19 01:13:47 +00:00
obj - > rtype . pobj_info . tmap_override = convert_tmap ( tmo ) ;
2006-03-20 16:43:15 +00:00
# else
if ( tmo = = - 1 )
obj - > rtype . pobj_info . tmap_override = - 1 ;
else {
int xlated_tmo = tmap_xlate_table [ tmo ] ;
if ( xlated_tmo < 0 ) {
Int3 ( ) ;
xlated_tmo = 0 ;
}
obj - > rtype . pobj_info . tmap_override = xlated_tmo ;
}
# endif
obj - > rtype . pobj_info . alt_textures = 0 ;
break ;
}
case RT_WEAPON_VCLIP :
case RT_HOSTAGE :
case RT_POWERUP :
case RT_FIREBALL :
2011-06-01 07:59:51 +00:00
obj - > rtype . vclip_info . vclip_num = convert_vclip ( PHYSFSX_readInt ( f ) ) ;
obj - > rtype . vclip_info . frametime = PHYSFSX_readFix ( f ) ;
obj - > rtype . vclip_info . framenum = PHYSFSX_readByte ( f ) ;
2006-03-20 16:43:15 +00:00
break ;
case RT_LASER :
break ;
default :
Int3 ( ) ;
}
}
# ifdef EDITOR
//writes one object to the given file
2008-01-23 17:25:09 +00:00
void write_object ( object * obj , PHYSFS_file * f )
2006-03-20 16:43:15 +00:00
{
2008-01-23 17:25:09 +00:00
PHYSFSX_writeU8 ( f , obj - > type ) ;
PHYSFSX_writeU8 ( f , obj - > id ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFSX_writeU8 ( f , obj - > control_type ) ;
PHYSFSX_writeU8 ( f , obj - > movement_type ) ;
PHYSFSX_writeU8 ( f , obj - > render_type ) ;
PHYSFSX_writeU8 ( f , obj - > flags ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE16 ( f , obj - > segnum ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFSX_writeVector ( f , & obj - > pos ) ;
PHYSFSX_writeMatrix ( f , & obj - > orient ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFSX_writeFix ( f , obj - > size ) ;
PHYSFSX_writeFix ( f , obj - > shields ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFSX_writeVector ( f , & obj - > last_pos ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFSX_writeU8 ( f , obj - > contains_type ) ;
PHYSFSX_writeU8 ( f , obj - > contains_id ) ;
PHYSFSX_writeU8 ( f , obj - > contains_count ) ;
2006-03-20 16:43:15 +00:00
switch ( obj - > movement_type ) {
case MT_PHYSICS :
2008-01-23 17:25:09 +00:00
PHYSFSX_writeVector ( f , & obj - > mtype . phys_info . velocity ) ;
PHYSFSX_writeVector ( f , & obj - > mtype . phys_info . thrust ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFSX_writeFix ( f , obj - > mtype . phys_info . mass ) ;
PHYSFSX_writeFix ( f , obj - > mtype . phys_info . drag ) ;
PHYSFSX_writeFix ( f , obj - > mtype . phys_info . brakes ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFSX_writeVector ( f , & obj - > mtype . phys_info . rotvel ) ;
PHYSFSX_writeVector ( f , & obj - > mtype . phys_info . rotthrust ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFSX_writeFixAng ( f , obj - > mtype . phys_info . turnroll ) ;
PHYSFS_writeSLE16 ( f , obj - > mtype . phys_info . flags ) ;
2006-03-20 16:43:15 +00:00
break ;
case MT_SPINNING :
2008-01-23 17:25:09 +00:00
PHYSFSX_writeVector ( f , & obj - > mtype . spin_rate ) ;
2006-03-20 16:43:15 +00:00
break ;
case MT_NONE :
break ;
default :
Int3 ( ) ;
}
switch ( obj - > control_type ) {
case CT_AI : {
int i ;
2008-01-23 17:25:09 +00:00
PHYSFSX_writeU8 ( f , obj - > ctype . ai_info . behavior ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
for ( i = 0 ; i < MAX_AI_FLAGS ; i + + )
PHYSFSX_writeU8 ( f , obj - > ctype . ai_info . flags [ i ] ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE16 ( f , obj - > ctype . ai_info . hide_segment ) ;
PHYSFS_writeSLE16 ( f , obj - > ctype . ai_info . hide_index ) ;
PHYSFS_writeSLE16 ( f , obj - > ctype . ai_info . path_length ) ;
PHYSFS_writeSLE16 ( f , obj - > ctype . ai_info . cur_path_index ) ;
PHYSFS_writeSLE16 ( f , obj - > ctype . ai_info . follow_path_start_seg ) ;
PHYSFS_writeSLE16 ( f , obj - > ctype . ai_info . follow_path_end_seg ) ;
2006-03-20 16:43:15 +00:00
break ;
}
case CT_EXPLOSION :
2008-01-23 17:25:09 +00:00
PHYSFSX_writeFix ( f , obj - > ctype . expl_info . spawn_time ) ;
PHYSFSX_writeFix ( f , obj - > ctype . expl_info . delete_time ) ;
PHYSFS_writeSLE16 ( f , obj - > ctype . expl_info . delete_objnum ) ;
2006-03-20 16:43:15 +00:00
break ;
case CT_WEAPON :
//do I really need to write these objects?
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE16 ( f , obj - > ctype . laser_info . parent_type ) ;
PHYSFS_writeSLE16 ( f , obj - > ctype . laser_info . parent_num ) ;
PHYSFS_writeSLE32 ( f , obj - > ctype . laser_info . parent_signature ) ;
2006-03-20 16:43:15 +00:00
break ;
case CT_LIGHT :
2008-01-23 17:25:09 +00:00
PHYSFSX_writeFix ( f , obj - > ctype . light_info . intensity ) ;
2006-03-20 16:43:15 +00:00
break ;
case CT_POWERUP :
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE32 ( f , obj - > ctype . powerup_info . count ) ;
2006-03-20 16:43:15 +00:00
break ;
case CT_NONE :
case CT_FLYING :
case CT_DEBRIS :
break ;
case CT_SLEW : //the player is generally saved as slew
break ;
case CT_CNTRLCEN :
break ; //control center object.
case CT_MORPH :
case CT_REPAIRCEN :
case CT_FLYTHROUGH :
default :
Int3 ( ) ;
}
switch ( obj - > render_type ) {
case RT_NONE :
break ;
case RT_MORPH :
case RT_POLYOBJ : {
int i ;
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE32 ( f , obj - > rtype . pobj_info . model_num ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
for ( i = 0 ; i < MAX_SUBMODELS ; i + + )
PHYSFSX_writeAngleVec ( f , & obj - > rtype . pobj_info . anim_angles [ i ] ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE32 ( f , obj - > rtype . pobj_info . subobj_flags ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE32 ( f , obj - > rtype . pobj_info . tmap_override ) ;
2006-03-20 16:43:15 +00:00
break ;
}
case RT_WEAPON_VCLIP :
case RT_HOSTAGE :
case RT_POWERUP :
case RT_FIREBALL :
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE32 ( f , obj - > rtype . vclip_info . vclip_num ) ;
PHYSFSX_writeFix ( f , obj - > rtype . vclip_info . frametime ) ;
PHYSFSX_writeU8 ( f , obj - > rtype . vclip_info . framenum ) ;
2006-03-20 16:43:15 +00:00
break ;
case RT_LASER :
break ;
default :
Int3 ( ) ;
}
}
# endif
2010-12-24 04:26:24 +00:00
// --------------------------------------------------------------------
2006-03-20 16:43:15 +00:00
// Load game
// Loads all the relevant data for a level.
// If level != -1, it loads the filename with extension changed to .min
// Otherwise it loads the appropriate level mine.
// returns 0=everything ok, 1=old version, -1=error
2011-06-01 07:59:51 +00:00
int load_game_data ( PHYSFS_file * LoadFile )
2006-03-20 16:43:15 +00:00
{
int i , j ;
2010-12-24 04:26:24 +00:00
short game_top_fileinfo_version ;
int object_offset ;
int gs_num_objects ;
int trig_size ;
2006-03-20 16:43:15 +00:00
//===================== READ FILE INFO ========================
2010-12-24 04:26:24 +00:00
#if 0
2011-06-01 07:59:51 +00:00
PHYSFS_read ( LoadFile , & game_top_fileinfo , sizeof ( game_top_fileinfo ) , 1 ) ;
2010-12-24 04:26:24 +00:00
# endif
2006-03-20 16:43:15 +00:00
// Check signature
2011-06-01 07:59:51 +00:00
if ( PHYSFSX_readShort ( LoadFile ) ! = 0x6705 )
2006-03-20 16:43:15 +00:00
return - 1 ;
2010-12-24 04:26:24 +00:00
// Read and check version number
2011-06-01 07:59:51 +00:00
game_top_fileinfo_version = PHYSFSX_readShort ( LoadFile ) ;
2010-12-24 04:26:24 +00:00
if ( game_top_fileinfo_version < GAME_COMPATIBLE_VERSION )
2006-03-20 16:43:15 +00:00
return - 1 ;
2010-12-24 04:26:24 +00:00
// We skip some parts of the former game_top_fileinfo
2011-06-01 07:59:51 +00:00
PHYSFSX_fseek ( LoadFile , 31 , SEEK_CUR ) ;
2010-12-24 04:26:24 +00:00
2011-06-01 07:59:51 +00:00
object_offset = PHYSFSX_readInt ( LoadFile ) ;
gs_num_objects = PHYSFSX_readInt ( LoadFile ) ;
PHYSFSX_fseek ( LoadFile , 8 , SEEK_CUR ) ;
2010-12-24 04:26:24 +00:00
2011-06-01 07:59:51 +00:00
Num_walls = PHYSFSX_readInt ( LoadFile ) ;
PHYSFSX_fseek ( LoadFile , 20 , SEEK_CUR ) ;
2010-12-24 04:26:24 +00:00
2011-06-01 07:59:51 +00:00
Num_triggers = PHYSFSX_readInt ( LoadFile ) ;
PHYSFSX_fseek ( LoadFile , 24 , SEEK_CUR ) ;
2010-12-24 04:26:24 +00:00
2011-06-01 07:59:51 +00:00
trig_size = PHYSFSX_readInt ( LoadFile ) ;
2010-12-24 04:26:24 +00:00
Assert ( trig_size = = sizeof ( ControlCenterTriggers ) ) ;
2011-06-01 07:59:51 +00:00
PHYSFSX_fseek ( LoadFile , 4 , SEEK_CUR ) ;
2010-12-24 04:26:24 +00:00
2011-06-01 07:59:51 +00:00
Num_robot_centers = PHYSFSX_readInt ( LoadFile ) ;
PHYSFSX_fseek ( LoadFile , 4 , SEEK_CUR ) ;
2010-12-24 04:26:24 +00:00
if ( game_top_fileinfo_version > = 31 ) //load mine filename
2008-01-19 01:13:47 +00:00
// read newline-terminated string, not sure what version this changed.
2011-06-01 07:59:51 +00:00
PHYSFSX_fgets ( Current_level_name , sizeof ( Current_level_name ) , LoadFile ) ;
2010-12-24 04:26:24 +00:00
else if ( game_top_fileinfo_version > = 14 ) { //load mine filename
// read null-terminated string
2006-03-20 16:43:15 +00:00
char * p = Current_level_name ;
2011-06-01 07:59:51 +00:00
//must do read one char at a time, since no PHYSFSX_fgets()
do * p = PHYSFSX_fgetc ( LoadFile ) ; while ( * p + + ! = 0 ) ;
2006-03-20 16:43:15 +00:00
}
else
Current_level_name [ 0 ] = 0 ;
2010-12-24 04:26:24 +00:00
if ( game_top_fileinfo_version > = 19 ) { //load pof names
2011-06-01 07:59:51 +00:00
N_save_pof_names = PHYSFSX_readShort ( LoadFile ) ;
2008-01-19 01:13:47 +00:00
if ( N_save_pof_names ! = 0x614d & & N_save_pof_names ! = 0x5547 ) { // "Ma"de w/DMB beta/"GU"ILE
Assert ( N_save_pof_names < MAX_POLYGON_MODELS ) ;
2011-06-01 07:59:51 +00:00
PHYSFS_read ( LoadFile , Save_pof_names , N_save_pof_names , FILENAME_LEN ) ;
2008-01-19 01:13:47 +00:00
}
2006-03-20 16:43:15 +00:00
}
//===================== READ PLAYER INFO ==========================
2010-01-28 15:26:27 +00:00
2006-03-20 16:43:15 +00:00
//===================== READ OBJECT INFO ==========================
Gamesave_num_org_robots = 0 ;
Gamesave_num_players = 0 ;
2010-12-24 04:26:24 +00:00
if ( object_offset > - 1 ) {
2011-06-01 07:59:51 +00:00
if ( PHYSFSX_fseek ( LoadFile , object_offset , SEEK_SET ) )
2006-03-20 16:43:15 +00:00
Error ( " Error seeking to object_offset in gamesave.c " ) ;
2010-12-24 04:26:24 +00:00
for ( i = 0 ; i < gs_num_objects ; i + + ) {
read_object ( & Objects [ i ] , LoadFile , game_top_fileinfo_version ) ;
2006-03-20 16:43:15 +00:00
2010-01-28 15:26:27 +00:00
Objects [ i ] . signature = obj_get_signature ( ) ;
2006-03-20 16:43:15 +00:00
verify_object ( & Objects [ i ] ) ;
}
}
//===================== READ WALL INFO ============================
2010-12-24 04:26:24 +00:00
for ( i = 0 ; i < Num_walls ; i + + ) {
if ( game_top_fileinfo_version > = 20 )
wall_read ( & Walls [ i ] , LoadFile ) ; // v20 walls and up.
else if ( game_top_fileinfo_version > = 17 ) {
v19_wall w ;
v19_wall_read ( & w , LoadFile ) ;
Walls [ i ] . segnum = w . segnum ;
Walls [ i ] . sidenum = w . sidenum ;
Walls [ i ] . linked_wall = w . linked_wall ;
Walls [ i ] . type = w . type ;
Walls [ i ] . flags = w . flags ;
Walls [ i ] . hps = w . hps ;
Walls [ i ] . trigger = w . trigger ;
Walls [ i ] . clip_num = convert_wclip ( w . clip_num ) ;
Walls [ i ] . keys = w . keys ;
Walls [ i ] . state = WALL_DOOR_CLOSED ;
} else {
v16_wall w ;
v16_wall_read ( & w , LoadFile ) ;
Walls [ i ] . segnum = Walls [ i ] . sidenum = Walls [ i ] . linked_wall = - 1 ;
Walls [ i ] . type = w . type ;
Walls [ i ] . flags = w . flags ;
Walls [ i ] . hps = w . hps ;
Walls [ i ] . trigger = w . trigger ;
Walls [ i ] . clip_num = convert_wclip ( w . clip_num ) ;
Walls [ i ] . keys = w . keys ;
2006-03-20 16:43:15 +00:00
}
}
2010-12-24 04:26:24 +00:00
#if 0
2006-03-20 16:43:15 +00:00
//===================== READ DOOR INFO ============================
if ( game_fileinfo . doors_offset > - 1 )
{
2011-06-01 07:59:51 +00:00
if ( ! PHYSFSX_fseek ( LoadFile , game_fileinfo . doors_offset , SEEK_SET ) ) {
2006-03-20 16:43:15 +00:00
for ( i = 0 ; i < game_fileinfo . doors_howmany ; i + + ) {
2010-12-24 04:26:24 +00:00
if ( game_top_fileinfo_version > = 20 )
active_door_read ( & ActiveDoors [ i ] , LoadFile ) ; // version 20 and up
2006-03-20 16:43:15 +00:00
else {
v19_door d ;
int p ;
2008-01-13 00:58:49 +00:00
v19_door_read ( & d , LoadFile ) ;
2006-03-20 16:43:15 +00:00
ActiveDoors [ i ] . n_parts = d . n_parts ;
for ( p = 0 ; p < d . n_parts ; p + + ) {
int cseg , cside ;
cseg = Segments [ d . seg [ p ] ] . children [ d . side [ p ] ] ;
cside = find_connect_side ( & Segments [ d . seg [ p ] ] , & Segments [ cseg ] ) ;
ActiveDoors [ i ] . front_wallnum [ p ] = Segments [ d . seg [ p ] ] . sides [ d . side [ p ] ] . wall_num ;
ActiveDoors [ i ] . back_wallnum [ p ] = Segments [ cseg ] . sides [ cside ] . wall_num ;
}
}
}
}
}
2010-12-24 04:26:24 +00:00
# endif // 0
2006-03-20 16:43:15 +00:00
//==================== READ TRIGGER INFO ==========================
2010-12-24 04:26:24 +00:00
for ( i = 0 ; i < Num_triggers ; i + + )
{
if ( game_top_fileinfo_version < = 25 )
trigger_read ( & Triggers [ i ] , LoadFile ) ;
else {
int type ;
2011-06-01 07:59:51 +00:00
switch ( ( type = PHYSFSX_readByte ( LoadFile ) ) )
2010-12-24 04:26:24 +00:00
{
case 0 : // door
Triggers [ i ] . type = 0 ;
Triggers [ i ] . flags = TRIGGER_CONTROL_DOORS ;
break ;
case 2 : // matcen
Triggers [ i ] . type = 0 ;
Triggers [ i ] . flags = TRIGGER_MATCEN ;
break ;
case 3 : // exit
Triggers [ i ] . type = 0 ;
Triggers [ i ] . flags = TRIGGER_EXIT ;
break ;
case 4 : // secret exit
Triggers [ i ] . type = 0 ;
Triggers [ i ] . flags = TRIGGER_SECRET_EXIT ;
break ;
case 5 : // illusion off
Triggers [ i ] . type = 0 ;
Triggers [ i ] . flags = TRIGGER_ILLUSION_OFF ;
break ;
case 6 : // illusion on
Triggers [ i ] . type = 0 ;
Triggers [ i ] . flags = TRIGGER_ILLUSION_ON ;
break ;
default :
con_printf ( CON_URGENT , " Warning: unsupported trigger type %d (%d) \n " , type , i ) ;
2006-03-20 16:43:15 +00:00
}
2011-06-01 07:59:51 +00:00
if ( PHYSFSX_readByte ( LoadFile ) & 2 ) // one shot
2010-12-24 04:26:24 +00:00
Triggers [ i ] . flags | = TRIGGER_ONE_SHOT ;
2011-06-01 07:59:51 +00:00
Triggers [ i ] . num_links = PHYSFSX_readShort ( LoadFile ) ;
Triggers [ i ] . value = PHYSFSX_readInt ( LoadFile ) ;
Triggers [ i ] . time = PHYSFSX_readInt ( LoadFile ) ;
2010-12-24 04:26:24 +00:00
for ( j = 0 ; j < MAX_WALLS_PER_LINK ; j + + )
2011-06-01 07:59:51 +00:00
Triggers [ i ] . seg [ j ] = PHYSFSX_readShort ( LoadFile ) ;
2010-12-24 04:26:24 +00:00
for ( j = 0 ; j < MAX_WALLS_PER_LINK ; j + + )
2011-06-01 07:59:51 +00:00
Triggers [ i ] . side [ j ] = PHYSFSX_readShort ( LoadFile ) ;
2006-03-20 16:43:15 +00:00
}
}
//================ READ CONTROL CENTER TRIGGER INFO ===============
2010-12-24 04:26:24 +00:00
2008-04-21 18:39:49 +00:00
control_center_triggers_read_n ( & ControlCenterTriggers , 1 , LoadFile ) ;
2006-03-20 16:43:15 +00:00
//================ READ MATERIALOGRIFIZATIONATORS INFO ===============
2010-12-24 04:26:24 +00:00
for ( i = 0 ; i < Num_robot_centers ; i + + ) {
matcen_info_read ( & RobotCenters [ i ] , LoadFile , game_top_fileinfo_version ) ;
// Set links in RobotCenters to Station array
for ( j = 0 ; j < = Highest_segment_index ; j + + )
if ( Segments [ j ] . special = = SEGMENT_IS_ROBOTMAKER )
if ( Segments [ j ] . matcen_num = = i )
RobotCenters [ i ] . fuelcen_num = Segments [ j ] . value ;
2006-03-20 16:43:15 +00:00
}
//========================= UPDATE VARIABLES ======================
2010-12-24 04:26:24 +00:00
reset_objects ( gs_num_objects ) ;
2006-03-20 16:43:15 +00:00
for ( i = 0 ; i < MAX_OBJECTS ; i + + ) {
Objects [ i ] . next = Objects [ i ] . prev = - 1 ;
if ( Objects [ i ] . type ! = OBJ_NONE ) {
int objsegnum = Objects [ i ] . segnum ;
if ( objsegnum > Highest_segment_index ) //bogus object
Objects [ i ] . type = OBJ_NONE ;
else {
Objects [ i ] . segnum = - 1 ; //avoid Assert()
obj_link ( i , objsegnum ) ;
}
}
}
clear_transient_objects ( 1 ) ; //1 means clear proximity bombs
// Make sure non-transparent doors are set correctly.
for ( i = 0 ; i < Num_segments ; i + + )
for ( j = 0 ; j < MAX_SIDES_PER_SEGMENT ; j + + ) {
side * sidep = & Segments [ i ] . sides [ j ] ;
if ( ( sidep - > wall_num ! = - 1 ) & & ( Walls [ sidep - > wall_num ] . clip_num ! = - 1 ) ) {
if ( WallAnims [ Walls [ sidep - > wall_num ] . clip_num ] . flags & WCF_TMAP1 ) {
sidep - > tmap_num = WallAnims [ Walls [ sidep - > wall_num ] . clip_num ] . frames [ 0 ] ;
sidep - > tmap_num2 = 0 ;
}
}
}
reset_walls ( ) ;
2010-12-24 04:26:24 +00:00
#if 0
2006-03-20 16:43:15 +00:00
Num_open_doors = game_fileinfo . doors_howmany ;
2010-12-24 04:26:24 +00:00
# endif // 0
Num_open_doors = 0 ;
//go through all walls, killing references to invalid triggers
for ( i = 0 ; i < Num_walls ; i + + )
if ( Walls [ i ] . trigger > = Num_triggers ) {
Walls [ i ] . trigger = - 1 ; //kill trigger
}
//go through all triggers, killing unused ones
for ( i = 0 ; i < Num_triggers ; ) {
int w ;
// Find which wall this trigger is connected to.
for ( w = 0 ; w < Num_walls ; w + + )
if ( Walls [ w ] . trigger = = i )
break ;
# ifdef EDITOR
if ( w = = Num_walls ) {
remove_trigger_num ( i ) ;
}
else
# endif
i + + ;
}
// MK, 10/17/95: Make walls point back at the triggers that control them.
// Go through all triggers, stuffing controlling_trigger field in Walls.
{
int t ;
2006-03-20 16:43:15 +00:00
2010-12-24 04:26:24 +00:00
for ( t = 0 ; t < Num_triggers ; t + + ) {
int l ;
for ( l = 0 ; l < Triggers [ t ] . num_links ; l + + ) {
int seg_num , side_num , wall_num ;
seg_num = Triggers [ t ] . seg [ l ] ;
side_num = Triggers [ t ] . side [ l ] ;
wall_num = Segments [ seg_num ] . sides [ side_num ] . wall_num ;
// -- if (Walls[wall_num].controlling_trigger != -1)
// -- Int3();
//check to see that if a trigger requires a wall that it has one,
//and if it requires a matcen that it has one
if ( Triggers [ t ] . type = = TRIGGER_MATCEN ) {
if ( Segments [ seg_num ] . special ! = SEGMENT_IS_ROBOTMAKER )
Int3 ( ) ; //matcen trigger doesn't point to matcen
}
}
}
}
2006-03-20 16:43:15 +00:00
//fix old wall structs
2010-12-24 04:26:24 +00:00
if ( game_top_fileinfo_version < 17 ) {
2006-03-20 16:43:15 +00:00
int segnum , sidenum , wallnum ;
for ( segnum = 0 ; segnum < = Highest_segment_index ; segnum + + )
for ( sidenum = 0 ; sidenum < 6 ; sidenum + + )
if ( ( wallnum = Segments [ segnum ] . sides [ sidenum ] . wall_num ) ! = - 1 ) {
Walls [ wallnum ] . segnum = segnum ;
Walls [ wallnum ] . sidenum = sidenum ;
}
}
# ifndef NDEBUG
{
int sidenum ;
for ( sidenum = 0 ; sidenum < 6 ; sidenum + + ) {
int wallnum = Segments [ Highest_segment_index ] . sides [ sidenum ] . wall_num ;
if ( wallnum ! = - 1 )
if ( ( Walls [ wallnum ] . segnum ! = Highest_segment_index ) | | ( Walls [ wallnum ] . sidenum ! = sidenum ) )
Int3 ( ) ; // Error. Bogus walls in this segment.
// Consult Yuan or Mike.
}
}
# endif
//create_local_segment_data();
fix_object_segs ( ) ;
# ifndef NDEBUG
dump_mine_info ( ) ;
# endif
2010-12-24 04:26:24 +00:00
if ( game_top_fileinfo_version < GAME_VERSION )
2006-03-20 16:43:15 +00:00
return 1 ; //means old version
else
return 0 ;
}
int check_segment_connections ( void ) ;
# define LEVEL_FILE_VERSION 1
# ifndef RELEASE
char * Level_being_loaded = NULL ;
# endif
# ifdef COMPACT_SEGS
extern void ncache_flush ( ) ;
# endif
//loads a level (.LVL) file from disk
2010-12-24 04:26:24 +00:00
//returns 0 if success, else error code
2006-03-20 16:43:15 +00:00
int load_level ( char * filename_passed )
{
2010-12-24 04:26:24 +00:00
# ifdef EDITOR
2006-03-20 16:43:15 +00:00
int use_compiled_level = 1 ;
2010-12-24 04:26:24 +00:00
# endif
2011-06-01 07:59:51 +00:00
PHYSFS_file * LoadFile ;
2008-01-19 01:13:47 +00:00
char filename [ PATH_MAX ] ;
int sig , minedata_offset , gamedata_offset , hostagetext_offset ;
int mine_err , game_err ;
2006-03-20 16:43:15 +00:00
# ifdef COMPACT_SEGS
ncache_flush ( ) ;
# endif
# ifndef RELEASE
Level_being_loaded = filename_passed ;
# endif
strcpy ( filename , filename_passed ) ;
2008-01-19 01:13:47 +00:00
# ifdef EDITOR
//if we have the editor, try the LVL first, no matter what was passed.
//if we don't have an LVL, try what was passed or SDL/RDL
//if we don't have the editor, we just use what was passed
2010-12-24 04:26:24 +00:00
2008-01-19 01:13:47 +00:00
change_filename_extension ( filename , filename_passed , " .lvl " ) ;
use_compiled_level = 0 ;
2010-12-24 04:26:24 +00:00
2011-06-01 07:59:51 +00:00
if ( ! PHYSFSX_exists ( filename , 1 ) )
2008-01-19 01:13:47 +00:00
{
char * p = strrchr ( filename_passed , ' . ' ) ;
2010-12-24 04:26:24 +00:00
2008-01-19 01:13:47 +00:00
if ( stricmp ( p , " .lvl " ) )
strcpy ( filename , filename_passed ) ; // set to what was passed
else
2010-12-24 04:26:24 +00:00
change_filename_extension ( filename , filename , " .rdl " ) ;
2006-03-20 16:43:15 +00:00
use_compiled_level = 1 ;
}
2008-01-19 01:13:47 +00:00
# endif
2008-01-23 17:25:09 +00:00
2011-06-01 07:59:51 +00:00
if ( ! PHYSFSX_exists ( filename , 1 ) )
2008-01-23 17:25:09 +00:00
sprintf ( filename , " %s%s " , MISSION_DIR , filename_passed ) ;
2010-12-24 04:26:24 +00:00
2011-06-01 07:59:51 +00:00
LoadFile = PHYSFSX_openReadBuffered ( filename ) ;
2006-03-20 16:43:15 +00:00
if ( ! LoadFile ) {
2010-12-24 04:26:24 +00:00
# ifdef EDITOR
return 1 ;
# else
Error ( " Can't open file <%s> \n " , filename ) ;
# endif
2008-01-19 01:13:47 +00:00
}
2010-12-24 04:26:24 +00:00
2006-03-20 16:43:15 +00:00
strcpy ( Gamesave_current_filename , filename ) ;
2011-06-01 07:59:51 +00:00
sig = PHYSFSX_readInt ( LoadFile ) ;
Gamesave_current_version = PHYSFSX_readInt ( LoadFile ) ;
minedata_offset = PHYSFSX_readInt ( LoadFile ) ;
gamedata_offset = PHYSFSX_readInt ( LoadFile ) ;
2006-03-20 16:43:15 +00:00
2010-12-24 04:26:24 +00:00
Assert ( sig = = MAKE_SIG ( ' P ' , ' L ' , ' V ' , ' L ' ) ) ;
2006-03-20 16:43:15 +00:00
2008-01-19 01:13:47 +00:00
if ( Gamesave_current_version < 5 )
2011-06-01 07:59:51 +00:00
hostagetext_offset = PHYSFSX_readInt ( LoadFile ) ;
2010-12-24 04:26:24 +00:00
2011-06-01 07:59:51 +00:00
PHYSFSX_fseek ( LoadFile , minedata_offset , SEEK_SET ) ;
2006-03-20 16:43:15 +00:00
# ifdef EDITOR
if ( ! use_compiled_level )
mine_err = load_mine_data ( LoadFile ) ;
else
# endif
//NOTE LINK TO ABOVE!!
mine_err = load_mine_data_compiled ( LoadFile ) ;
2010-07-17 11:19:29 +00:00
/* !!!HACK!!!
* Descent 1 - Level 19 : OBERON MINE has some ugly overlapping rooms ( segment 484 ) .
* HACK to make this issue less visible by moving one vertex a little .
*/
2011-06-01 07:59:51 +00:00
if ( ! stricmp ( " Descent: First Strike " , Current_mission_longname ) & & ! stricmp ( " level19.rdl " , filename ) & & PHYSFS_fileLength ( LoadFile ) = = 136706 )
2010-07-17 11:19:29 +00:00
Vertices [ 1905 ] . z = - 385 * F1_0 ;
2010-12-24 04:26:24 +00:00
if ( mine_err = = - 1 ) { //error!!
2011-06-01 07:59:51 +00:00
PHYSFS_close ( LoadFile ) ;
2010-12-24 04:26:24 +00:00
return 2 ;
}
2006-03-20 16:43:15 +00:00
2011-06-01 07:59:51 +00:00
PHYSFSX_fseek ( LoadFile , gamedata_offset , SEEK_SET ) ;
2006-03-20 16:43:15 +00:00
game_err = load_game_data ( LoadFile ) ;
2010-12-24 04:26:24 +00:00
if ( game_err = = - 1 ) { //error!!
2011-06-01 07:59:51 +00:00
PHYSFS_close ( LoadFile ) ;
2010-12-24 04:26:24 +00:00
return 3 ;
}
2006-03-20 16:43:15 +00:00
# ifdef HOSTAGE_FACES
2011-06-01 07:59:51 +00:00
PHYSFSX_fseek ( LoadFile , hostagetext_offset , SEEK_SET ) ;
2006-03-20 16:43:15 +00:00
load_hostage_data ( LoadFile , ( version > = 1 ) ) ;
# endif
//======================== CLOSE FILE =============================
2011-06-01 07:59:51 +00:00
PHYSFS_close ( LoadFile ) ;
2006-03-20 16:43:15 +00:00
# ifdef EDITOR
# ifndef RELEASE
write_game_text_file ( filename ) ;
if ( Errors_in_mine ) {
if ( is_real_level ( filename ) ) {
char ErrorMessage [ 200 ] ;
sprintf ( ErrorMessage , " Warning: %i errors in %s! \n " , Errors_in_mine , Level_being_loaded ) ;
stop_time ( ) ;
gr_palette_load ( gr_palette ) ;
nm_messagebox ( NULL , 1 , " Continue " , ErrorMessage ) ;
start_time ( ) ;
2008-04-06 20:23:28 +00:00
}
2006-03-20 16:43:15 +00:00
}
# endif
# endif
# ifdef EDITOR
//If an old version, ask the use if he wants to save as new version
2010-08-19 13:32:33 +00:00
if ( ( ( LEVEL_FILE_VERSION > 1 ) & & Gamesave_current_version < LEVEL_FILE_VERSION ) | | mine_err = = 1 | | game_err = = 1 ) {
2006-03-20 16:43:15 +00:00
char ErrorMessage [ 200 ] ;
sprintf ( ErrorMessage , " You just loaded a old version level. Would \n "
" you like to save it as a current version level? " ) ;
gr_palette_load ( gr_palette ) ;
if ( nm_messagebox ( NULL , 2 , " Don't Save " , " Save " , ErrorMessage ) = = 1 )
save_level ( filename ) ;
}
# endif
# ifdef EDITOR
if ( Function_mode = = FMODE_EDITOR )
editor_status ( " Loaded NEW mine %s, \" %s \" " , filename , Current_level_name ) ;
# endif
2010-12-24 04:26:24 +00:00
# if !defined(NDEBUG) && !defined(COMPACT_SEGS)
2006-03-20 16:43:15 +00:00
if ( check_segment_connections ( ) )
nm_messagebox ( " ERROR " , 1 , " Ok " ,
" Connectivity errors detected in \n "
" mine. See monochrome screen for \n "
" details, and contact Matt or Mike. " ) ;
# endif
return 0 ;
}
# ifdef EDITOR
int get_level_name ( )
{
newmenu_item m [ 2 ] ;
m [ 0 ] . type = NM_TYPE_TEXT ; m [ 0 ] . text = " Please enter a name for this mine: " ;
m [ 1 ] . type = NM_TYPE_INPUT ; m [ 1 ] . text = Current_level_name ; m [ 1 ] . text_len = LEVEL_NAME_LEN ;
2010-12-24 04:26:24 +00:00
return newmenu_do ( NULL , " Enter mine name " , 2 , m , NULL , NULL ) > = 0 ;
2006-03-20 16:43:15 +00:00
}
# endif
# ifdef EDITOR
int Errors_in_mine ;
// -----------------------------------------------------------------------------
// Save game
2010-12-24 04:26:24 +00:00
int save_game_data ( PHYSFS_file * SaveFile )
2006-03-20 16:43:15 +00:00
{
2010-12-24 04:26:24 +00:00
short game_top_fileinfo_version = Gamesave_current_version > = 5 ? 31 : GAME_VERSION ;
2007-06-11 15:54:09 +00:00
int player_offset = 0 , object_offset = 0 , walls_offset = 0 , doors_offset = 0 , triggers_offset = 0 , control_offset = 0 , matcen_offset = 0 ; //, links_offset;
2010-12-24 04:26:24 +00:00
int offset_offset = 0 , end_offset = 0 ;
int i ;
2006-03-20 16:43:15 +00:00
//===================== SAVE FILE INFO ========================
2010-12-24 04:26:24 +00:00
PHYSFS_writeSLE16 ( SaveFile , 0x6705 ) ; // signature
PHYSFS_writeSLE16 ( SaveFile , game_top_fileinfo_version ) ;
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE32 ( SaveFile , sizeof ( game_fileinfo ) ) ;
PHYSFS_write ( SaveFile , Current_level_name , 15 , 1 ) ;
PHYSFS_writeSLE32 ( SaveFile , Current_level_num ) ;
offset_offset = PHYSFS_tell ( SaveFile ) ; // write the offsets later
PHYSFS_writeSLE32 ( SaveFile , - 1 ) ;
PHYSFS_writeSLE32 ( SaveFile , sizeof ( player ) ) ;
# define WRITE_HEADER_ENTRY(t, n) do { PHYSFS_writeSLE32(SaveFile, -1); PHYSFS_writeSLE32(SaveFile, n); PHYSFS_writeSLE32(SaveFile, sizeof(t)); } while(0)
WRITE_HEADER_ENTRY ( object , Highest_object_index + 1 ) ;
WRITE_HEADER_ENTRY ( wall , Num_walls ) ;
WRITE_HEADER_ENTRY ( active_door , Num_open_doors ) ;
WRITE_HEADER_ENTRY ( trigger , Num_triggers ) ;
WRITE_HEADER_ENTRY ( 0 , 0 ) ; // links (removed by Parallax)
WRITE_HEADER_ENTRY ( control_center_triggers , 1 ) ;
WRITE_HEADER_ENTRY ( matcen_info , Num_robot_centers ) ;
2006-03-20 16:43:15 +00:00
// Write the mine name
2008-01-23 17:25:09 +00:00
PHYSFSX_printf ( SaveFile , " %s \n " , Current_level_name ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE16 ( SaveFile , N_polygon_models ) ;
PHYSFS_write ( SaveFile , Pof_names , sizeof ( * Pof_names ) , N_polygon_models ) ;
2006-03-20 16:43:15 +00:00
//==================== SAVE PLAYER INFO ===========================
2008-01-23 17:25:09 +00:00
player_offset = PHYSFS_tell ( SaveFile ) ;
2010-12-24 04:26:24 +00:00
PHYSFS_write ( SaveFile , & Players [ Player_num ] , sizeof ( player ) , 1 ) ; // not endian friendly, but not used either
2006-03-20 16:43:15 +00:00
//==================== SAVE OBJECT INFO ===========================
2010-08-19 13:32:33 +00:00
object_offset = PHYSFS_tell ( SaveFile ) ;
2006-03-20 16:43:15 +00:00
//fwrite( &Objects, sizeof(object), game_fileinfo.object_howmany, SaveFile );
2010-12-24 04:26:24 +00:00
for ( i = 0 ; i < = Highest_object_index ; i + + )
write_object ( & Objects [ i ] , SaveFile ) ;
2006-03-20 16:43:15 +00:00
//==================== SAVE WALL INFO =============================
2008-01-23 17:25:09 +00:00
walls_offset = PHYSFS_tell ( SaveFile ) ;
2010-12-24 04:26:24 +00:00
for ( i = 0 ; i < Num_walls ; i + + )
wall_write ( & Walls [ i ] , game_top_fileinfo_version , SaveFile ) ;
2006-03-20 16:43:15 +00:00
//==================== SAVE DOOR INFO =============================
2008-01-23 17:25:09 +00:00
#if 0 // FIXME: okay to leave this out?
doors_offset = PHYSFS_tell ( SaveFile ) ;
for ( i = 0 ; i < Num_open_doors ; i + + )
door_write ( & ActiveDoors [ i ] , game_top_fileinfo_version , SaveFile ) ;
# endif
2006-03-20 16:43:15 +00:00
//==================== SAVE TRIGGER INFO =============================
2008-01-23 17:25:09 +00:00
triggers_offset = PHYSFS_tell ( SaveFile ) ;
2010-12-24 04:26:24 +00:00
for ( i = 0 ; i < Num_triggers ; i + + )
trigger_write ( & Triggers [ i ] , game_top_fileinfo_version , SaveFile ) ;
2006-03-20 16:43:15 +00:00
//================ SAVE CONTROL CENTER TRIGGER INFO ===============
2008-01-23 17:25:09 +00:00
control_offset = PHYSFS_tell ( SaveFile ) ;
2010-12-24 04:26:24 +00:00
control_center_triggers_write ( & ControlCenterTriggers , SaveFile ) ;
2006-03-20 16:43:15 +00:00
//================ SAVE MATERIALIZATION CENTER TRIGGER INFO ===============
2008-01-23 17:25:09 +00:00
matcen_offset = PHYSFS_tell ( SaveFile ) ;
2010-12-24 04:26:24 +00:00
for ( i = 0 ; i < Num_robot_centers ; i + + )
matcen_info_write ( & RobotCenters [ i ] , game_top_fileinfo_version , SaveFile ) ;
2006-03-20 16:43:15 +00:00
//============= REWRITE FILE INFO, TO SAVE OFFSETS ===============
2008-01-23 17:25:09 +00:00
end_offset = PHYSFS_tell ( SaveFile ) ;
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
// Update the offset fields
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
# define WRITE_OFFSET(o, n) do { PHYSFS_seek(SaveFile, offset_offset); PHYSFS_writeSLE32(SaveFile, o ## _offset); offset_offset += sizeof(int)*n; } while (0)
2006-03-20 16:43:15 +00:00
2008-01-23 17:25:09 +00:00
WRITE_OFFSET ( player , 2 ) ;
WRITE_OFFSET ( object , 3 ) ;
WRITE_OFFSET ( walls , 3 ) ;
WRITE_OFFSET ( doors , 3 ) ;
WRITE_OFFSET ( triggers , 6 ) ;
WRITE_OFFSET ( control , 3 ) ;
WRITE_OFFSET ( matcen , 3 ) ;
2006-03-20 16:43:15 +00:00
// Go back to end of data
2008-01-23 17:25:09 +00:00
PHYSFS_seek ( SaveFile , end_offset ) ;
2006-03-20 16:43:15 +00:00
return 0 ;
}
2008-01-23 17:25:09 +00:00
int save_mine_data ( PHYSFS_file * SaveFile ) ;
2006-03-20 16:43:15 +00:00
// -----------------------------------------------------------------------------
// Save game
int save_level_sub ( char * filename , int compiled_version )
{
2008-01-23 17:25:09 +00:00
PHYSFS_file * SaveFile ;
2010-12-24 04:26:24 +00:00
char temp_filename [ PATH_MAX ] ;
int minedata_offset = 0 , gamedata_offset = 0 , hostagetext_offset = 0 ;
2006-03-20 16:43:15 +00:00
2010-12-24 04:26:24 +00:00
// if ( !compiled_version )
{
2006-03-20 16:43:15 +00:00
write_game_text_file ( filename ) ;
if ( Errors_in_mine ) {
if ( is_real_level ( filename ) ) {
char ErrorMessage [ 200 ] ;
sprintf ( ErrorMessage , " Warning: %i errors in this mine! \n " , Errors_in_mine ) ;
gr_palette_load ( gr_palette ) ;
if ( nm_messagebox ( NULL , 2 , " Cancel Save " , " Save " , ErrorMessage ) ! = 1 ) {
return 1 ;
}
2008-04-06 20:23:28 +00:00
}
2006-03-20 16:43:15 +00:00
}
2010-12-24 04:26:24 +00:00
// change_filename_extension(temp_filename,filename,".LVL");
}
// else
{
change_filename_extension ( temp_filename , filename , " .RDL " ) ;
2006-03-20 16:43:15 +00:00
}
2008-01-23 17:25:09 +00:00
SaveFile = PHYSFSX_openWriteBuffered ( temp_filename ) ;
2006-03-20 16:43:15 +00:00
if ( ! SaveFile )
{
char ErrorMessage [ 256 ] ;
char fname [ 20 ] ;
2010-12-24 04:26:24 +00:00
_splitpath ( temp_filename , NULL , NULL , fname , NULL ) ;
2006-03-20 16:43:15 +00:00
sprintf ( ErrorMessage , \
" ERROR: Cannot write to '%s'. \n You probably need to check out a locked \n version of the file. You should save \n this under a different filename, and then \n check out a locked copy by typing \n \' co -l %s.lvl' \n at the DOS prompt. \n "
, temp_filename , fname ) ;
gr_palette_load ( gr_palette ) ;
nm_messagebox ( NULL , 1 , " Ok " , ErrorMessage ) ;
return 1 ;
}
if ( Current_level_name [ 0 ] = = 0 )
strcpy ( Current_level_name , " Untitled " ) ;
clear_transient_objects ( 1 ) ; //1 means clear proximity bombs
compress_objects ( ) ; //after this, Highest_object_index == num objects
//make sure player is in a segment
if ( update_object_seg ( & Objects [ Players [ 0 ] . objnum ] ) = = 0 ) {
if ( ConsoleObject - > segnum > Highest_segment_index )
ConsoleObject - > segnum = 0 ;
compute_segment_center ( & ConsoleObject - > pos , & ( Segments [ ConsoleObject - > segnum ] ) ) ;
}
fix_object_segs ( ) ;
//Write the header
2010-12-24 04:26:24 +00:00
PHYSFS_writeSLE32 ( SaveFile , MAKE_SIG ( ' P ' , ' L ' , ' V ' , ' L ' ) ) ;
PHYSFS_writeSLE32 ( SaveFile , Gamesave_current_version ) ;
2006-03-20 16:43:15 +00:00
//save placeholders
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE32 ( SaveFile , minedata_offset ) ;
PHYSFS_writeSLE32 ( SaveFile , gamedata_offset ) ;
PHYSFS_writeSLE32 ( SaveFile , hostagetext_offset ) ;
2006-03-20 16:43:15 +00:00
//Now write the damn data
2008-01-23 17:25:09 +00:00
minedata_offset = PHYSFS_tell ( SaveFile ) ;
2010-12-24 04:26:24 +00:00
#if 0 // only save compiled mine data
2006-03-20 16:43:15 +00:00
if ( ! compiled_version )
save_mine_data ( SaveFile ) ;
else
2010-12-24 04:26:24 +00:00
# endif
2006-03-20 16:43:15 +00:00
save_mine_data_compiled ( SaveFile ) ;
2008-01-23 17:25:09 +00:00
gamedata_offset = PHYSFS_tell ( SaveFile ) ;
2006-03-20 16:43:15 +00:00
save_game_data ( SaveFile ) ;
2008-01-23 17:25:09 +00:00
hostagetext_offset = PHYSFS_tell ( SaveFile ) ;
2006-03-20 16:43:15 +00:00
# ifdef HOSTAGE_FACES
save_hostage_data ( SaveFile ) ;
# endif
2010-12-24 04:26:24 +00:00
PHYSFS_seek ( SaveFile , sizeof ( int ) + sizeof ( Gamesave_current_version ) ) ;
2008-01-23 17:25:09 +00:00
PHYSFS_writeSLE32 ( SaveFile , minedata_offset ) ;
PHYSFS_writeSLE32 ( SaveFile , gamedata_offset ) ;
PHYSFS_writeSLE32 ( SaveFile , hostagetext_offset ) ;
2006-03-20 16:43:15 +00:00
//==================== CLOSE THE FILE =============================
2008-01-23 17:25:09 +00:00
PHYSFS_close ( SaveFile ) ;
2006-03-20 16:43:15 +00:00
2010-12-24 04:26:24 +00:00
// if ( !compiled_version )
{
2006-03-20 16:43:15 +00:00
if ( Function_mode = = FMODE_EDITOR )
editor_status ( " Saved mine %s, \" %s \" " , filename , Current_level_name ) ;
}
return 0 ;
}
int save_level ( char * filename )
{
int r1 ;
// Save normal version...
2010-12-24 04:26:24 +00:00
//save_level_sub(filename, 0); // just save compiled one
2006-03-20 16:43:15 +00:00
// Save compiled version...
2010-12-24 04:26:24 +00:00
r1 = save_level_sub ( filename , 1 ) ;
2006-03-20 16:43:15 +00:00
return r1 ;
}
# ifdef HOSTAGE_FACES
2008-01-23 17:25:09 +00:00
void save_hostage_data ( PHYSFS_file * fp )
2006-03-20 16:43:15 +00:00
{
int i , num_hostages = 0 ;
// Find number of hostages in mine...
for ( i = 0 ; i < = Highest_object_index ; i + + ) {
int num ;
if ( Objects [ i ] . type = = OBJ_HOSTAGE ) {
num = Objects [ i ] . id ;
# ifndef SHAREWARE
if ( num < 0 | | num > = MAX_HOSTAGES | | Hostage_face_clip [ Hostages [ num ] . vclip_num ] . num_frames < = 0 )
num = 0 ;
# else
num = 0 ;
# endif
if ( num + 1 > num_hostages )
num_hostages = num + 1 ;
}
}
2008-01-13 00:58:49 +00:00
cfile_write_int ( HOSTAGE_DATA_VERSION , fp ) ;
2006-03-20 16:43:15 +00:00
for ( i = 0 ; i < num_hostages ; i + + ) {
2008-01-13 00:58:49 +00:00
cfile_write_int ( Hostages [ i ] . vclip_num , fp ) ;
2006-03-20 16:43:15 +00:00
fputs ( Hostages [ i ] . text , fp ) ;
fputc ( ' \n ' , fp ) ; //fgets wants a newline
}
}
# endif //HOSTAGE_FACES
# endif //EDITOR
# ifndef NDEBUG
void dump_mine_info ( void )
{
int segnum , sidenum ;
fix min_u , max_u , min_v , max_v , min_l , max_l , max_sl ;
min_u = F1_0 * 1000 ;
min_v = min_u ;
min_l = min_u ;
max_u = - min_u ;
max_v = max_u ;
max_l = max_u ;
max_sl = 0 ;
for ( segnum = 0 ; segnum < = Highest_segment_index ; segnum + + ) {
for ( sidenum = 0 ; sidenum < MAX_SIDES_PER_SEGMENT ; sidenum + + ) {
int vertnum ;
side * sidep = & Segments [ segnum ] . sides [ sidenum ] ;
if ( Segments [ segnum ] . static_light > max_sl )
max_sl = Segments [ segnum ] . static_light ;
for ( vertnum = 0 ; vertnum < 4 ; vertnum + + ) {
if ( sidep - > uvls [ vertnum ] . u < min_u )
min_u = sidep - > uvls [ vertnum ] . u ;
else if ( sidep - > uvls [ vertnum ] . u > max_u )
max_u = sidep - > uvls [ vertnum ] . u ;
if ( sidep - > uvls [ vertnum ] . v < min_v )
min_v = sidep - > uvls [ vertnum ] . v ;
else if ( sidep - > uvls [ vertnum ] . v > max_v )
max_v = sidep - > uvls [ vertnum ] . v ;
if ( sidep - > uvls [ vertnum ] . l < min_l )
min_l = sidep - > uvls [ vertnum ] . l ;
else if ( sidep - > uvls [ vertnum ] . l > max_l )
max_l = sidep - > uvls [ vertnum ] . l ;
}
}
}
}
# endif
# ifdef HOSTAGE_FACES
2011-06-01 07:59:51 +00:00
void load_hostage_data ( PHYSFS_file * fp , int do_read )
2006-03-20 16:43:15 +00:00
{
int version , i , num , num_hostages ;
hostage_init_all ( ) ;
num_hostages = 0 ;
// Find number of hostages in mine...
for ( i = 0 ; i < = Highest_object_index ; i + + ) {
if ( Objects [ i ] . type = = OBJ_HOSTAGE ) {
num = Objects [ i ] . id ;
if ( num + 1 > num_hostages )
num_hostages = num + 1 ;
if ( Hostages [ num ] . objnum ! = - 1 ) { //slot already used
num = hostage_get_next_slot ( ) ; //..so get new slot
if ( num + 1 > num_hostages )
num_hostages = num + 1 ;
Objects [ i ] . id = num ;
}
if ( num > - 1 & & num < MAX_HOSTAGES ) {
Assert ( Hostages [ num ] . objnum = = - 1 ) ; //make sure not used
// -- Matt -- commented out by MK on 11/19/94, hit often in level 3, level 4. Assert(Hostages[num].objnum == -1); //make sure not used
Hostages [ num ] . objnum = i ;
Hostages [ num ] . objsig = Objects [ i ] . signature ;
}
}
}
if ( do_read ) {
2011-06-01 07:59:51 +00:00
version = PHYSFSX_readInt ( fp ) ;
2006-03-20 16:43:15 +00:00
for ( i = 0 ; i < num_hostages ; i + + ) {
Assert ( Hostages [ i ] . objnum ! = - 1 ) ; //make sure slot filled in
2011-06-01 07:59:51 +00:00
Hostages [ i ] . vclip_num = PHYSFSX_readInt ( fp ) ;
2006-03-20 16:43:15 +00:00
# ifndef SHAREWARE
if ( Hostages [ i ] . vclip_num < 0 | | Hostages [ i ] . vclip_num > = MAX_HOSTAGES | | Hostage_face_clip [ Hostages [ i ] . vclip_num ] . num_frames < = 0 )
Hostages [ i ] . vclip_num = 0 ;
Assert ( Hostage_face_clip [ Hostages [ i ] . vclip_num ] . num_frames ) ;
# endif
2011-06-01 07:59:51 +00:00
PHYSFSX_fgets ( Hostages [ i ] . text , HOSTAGE_MESSAGE_LEN , fp ) ;
2006-03-20 16:43:15 +00:00
}
}
else
for ( i = 0 ; i < num_hostages ; i + + ) {
Assert ( Hostages [ i ] . objnum ! = - 1 ) ; //make sure slot filled in
Hostages [ i ] . vclip_num = 0 ;
}
}
# endif //HOSTAGE_FACES