//type==1 means 1.1, type==2 means 1.2 (with weapons) void bm_read_extra_robots(char *fname,int type) { PHYSFS_file *fp; int t,i,version; fp = PHYSFSX_openReadBuffered(fname); if (!fp) { Error("Failed to open HAM file \"%s\"", fname); return; } if (type == 2) { int sig; sig = PHYSFSX_readInt(fp); if (sig != MAKE_SIG('X','H','A','M')) return; version = PHYSFSX_readInt(fp); } else version = 0; (void)version; // NOTE: we do not need it, but keep it for possible further use bm_free_extra_models(); bm_free_extra_objbitmaps(); //read extra weapons t = PHYSFSX_readInt(fp); N_weapon_types = N_D2_WEAPON_TYPES+t; if (N_weapon_types >= MAX_WEAPON_TYPES) Error("Too many weapons (%d) in <%s>. Max is %d.",t,fname,MAX_WEAPON_TYPES-N_D2_WEAPON_TYPES); weapon_info_read_n(&Weapon_info[N_D2_WEAPON_TYPES], t, fp, 3); //now read robot info t = PHYSFSX_readInt(fp); N_robot_types = N_D2_ROBOT_TYPES+t; if (N_robot_types >= MAX_ROBOT_TYPES) Error("Too many robots (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_TYPES-N_D2_ROBOT_TYPES); robot_info_read_n(&Robot_info[N_D2_ROBOT_TYPES], t, fp); t = PHYSFSX_readInt(fp); N_robot_joints = N_D2_ROBOT_JOINTS+t; if (N_robot_joints >= MAX_ROBOT_JOINTS) Error("Too many robot joints (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_JOINTS-N_D2_ROBOT_JOINTS); jointpos_read_n(&Robot_joints[N_D2_ROBOT_JOINTS], t, fp); t = PHYSFSX_readInt(fp); N_polygon_models = N_D2_POLYGON_MODELS+t; if (N_polygon_models >= MAX_POLYGON_MODELS) Error("Too many polygon models (%d) in <%s>. Max is %d.",t,fname,MAX_POLYGON_MODELS-N_D2_POLYGON_MODELS); polymodel_read_n(&Polygon_models[N_D2_POLYGON_MODELS], t, fp); for (i=N_D2_POLYGON_MODELS; i<N_polygon_models; i++ ) polygon_model_data_read(&Polygon_models[i], fp); for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++) Dying_modelnums[i] = PHYSFSX_readInt(fp); for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++) Dead_modelnums[i] = PHYSFSX_readInt(fp); t = PHYSFSX_readInt(fp); if (N_D2_OBJBITMAPS+t >= MAX_OBJ_BITMAPS) Error("Too many object bitmaps (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPS); bitmap_index_read_n(&ObjBitmaps[N_D2_OBJBITMAPS], t, fp); t = PHYSFSX_readInt(fp); if (N_D2_OBJBITMAPPTRS+t >= MAX_OBJ_BITMAPS) Error("Too many object bitmap pointers (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPPTRS); for (i = N_D2_OBJBITMAPPTRS; i < (N_D2_OBJBITMAPPTRS + t); i++) ObjBitmapPtrs[i] = PHYSFSX_readShort(fp); PHYSFS_close(fp); }
/* * reads n weapon_info structs from a PHYSFS_file */ int weapon_info_read_n(weapon_info *wi, int n, PHYSFS_file *fp, int file_version) { int i, j; for (i = 0; i < n; i++) { wi[i].render_type = PHYSFSX_readByte(fp); wi[i].persistent = PHYSFSX_readByte(fp); wi[i].model_num = PHYSFSX_readShort(fp); wi[i].model_num_inner = PHYSFSX_readShort(fp); wi[i].flash_vclip = PHYSFSX_readByte(fp); wi[i].robot_hit_vclip = PHYSFSX_readByte(fp); wi[i].flash_sound = PHYSFSX_readShort(fp); wi[i].wall_hit_vclip = PHYSFSX_readByte(fp); wi[i].fire_count = PHYSFSX_readByte(fp); wi[i].robot_hit_sound = PHYSFSX_readShort(fp); wi[i].ammo_usage = PHYSFSX_readByte(fp); wi[i].weapon_vclip = PHYSFSX_readByte(fp); wi[i].wall_hit_sound = PHYSFSX_readShort(fp); wi[i].destroyable = PHYSFSX_readByte(fp); wi[i].matter = PHYSFSX_readByte(fp); wi[i].bounce = PHYSFSX_readByte(fp); wi[i].homing_flag = PHYSFSX_readByte(fp); wi[i].speedvar = PHYSFSX_readByte(fp); wi[i].flags = PHYSFSX_readByte(fp); wi[i].flash = PHYSFSX_readByte(fp); wi[i].afterburner_size = PHYSFSX_readByte(fp); if (file_version >= 3) wi[i].children = PHYSFSX_readByte(fp); else /* Set the type of children correctly when using old * datafiles. In earlier descent versions this was simply * hard-coded in create_smart_children(). */ switch (i) { case SMART_ID: wi[i].children = PLAYER_SMART_HOMING_ID; break; case SUPERPROX_ID: wi[i].children = SMART_MINE_HOMING_ID; break; #if 0 /* not present in shareware */ case ROBOT_SUPERPROX_ID: wi[i].children = ROBOT_SMART_MINE_HOMING_ID; break; case EARTHSHAKER_ID: wi[i].children = EARTHSHAKER_MEGA_ID; break; #endif default: wi[i].children = -1; break; } wi[i].energy_usage = PHYSFSX_readFix(fp); wi[i].fire_wait = PHYSFSX_readFix(fp); if (file_version >= 3) wi[i].multi_damage_scale = PHYSFSX_readFix(fp); else /* FIXME: hack this to set the real values */ wi[i].multi_damage_scale = F1_0; bitmap_index_read(&wi[i].bitmap, fp); wi[i].blob_size = PHYSFSX_readFix(fp); wi[i].flash_size = PHYSFSX_readFix(fp); wi[i].impact_size = PHYSFSX_readFix(fp); for (j = 0; j < NDL; j++) wi[i].strength[j] = PHYSFSX_readFix(fp); for (j = 0; j < NDL; j++) wi[i].speed[j] = PHYSFSX_readFix(fp); wi[i].mass = PHYSFSX_readFix(fp); wi[i].drag = PHYSFSX_readFix(fp); wi[i].thrust = PHYSFSX_readFix(fp); wi[i].po_len_to_width_ratio = PHYSFSX_readFix(fp); wi[i].light = PHYSFSX_readFix(fp); wi[i].lifetime = PHYSFSX_readFix(fp); wi[i].damage_radius = PHYSFSX_readFix(fp); bitmap_index_read(&wi[i].picture, fp); if (file_version >= 3) bitmap_index_read(&wi[i].hires_picture, fp); else wi[i].hires_picture.index = wi[i].picture.index; } return i; }
void bm_read_all(PHYSFS_file * fp) { int i,t; NumTextures = PHYSFSX_readInt(fp); bitmap_index_read_n(Textures, NumTextures, fp ); tmap_info_read_n(TmapInfo, NumTextures, fp); t = PHYSFSX_readInt(fp); PHYSFS_read( fp, Sounds, sizeof(ubyte), t ); PHYSFS_read( fp, AltSounds, sizeof(ubyte), t ); Num_vclips = PHYSFSX_readInt(fp); vclip_read_n(Vclip, Num_vclips, fp); Num_effects = PHYSFSX_readInt(fp); eclip_read_n(Effects, Num_effects, fp); Num_wall_anims = PHYSFSX_readInt(fp); wclip_read_n(WallAnims, Num_wall_anims, fp); N_robot_types = PHYSFSX_readInt(fp); robot_info_read_n(Robot_info, N_robot_types, fp); N_robot_joints = PHYSFSX_readInt(fp); jointpos_read_n(Robot_joints, N_robot_joints, fp); N_weapon_types = PHYSFSX_readInt(fp); weapon_info_read_n(Weapon_info, N_weapon_types, fp, Piggy_hamfile_version); N_powerup_types = PHYSFSX_readInt(fp); powerup_type_info_read_n(Powerup_info, N_powerup_types, fp); N_polygon_models = PHYSFSX_readInt(fp); polymodel_read_n(Polygon_models, N_polygon_models, fp); for (i=0; i<N_polygon_models; i++ ) polygon_model_data_read(&Polygon_models[i], fp); for (i = 0; i < N_polygon_models; i++) Dying_modelnums[i] = PHYSFSX_readInt(fp); for (i = 0; i < N_polygon_models; i++) Dead_modelnums[i] = PHYSFSX_readInt(fp); t = PHYSFSX_readInt(fp); bitmap_index_read_n(Gauges, t, fp); bitmap_index_read_n(Gauges_hires, t, fp); N_ObjBitmaps = PHYSFSX_readInt(fp); bitmap_index_read_n(ObjBitmaps, N_ObjBitmaps, fp); for (i = 0; i < N_ObjBitmaps; i++) ObjBitmapPtrs[i] = PHYSFSX_readShort(fp); player_ship_read(&only_player_ship, fp); Num_cockpits = PHYSFSX_readInt(fp); bitmap_index_read_n(cockpit_bitmap, Num_cockpits, fp); //@@ PHYSFS_read( fp, &Num_total_object_types, sizeof(int), 1 ); //@@ PHYSFS_read( fp, ObjType, sizeof(byte), Num_total_object_types ); //@@ PHYSFS_read( fp, ObjId, sizeof(byte), Num_total_object_types ); //@@ PHYSFS_read( fp, ObjStrength, sizeof(fix), Num_total_object_types ); First_multi_bitmap_num = PHYSFSX_readInt(fp); Num_reactors = PHYSFSX_readInt(fp); reactor_read_n(Reactors, Num_reactors, fp); Marker_model_num = PHYSFSX_readInt(fp); //@@PHYSFS_read( fp, &N_controlcen_guns, sizeof(int), 1 ); //@@PHYSFS_read( fp, controlcen_gun_points, sizeof(vms_vector), N_controlcen_guns ); //@@PHYSFS_read( fp, controlcen_gun_dirs, sizeof(vms_vector), N_controlcen_guns ); if (Piggy_hamfile_version < 3) { exit_modelnum = PHYSFSX_readInt(fp); destroyed_exit_modelnum = PHYSFSX_readInt(fp); } else exit_modelnum = destroyed_exit_modelnum = N_polygon_models; }
int load_mine_data_compiled(PHYSFS_file *LoadFile) { int i, segnum, sidenum; ubyte compiled_version; short temp_short; ushort temp_ushort = 0; ubyte bit_mask; if (!strcmp(strchr(Gamesave_current_filename, '.'), ".sdl")) New_file_format_load = 0; // descent 1 shareware else New_file_format_load = 1; // For compiled levels, textures map to themselves, prevent tmap_override always being gray, // bug which Matt and John refused to acknowledge, so here is Mike, fixing it. // // Although in a cloud of arrogant glee, he forgot to ifdef it on EDITOR! // (Matt told me to write that!) #ifdef EDITOR for (i=0; i<MAX_TEXTURES; i++) tmap_xlate_table[i] = i; #endif // memset( Segments, 0, sizeof(segment)*MAX_SEGMENTS ); fuelcen_reset(); //=============================== Reading part ============================== compiled_version = PHYSFSX_readByte(LoadFile); (void)compiled_version; if (New_file_format_load) Num_vertices = PHYSFSX_readShort(LoadFile); else Num_vertices = PHYSFSX_readInt(LoadFile); Assert( Num_vertices <= MAX_VERTICES ); if (New_file_format_load) Num_segments = PHYSFSX_readShort(LoadFile); else Num_segments = PHYSFSX_readInt(LoadFile); Assert( Num_segments <= MAX_SEGMENTS ); for (i = 0; i < Num_vertices; i++) PHYSFSX_readVector( &(Vertices[i]), LoadFile); for (segnum=0; segnum<Num_segments; segnum++ ) { #ifdef EDITOR Segments[segnum].segnum = segnum; Segments[segnum].group = 0; #endif if (New_file_format_load) bit_mask = PHYSFSX_readByte(LoadFile); else bit_mask = 0x7f; // read all six children and special stuff... if (Gamesave_current_version == 5) { // d2 SHAREWARE level read_special(segnum,bit_mask,LoadFile); read_verts(segnum,LoadFile); read_children(segnum,bit_mask,LoadFile); } else { read_children(segnum,bit_mask,LoadFile); read_verts(segnum,LoadFile); if (Gamesave_current_version <= 1) { // descent 1 level read_special(segnum,bit_mask,LoadFile); } } Segments[segnum].objects = -1; if (Gamesave_current_version <= 5) { // descent 1 thru d2 SHAREWARE level // Read fix Segments[segnum].static_light (shift down 5 bits, write as short) temp_ushort = PHYSFSX_readShort(LoadFile); Segments[segnum].static_light = ((fix)temp_ushort) << 4; //PHYSFS_read( LoadFile, &Segments[segnum].static_light, sizeof(fix), 1 ); } // Read the walls as a 6 byte array for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++ ) { Segments[segnum].sides[sidenum].pad = 0; } if (New_file_format_load) bit_mask = PHYSFSX_readByte(LoadFile); else bit_mask = 0x3f; // read all six sides for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) { ubyte byte_wallnum; if (bit_mask & (1 << sidenum)) { byte_wallnum = PHYSFSX_readByte(LoadFile); if ( byte_wallnum == 255 ) Segments[segnum].sides[sidenum].wall_num = -1; else Segments[segnum].sides[sidenum].wall_num = byte_wallnum; } else Segments[segnum].sides[sidenum].wall_num = -1; } for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++ ) { if ( (Segments[segnum].children[sidenum]==-1) || (Segments[segnum].sides[sidenum].wall_num!=-1) ) { // Read short Segments[segnum].sides[sidenum].tmap_num; temp_ushort = PHYSFSX_readShort(LoadFile); Segments[segnum].sides[sidenum].tmap_num = convert_tmap(temp_ushort & 0x7fff); if (New_file_format_load && !(temp_ushort & 0x8000)) Segments[segnum].sides[sidenum].tmap_num2 = 0; else { // Read short Segments[segnum].sides[sidenum].tmap_num2; Segments[segnum].sides[sidenum].tmap_num2 = PHYSFSX_readShort(LoadFile); Segments[segnum].sides[sidenum].tmap_num2 = (convert_tmap(Segments[segnum].sides[sidenum].tmap_num2 & 0x3fff)) | (Segments[segnum].sides[sidenum].tmap_num2 & 0xc000); } // Read uvl Segments[segnum].sides[sidenum].uvls[4] (u,v>>5, write as short, l>>1 write as short) for (i=0; i<4; i++ ) { temp_short = PHYSFSX_readShort(LoadFile); Segments[segnum].sides[sidenum].uvls[i].u = ((fix)temp_short) << 5; temp_short = PHYSFSX_readShort(LoadFile); Segments[segnum].sides[sidenum].uvls[i].v = ((fix)temp_short) << 5; temp_ushort = PHYSFSX_readShort(LoadFile); Segments[segnum].sides[sidenum].uvls[i].l = ((fix)temp_ushort) << 1; //PHYSFS_read( LoadFile, &Segments[segnum].sides[sidenum].uvls[i].l, sizeof(fix), 1 ); } } else { Segments[segnum].sides[sidenum].tmap_num = 0; Segments[segnum].sides[sidenum].tmap_num2 = 0; for (i=0; i<4; i++ ) { Segments[segnum].sides[sidenum].uvls[i].u = 0; Segments[segnum].sides[sidenum].uvls[i].v = 0; Segments[segnum].sides[sidenum].uvls[i].l = 0; } } } } Highest_vertex_index = Num_vertices-1; Highest_segment_index = Num_segments-1; validate_segment_all(); // Fill in side type and normals. for (i=0; i<Num_segments; i++) { if (Gamesave_current_version > 5) segment2_read(&Segments[i], LoadFile); fuelcen_activate( &Segments[i], Segments[i].special ); } reset_objects(1); //one object, the player return 0; }