1 /* $Id: bm.c,v 1.29 2003-03-25 10:17:05 btb Exp $ */
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 * Bitmap and palette loading functions.
20 * Revision 1.1 1995/05/16 15:23:08 allender
23 * Revision 2.3 1995/03/14 16:22:04 john
24 * Added cdrom alternate directory stuff.
26 * Revision 2.2 1995/03/07 16:51:48 john
27 * Fixed robots not moving without edtiro bug.
29 * Revision 2.1 1995/03/06 15:23:06 john
30 * New screen techniques.
32 * Revision 2.0 1995/02/27 11:27:05 john
33 * New version 2.0, which has no anonymous unions, builds with
34 * Watcom 10.0, and doesn't require parsing BITMAPS.TBL.
78 ubyte Sounds[MAX_SOUNDS];
79 ubyte AltSounds[MAX_SOUNDS];
82 int Num_total_object_types;
83 byte ObjType[MAX_OBJTYPE];
84 byte ObjId[MAX_OBJTYPE];
85 fix ObjStrength[MAX_OBJTYPE];
88 //for each model, a model number for dying & dead variants, or -1 if none
89 int Dying_modelnums[MAX_POLYGON_MODELS];
90 int Dead_modelnums[MAX_POLYGON_MODELS];
92 //the polygon model number to use for the marker
93 int Marker_model_num = -1;
95 //right now there's only one player ship, but we can have another by
96 //adding an array and setting the pointer to the active ship.
97 player_ship only_player_ship,*Player_ship=&only_player_ship;
99 //----------------- Miscellaneous bitmap pointers ---------------
100 int Num_cockpits = 0;
101 bitmap_index cockpit_bitmap[N_COCKPIT_BITMAPS];
103 //---------------- Variables for wall textures ------------------
105 tmap_info TmapInfo[MAX_TEXTURES];
107 //---------------- Variables for object textures ----------------
109 int First_multi_bitmap_num=-1;
112 bitmap_index ObjBitmaps[MAX_OBJ_BITMAPS];
113 ushort ObjBitmapPtrs[MAX_OBJ_BITMAPS]; // These point back into ObjBitmaps, since some are used twice.
116 #define tmap_info_read_n(ti, n, fp) cfread(ti, sizeof(tmap_info), n, fp)
119 * reads n tmap_info structs from a CFILE
121 int tmap_info_read_n(tmap_info *ti, int n, CFILE *fp)
125 for (i = 0; i < n; i++) {
126 ti[i].flags = cfile_read_byte(fp);
127 ti[i].pad[0] = cfile_read_byte(fp);
128 ti[i].pad[1] = cfile_read_byte(fp);
129 ti[i].pad[2] = cfile_read_byte(fp);
130 ti[i].lighting = cfile_read_fix(fp);
131 ti[i].damage = cfile_read_fix(fp);
132 ti[i].eclip_num = cfile_read_short(fp);
133 ti[i].destroyed = cfile_read_short(fp);
134 ti[i].slide_u = cfile_read_short(fp);
135 ti[i].slide_v = cfile_read_short(fp);
141 int tmap_info_read_n_d1(tmap_info *ti, int n, CFILE *fp)
145 for (i = 0; i < n; i++) {
146 cfseek(fp, 13, SEEK_CUR);// skip filename
147 ti[i].flags = cfile_read_byte(fp);
148 ti[i].lighting = cfile_read_fix(fp);
149 ti[i].damage = cfile_read_fix(fp);
150 ti[i].eclip_num = cfile_read_int(fp);
155 extern int Num_bitmap_files;
156 int extra_bitmap_num;
158 bitmap_index exitmodel_bm_load_sub( char * filename )
160 bitmap_index bitmap_num;
161 grs_bitmap * new = &GameBitmaps[extra_bitmap_num];
163 int iff_error; //reference parm to avoid warning message
165 bitmap_num.index = 0;
167 //MALLOC( new, grs_bitmap, 1 );
168 iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal);
170 if (iff_error != IFF_NO_ERROR) {
171 con_printf(CON_DEBUG, "Error loading exit model bitmap <%s> - IFF error: %s\n", filename, iff_errormsg(iff_error));
175 if ( iff_has_transparency )
176 gr_remap_bitmap_good( new, newpal, iff_transparent_color, 254 );
178 gr_remap_bitmap_good( new, newpal, -1, 254 );
180 new->avg_color = 0; //compute_average_pixel(new);
182 bitmap_num.index = extra_bitmap_num;
184 GameBitmaps[extra_bitmap_num++] = *new;
190 grs_bitmap *load_exit_model_bitmap(char *name)
192 Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS);
195 ObjBitmaps[N_ObjBitmaps] = exitmodel_bm_load_sub(name);
197 if (ObjBitmaps[N_ObjBitmaps].index == 0)
199 char *name2 = d_strdup(name);
200 *strrchr(name2, '.') = '\0';
201 ObjBitmaps[N_ObjBitmaps] = read_extra_d1_bitmap(name2);
204 if (ObjBitmaps[N_ObjBitmaps].index == 0)
207 if (GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_w!=64 || GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_h!=64)
208 Error("Bitmap <%s> is not 64x64",name);
209 ObjBitmapPtrs[N_ObjBitmaps] = N_ObjBitmaps;
211 Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS);
212 return &GameBitmaps[ObjBitmaps[N_ObjBitmaps-1].index];
217 bm_free_extra_bitmaps()
221 for (i = Num_bitmap_files; i < extra_bitmap_num; i++)
222 d_free(GameBitmaps[i].bm_data);
223 extra_bitmap_num = Num_bitmap_files;
228 void ogl_cache_polymodel_textures(int model_num);
231 int load_exit_models()
236 start_num = N_ObjBitmaps;
237 extra_bitmap_num = Num_bitmap_files;
238 if (!load_exit_model_bitmap("steel1.bbm") ||
239 !load_exit_model_bitmap("rbot061.bbm") ||
240 !load_exit_model_bitmap("rbot062.bbm") ||
241 !load_exit_model_bitmap("steel1.bbm") ||
242 !load_exit_model_bitmap("rbot061.bbm") ||
243 !load_exit_model_bitmap("rbot063.bbm"))
245 Warning("Can't load exit models!\n");
250 exit_hamfile = cfopen("exit.ham","rb");
252 exit_hamfile = cfopen(":Data:exit.ham","rb");
255 polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile);
256 polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile);
257 Polygon_models[exit_modelnum].first_texture = start_num;
258 Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3;
260 polygon_model_data_read(&Polygon_models[exit_modelnum], exit_hamfile);
262 polygon_model_data_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile);
264 cfclose(exit_hamfile);
266 } else if (cfexist("exit01.pof") && cfexist("exit01d.pof")) {
268 exit_modelnum = load_polygon_model("exit01.pof", 3, start_num, NULL);
269 destroyed_exit_modelnum = load_polygon_model("exit01d.pof", 3, start_num + 3, NULL);
272 ogl_cache_polymodel_textures(exit_modelnum);
273 ogl_cache_polymodel_textures(destroyed_exit_modelnum);
276 else if (cfexist(D1_PIGFILE))
280 exit_hamfile = cfopen(D1_PIGFILE, "rb");
281 switch (cfilelength(exit_hamfile)) { //total hack for loading models
283 offset = 91848; /* and 92582 */
284 offset2 = 383390; /* and 394022 */
288 case D1_SHAREWARE_10_PIGSIZE:
289 case D1_SHAREWARE_PIGSIZE:
290 Int3(); /* exit models should be in .pofs */
293 case D1_MAC_SHARE_PIGSIZE:
294 Warning("Can't load exit models!\n");
298 cfseek(exit_hamfile, offset, SEEK_SET);
299 polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile);
300 polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile);
301 Polygon_models[exit_modelnum].first_texture = start_num;
302 Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3;
304 cfseek(exit_hamfile, offset2, SEEK_SET);
305 polygon_model_data_read(&Polygon_models[exit_modelnum], exit_hamfile);
306 polygon_model_data_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile);
308 cfclose(exit_hamfile);
310 Warning("Can't load exit models!\n");
314 atexit(bm_free_extra_bitmaps);
320 //-----------------------------------------------------------------
321 // Read data from piggy.
322 // This is called when the editor is OUT.
323 // If editor is in, bm_init_use_table() is called.
326 init_polygon_models();
327 if (! piggy_init()) // This calls bm_read_all
328 Error("Cannot open pig and/or ham file");
332 init_endlevel(); //this is in bm_init_use_tbl(), so I gues it goes here
337 void bm_read_all(CFILE * fp)
341 NumTextures = cfile_read_int(fp);
342 bitmap_index_read_n(Textures, NumTextures, fp );
343 tmap_info_read_n(TmapInfo, NumTextures, fp);
345 t = cfile_read_int(fp);
346 cfread( Sounds, sizeof(ubyte), t, fp );
347 cfread( AltSounds, sizeof(ubyte), t, fp );
349 Num_vclips = cfile_read_int(fp);
350 vclip_read_n(Vclip, Num_vclips, fp);
352 Num_effects = cfile_read_int(fp);
353 eclip_read_n(Effects, Num_effects, fp);
355 Num_wall_anims = cfile_read_int(fp);
356 wclip_read_n(WallAnims, Num_wall_anims, fp);
358 N_robot_types = cfile_read_int(fp);
359 robot_info_read_n(Robot_info, N_robot_types, fp);
361 N_robot_joints = cfile_read_int(fp);
362 jointpos_read_n(Robot_joints, N_robot_joints, fp);
364 N_weapon_types = cfile_read_int(fp);
365 weapon_info_read_n(Weapon_info, N_weapon_types, fp, Piggy_hamfile_version);
367 N_powerup_types = cfile_read_int(fp);
368 powerup_type_info_read_n(Powerup_info, N_powerup_types, fp);
370 N_polygon_models = cfile_read_int(fp);
371 polymodel_read_n(Polygon_models, N_polygon_models, fp);
373 for (i=0; i<N_polygon_models; i++ )
374 polygon_model_data_read(&Polygon_models[i], fp);
376 for (i = 0; i < N_polygon_models; i++)
377 Dying_modelnums[i] = cfile_read_int(fp);
378 for (i = 0; i < N_polygon_models; i++)
379 Dead_modelnums[i] = cfile_read_int(fp);
381 t = cfile_read_int(fp);
382 bitmap_index_read_n(Gauges, t, fp);
383 bitmap_index_read_n(Gauges_hires, t, fp);
385 N_ObjBitmaps = cfile_read_int(fp);
386 bitmap_index_read_n(ObjBitmaps, N_ObjBitmaps, fp);
387 for (i = 0; i < N_ObjBitmaps; i++)
388 ObjBitmapPtrs[i] = cfile_read_short(fp);
390 player_ship_read(&only_player_ship, fp);
392 Num_cockpits = cfile_read_int(fp);
393 bitmap_index_read_n(cockpit_bitmap, Num_cockpits, fp);
395 //@@ cfread( &Num_total_object_types, sizeof(int), 1, fp );
396 //@@ cfread( ObjType, sizeof(byte), Num_total_object_types, fp );
397 //@@ cfread( ObjId, sizeof(byte), Num_total_object_types, fp );
398 //@@ cfread( ObjStrength, sizeof(fix), Num_total_object_types, fp );
400 First_multi_bitmap_num = cfile_read_int(fp);
402 Num_reactors = cfile_read_int(fp);
403 reactor_read_n(Reactors, Num_reactors, fp);
405 Marker_model_num = cfile_read_int(fp);
407 //@@cfread( &N_controlcen_guns, sizeof(int), 1, fp );
408 //@@cfread( controlcen_gun_points, sizeof(vms_vector), N_controlcen_guns, fp );
409 //@@cfread( controlcen_gun_dirs, sizeof(vms_vector), N_controlcen_guns, fp );
411 if (Piggy_hamfile_version < 3) {
412 exit_modelnum = cfile_read_int(fp);
413 destroyed_exit_modelnum = cfile_read_int(fp);
415 exit_modelnum = N_polygon_models++;
416 destroyed_exit_modelnum = N_polygon_models++;
417 Polygon_models[exit_modelnum].model_data = NULL;
418 Polygon_models[destroyed_exit_modelnum].model_data = NULL;
422 #define D1_MAX_TEXTURES 800
423 #define D1_MAX_SOUNDS 250
424 #define D1_MAX_VCLIPS 70
425 #define D1_MAX_EFFECTS 60
426 #define D1_MAX_WALL_ANIMS 30
427 #define D1_MAX_ROBOT_TYPES 30
428 #define D1_MAX_ROBOT_JOINTS 600
429 #define D1_MAX_WEAPON_TYPES 30
430 #define D1_MAX_POWERUP_TYPES 29
431 #define D1_MAX_GAUGE_BMS 80
432 #define D1_MAX_OBJ_BITMAPS 210
433 #define D1_MAX_COCKPIT_BITMAPS 4
434 #define D1_MAX_OBJTYPE 100
435 #define D1_MAX_POLYGON_MODELS 85
437 #define D1_TMAP_INFO_SIZE 26
438 #define D1_VCLIP_SIZE 66
439 #define D1_ROBOT_INFO_SIZE 486
440 #define D1_WEAPON_INFO_SIZE 115
442 #define D1_LAST_STATIC_TMAP_NUM 324
444 // store the Textures[] array as read from the descent 2 pig.
445 short *d2_Textures_backup = NULL;
447 void undo_bm_read_all_d1() {
448 if (d2_Textures_backup) {
450 for (i = 0; i < D1_LAST_STATIC_TMAP_NUM; i++)
451 Textures[i].index = d2_Textures_backup[i];
452 d_free(d2_Textures_backup);
453 d2_Textures_backup = NULL;
458 * used by piggy_d1_init to read in descent 1 pigfile
460 void bm_read_all_d1(CFILE * fp)
464 atexit(undo_bm_read_all_d1);
466 /*NumTextures = */ cfile_read_int(fp);
467 //bitmap_index_read_n(Textures, D1_MAX_TEXTURES, fp );
468 //for (i = 0; i < D1_MAX_TEXTURES; i++)
469 // Textures[i].index = cfile_read_short(fp) + 600;
470 //cfseek(fp, D1_MAX_TEXTURES * sizeof(short), SEEK_CUR);
471 MALLOC(d2_Textures_backup, short, D1_LAST_STATIC_TMAP_NUM);
472 for (i = 0; i < D1_LAST_STATIC_TMAP_NUM; i++) {
473 d2_Textures_backup[i] = Textures[i].index;
474 Textures[i].index = cfile_read_short(fp) + 521;
476 cfseek(fp, (D1_MAX_TEXTURES - D1_LAST_STATIC_TMAP_NUM) * sizeof(short), SEEK_CUR);
478 //tmap_info_read_n_d1(TmapInfo, D1_MAX_TEXTURES, fp);
479 cfseek(fp, D1_MAX_TEXTURES * D1_TMAP_INFO_SIZE, SEEK_CUR);
482 cfread( Sounds, sizeof(ubyte), D1_MAX_SOUNDS, fp );
483 cfread( AltSounds, sizeof(ubyte), D1_MAX_SOUNDS, fp );
484 */cfseek(fp, D1_MAX_SOUNDS * 2, SEEK_CUR);
486 /*Num_vclips = */ cfile_read_int(fp);
487 //vclip_read_n(Vclip, D1_MAX_VCLIPS, fp);
488 cfseek(fp, D1_MAX_VCLIPS * D1_VCLIP_SIZE, SEEK_CUR);
491 Num_effects = cfile_read_int(fp);
492 eclip_read_n(Effects, D1_MAX_EFFECTS, fp);
494 Num_wall_anims = cfile_read_int(fp);
495 wclip_read_n_d1(WallAnims, D1_MAX_WALL_ANIMS, fp);
499 N_robot_types = cfile_read_int(fp);
500 //robot_info_read_n(Robot_info, D1_MAX_ROBOT_TYPES, fp);
501 cfseek(fp, D1_MAX_ROBOT_TYPES * D1_ROBOT_INFO_SIZE, SEEK_CUR);
503 N_robot_joints = cfile_read_int(fp);
504 jointpos_read_n(Robot_joints, D1_MAX_ROBOT_JOINTS, fp);
506 N_weapon_types = cfile_read_int(fp);
507 //weapon_info_read_n(Weapon_info, D1_MAX_WEAPON_TYPES, fp, Piggy_hamfile_version);
508 cfseek(fp, D1_MAX_WEAPON_TYPES * D1_WEAPON_INFO_SIZE, SEEK_CUR);
510 N_powerup_types = cfile_read_int(fp);
511 powerup_type_info_read_n(Powerup_info, D1_MAX_POWERUP_TYPES, fp);
514 /* in the following code are bugs, solved by hack
515 N_polygon_models = cfile_read_int(fp);
516 polymodel_read_n(Polygon_models, N_polygon_models, fp);
517 for (i=0; i<N_polygon_models; i++ )
518 polygon_model_data_read(&Polygon_models[i], fp);
519 */cfseek(fp, 521490-160, SEEK_SET); // OK, I admit, this is a dirty hack
520 //bitmap_index_read_n(Gauges, D1_MAX_GAUGE_BMS, fp);
521 cfseek(fp, D1_MAX_GAUGE_BMS * sizeof(bitmap_index), SEEK_CUR);
524 for (i = 0; i < D1_MAX_POLYGON_MODELS; i++)
525 Dying_modelnums[i] = cfile_read_int(fp);
526 for (i = 0; i < D1_MAX_POLYGON_MODELS; i++)
527 Dead_modelnums[i] = cfile_read_int(fp);
528 */ cfseek(fp, D1_MAX_POLYGON_MODELS * 8, SEEK_CUR);
530 //bitmap_index_read_n(ObjBitmaps, D1_MAX_OBJ_BITMAPS, fp);
531 cfseek(fp, D1_MAX_OBJ_BITMAPS * sizeof(bitmap_index), SEEK_CUR);
532 for (i = 0; i < D1_MAX_OBJ_BITMAPS; i++)
533 cfseek(fp, 2, SEEK_CUR);//ObjBitmapPtrs[i] = cfile_read_short(fp);
535 //player_ship_read(&only_player_ship, fp);
536 cfseek(fp, sizeof(player_ship), SEEK_CUR);
538 /*Num_cockpits = */ cfile_read_int(fp);
539 //bitmap_index_read_n(cockpit_bitmap, D1_MAX_COCKPIT_BITMAPS, fp);
540 cfseek(fp, D1_MAX_COCKPIT_BITMAPS * sizeof(bitmap_index), SEEK_CUR);
543 cfread( Sounds, sizeof(ubyte), D1_MAX_SOUNDS, fp );
544 cfread( AltSounds, sizeof(ubyte), D1_MAX_SOUNDS, fp );
545 */cfseek(fp, D1_MAX_SOUNDS * 2, SEEK_CUR);
547 /*Num_total_object_types = */ cfile_read_int( fp );
549 cfread( ObjType, sizeof(byte), D1_MAX_OBJTYPE, fp );
550 cfread( ObjId, sizeof(byte), D1_MAX_OBJTYPE, fp );
551 for (i=0; i<D1_MAX_OBJTYPE; i++ )
552 ObjStrength[i] = cfile_read_int( fp );
553 */ cfseek(fp, D1_MAX_OBJTYPE * 6, SEEK_CUR);
555 /*First_multi_bitmap_num =*/ cfile_read_int(fp);
556 /*Reactors[0].n_guns = */ cfile_read_int( fp );
557 /*for (i=0; i<4; i++)
558 cfile_read_vector(&(Reactors[0].gun_points[i]), fp);
560 cfile_read_vector(&(Reactors[0].gun_dirs[i]), fp);
561 */cfseek(fp, 8 * 12, SEEK_CUR);
563 /*exit_modelnum = */ cfile_read_int(fp);
564 /*destroyed_exit_modelnum = */ cfile_read_int(fp);
567 //these values are the number of each item in the release of d2
568 //extra items added after the release get written in an additional hamfile
569 #define N_D2_ROBOT_TYPES 66
570 #define N_D2_ROBOT_JOINTS 1145
571 #define N_D2_POLYGON_MODELS 166 + 2 // add 2 for exit models
572 #define N_D2_OBJBITMAPS 422
573 #define N_D2_OBJBITMAPPTRS 502
574 #define N_D2_WEAPON_TYPES 62
576 void bm_free_extra_robots()
578 while (N_polygon_models > N_D2_POLYGON_MODELS)
579 free_model(&Polygon_models[--N_polygon_models]);
582 //type==1 means 1.1, type==2 means 1.2 (with weapons)
583 void bm_read_extra_robots(char *fname,int type)
589 fp = cfopen(fname,"rb");
594 sig = cfile_read_int(fp);
595 if (sig != MAKE_SIG('X','H','A','M'))
597 version = cfile_read_int(fp);
602 bm_free_extra_robots();
606 t = cfile_read_int(fp);
607 N_weapon_types = N_D2_WEAPON_TYPES+t;
608 if (N_weapon_types >= MAX_WEAPON_TYPES)
609 Error("Too many weapons (%d) in <%s>. Max is %d.",t,fname,MAX_WEAPON_TYPES-N_D2_WEAPON_TYPES);
610 weapon_info_read_n(&Weapon_info[N_D2_WEAPON_TYPES], t, fp, 3);
612 //now read robot info
614 t = cfile_read_int(fp);
615 N_robot_types = N_D2_ROBOT_TYPES+t;
616 if (N_robot_types >= MAX_ROBOT_TYPES)
617 Error("Too many robots (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_TYPES-N_D2_ROBOT_TYPES);
618 robot_info_read_n(&Robot_info[N_D2_ROBOT_TYPES], t, fp);
620 t = cfile_read_int(fp);
621 N_robot_joints = N_D2_ROBOT_JOINTS+t;
622 if (N_robot_joints >= MAX_ROBOT_JOINTS)
623 Error("Too many robot joints (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_JOINTS-N_D2_ROBOT_JOINTS);
624 jointpos_read_n(&Robot_joints[N_D2_ROBOT_JOINTS], t, fp);
626 t = cfile_read_int(fp);
627 N_polygon_models = N_D2_POLYGON_MODELS+t;
628 if (N_polygon_models >= MAX_POLYGON_MODELS)
629 Error("Too many polygon models (%d) in <%s>. Max is %d.",t,fname,MAX_POLYGON_MODELS-N_D2_POLYGON_MODELS);
630 polymodel_read_n(&Polygon_models[N_D2_POLYGON_MODELS], t, fp);
632 for (i=N_D2_POLYGON_MODELS; i<N_polygon_models; i++ )
633 polygon_model_data_read(&Polygon_models[i], fp);
635 for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++)
636 Dying_modelnums[i] = cfile_read_int(fp);
637 for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++)
638 Dead_modelnums[i] = cfile_read_int(fp);
640 t = cfile_read_int(fp);
641 if (N_D2_OBJBITMAPS+t >= MAX_OBJ_BITMAPS)
642 Error("Too many object bitmaps (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPS);
643 bitmap_index_read_n(&ObjBitmaps[N_D2_OBJBITMAPS], t, fp);
645 t = cfile_read_int(fp);
646 if (N_D2_OBJBITMAPPTRS+t >= MAX_OBJ_BITMAPS)
647 Error("Too many object bitmap pointers (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPPTRS);
648 for (i = N_D2_OBJBITMAPPTRS; i < (N_D2_OBJBITMAPPTRS + t); i++)
649 ObjBitmapPtrs[i] = cfile_read_short(fp);
654 extern void change_filename_extension( char *dest, char *src, char *new_ext );
656 int Robot_replacements_loaded = 0;
658 void load_robot_replacements(char *level_name)
662 char ifile_name[FILENAME_LEN];
664 change_filename_extension(ifile_name, level_name, ".HXM" );
666 fp = cfopen(ifile_name,"rb");
668 if (!fp) //no robot replacement file
671 t = cfile_read_int(fp); //read id "HXM!"
673 Error("ID of HXM! file incorrect");
675 t = cfile_read_int(fp); //read version
677 Error("HXM! version too old (%d)",t);
679 t = cfile_read_int(fp); //read number of robots
681 i = cfile_read_int(fp); //read robot number
682 if (i<0 || i>=N_robot_types)
683 Error("Robots number (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_robot_types-1);
684 robot_info_read_n(&Robot_info[i], 1, fp);
687 t = cfile_read_int(fp); //read number of joints
689 i = cfile_read_int(fp); //read joint number
690 if (i<0 || i>=N_robot_joints)
691 Error("Robots joint (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_robot_joints-1);
692 jointpos_read_n(&Robot_joints[i], 1, fp);
695 t = cfile_read_int(fp); //read number of polygon models
698 i = cfile_read_int(fp); //read model number
699 if (i<0 || i>=N_polygon_models)
700 Error("Polygon model (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_polygon_models-1);
701 polymodel_read(&Polygon_models[i], fp);
703 free_model(&Polygon_models[i]);
704 polygon_model_data_read(&Polygon_models[i], fp);
706 Dying_modelnums[i] = cfile_read_int(fp);
707 Dead_modelnums[i] = cfile_read_int(fp);
710 t = cfile_read_int(fp); //read number of objbitmaps
712 i = cfile_read_int(fp); //read objbitmap number
713 if (i<0 || i>=MAX_OBJ_BITMAPS)
714 Error("Object bitmap number (%d) out of range in (%s). Range = [0..%d].",i,level_name,MAX_OBJ_BITMAPS-1);
715 bitmap_index_read(&ObjBitmaps[i], fp);
718 t = cfile_read_int(fp); //read number of objbitmapptrs
720 i = cfile_read_int(fp); //read objbitmapptr number
721 if (i<0 || i>=MAX_OBJ_BITMAPS)
722 Error("Object bitmap pointer (%d) out of range in (%s). Range = [0..%d].",i,level_name,MAX_OBJ_BITMAPS-1);
723 ObjBitmapPtrs[i] = cfile_read_short(fp);