1 /* $Id: bm.c,v 1.19 2002-10-28 20:57:11 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.
60 ubyte Sounds[MAX_SOUNDS];
61 ubyte AltSounds[MAX_SOUNDS];
64 int Num_total_object_types;
65 byte ObjType[MAX_OBJTYPE];
66 byte ObjId[MAX_OBJTYPE];
67 fix ObjStrength[MAX_OBJTYPE];
70 //for each model, a model number for dying & dead variants, or -1 if none
71 int Dying_modelnums[MAX_POLYGON_MODELS];
72 int Dead_modelnums[MAX_POLYGON_MODELS];
74 //the polygon model number to use for the marker
75 int Marker_model_num = -1;
77 //right now there's only one player ship, but we can have another by
78 //adding an array and setting the pointer to the active ship.
79 player_ship only_player_ship,*Player_ship=&only_player_ship;
81 //----------------- Miscellaneous bitmap pointers ---------------
83 bitmap_index cockpit_bitmap[N_COCKPIT_BITMAPS];
85 //---------------- Variables for wall textures ------------------
87 tmap_info TmapInfo[MAX_TEXTURES];
89 //---------------- Variables for object textures ----------------
91 int First_multi_bitmap_num=-1;
94 bitmap_index ObjBitmaps[MAX_OBJ_BITMAPS];
95 ushort ObjBitmapPtrs[MAX_OBJ_BITMAPS]; // These point back into ObjBitmaps, since some are used twice.
98 #define tmap_info_read_n(ti, n, fp) cfread(ti, sizeof(tmap_info), n, fp)
101 * reads n tmap_info structs from a CFILE
103 int tmap_info_read_n(tmap_info *ti, int n, CFILE *fp)
107 for (i = 0; i < n; i++) {
108 ti[i].flags = cfile_read_byte(fp);
109 ti[i].pad[0] = cfile_read_byte(fp);
110 ti[i].pad[1] = cfile_read_byte(fp);
111 ti[i].pad[2] = cfile_read_byte(fp);
112 ti[i].lighting = cfile_read_fix(fp);
113 ti[i].damage = cfile_read_fix(fp);
114 ti[i].eclip_num = cfile_read_short(fp);
115 ti[i].destroyed = cfile_read_short(fp);
116 ti[i].slide_u = cfile_read_short(fp);
117 ti[i].slide_v = cfile_read_short(fp);
123 extern int Num_bitmap_files;
124 int extra_bitmap_num;
126 bitmap_index exitmodel_bm_load_sub( char * filename )
128 bitmap_index bitmap_num;
129 grs_bitmap * new = &GameBitmaps[extra_bitmap_num];
131 int iff_error; //reference parm to avoid warning message
133 bitmap_num.index = 0;
135 //MALLOC( new, grs_bitmap, 1 );
136 iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal);
138 if (iff_error != IFF_NO_ERROR) {
139 Error("Error loading exit model bitmap <%s> - IFF error: %s",filename,iff_errormsg(iff_error));
142 if ( iff_has_transparency )
143 gr_remap_bitmap_good( new, newpal, iff_transparent_color, 254 );
145 gr_remap_bitmap_good( new, newpal, -1, 254 );
147 new->avg_color = 0; //compute_average_pixel(new);
149 bitmap_num.index = extra_bitmap_num;
151 GameBitmaps[extra_bitmap_num++] = *new;
157 grs_bitmap *load_exit_model_bitmap(char *name)
159 Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS);
162 ObjBitmaps[N_ObjBitmaps] = exitmodel_bm_load_sub(name);
163 if (GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_w!=64 || GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_h!=64)
164 Error("Bitmap <%s> is not 64x64",name);
165 ObjBitmapPtrs[N_ObjBitmaps] = N_ObjBitmaps;
167 Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS);
168 return &GameBitmaps[ObjBitmaps[N_ObjBitmaps-1].index];
173 free_exit_model_data()
177 for (i = Num_bitmap_files; i < extra_bitmap_num; i++)
178 d_free(GameBitmaps[i].bm_data);
179 extra_bitmap_num = Num_bitmap_files;
184 void ogl_cache_polymodel_textures(int model_num);
187 void load_exit_models()
192 if (!cfexist("steel1.bbm") ||
193 !cfexist("rbot061.bbm") ||
194 !cfexist("rbot062.bbm") ||
195 !cfexist("rbot063.bbm")) {
196 Warning("Can't load exit models!\n");
200 start_num = N_ObjBitmaps;
201 extra_bitmap_num = Num_bitmap_files;
202 load_exit_model_bitmap("steel1.bbm");
203 load_exit_model_bitmap("rbot061.bbm");
204 load_exit_model_bitmap("rbot062.bbm");
206 load_exit_model_bitmap("steel1.bbm");
207 load_exit_model_bitmap("rbot061.bbm");
208 load_exit_model_bitmap("rbot063.bbm");
210 if (cfexist("exit.ham")) {
212 exit_hamfile = cfopen("exit.ham","rb");
214 exit_hamfile = cfopen(":Data:exit.ham","rb");
217 exit_modelnum = N_polygon_models++;
218 destroyed_exit_modelnum = N_polygon_models++;
219 polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile);
220 polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile);
221 Polygon_models[exit_modelnum].first_texture = start_num;
222 Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3;
224 Polygon_models[exit_modelnum].model_data = d_malloc(Polygon_models[exit_modelnum].model_data_size);
225 Assert( Polygon_models[exit_modelnum].model_data != NULL );
226 cfread( Polygon_models[exit_modelnum].model_data, sizeof(ubyte), Polygon_models[exit_modelnum].model_data_size, exit_hamfile );
227 swap_polygon_model_data(Polygon_models[exit_modelnum].model_data);
228 g3_init_polygon_model(Polygon_models[exit_modelnum].model_data);
230 Polygon_models[destroyed_exit_modelnum].model_data = d_malloc(Polygon_models[destroyed_exit_modelnum].model_data_size);
231 Assert( Polygon_models[destroyed_exit_modelnum].model_data != NULL );
232 cfread( Polygon_models[destroyed_exit_modelnum].model_data, sizeof(ubyte), Polygon_models[destroyed_exit_modelnum].model_data_size, exit_hamfile );
233 swap_polygon_model_data(Polygon_models[destroyed_exit_modelnum].model_data);
234 g3_init_polygon_model(Polygon_models[destroyed_exit_modelnum].model_data);
235 cfclose(exit_hamfile);
237 } else if (cfexist("exit01.pof") && cfexist("exit01d.pof")) {
239 exit_modelnum = load_polygon_model("exit01.pof", 3, start_num, NULL);
240 destroyed_exit_modelnum = load_polygon_model("exit01d.pof", 3, start_num + 3, NULL);
243 ogl_cache_polymodel_textures(exit_modelnum);
244 ogl_cache_polymodel_textures(destroyed_exit_modelnum);
248 Warning("Can't load exit models!\n");
252 //-----------------------------------------------------------------
253 // Read data from piggy.
254 // This is called when the editor is OUT.
255 // If editor is in, bm_init_use_table() is called.
258 init_polygon_models();
259 if (! piggy_init()) // This calls bm_read_all
260 Error("Cannot open pig and/or ham file");
264 init_endlevel(); //this is in bm_init_use_tbl(), so I gues it goes here
269 void bm_read_all(CFILE * fp)
273 NumTextures = cfile_read_int(fp);
274 bitmap_index_read_n(Textures, NumTextures, fp );
275 tmap_info_read_n(TmapInfo, NumTextures, fp);
277 t = cfile_read_int(fp);
278 cfread( Sounds, sizeof(ubyte), t, fp );
279 cfread( AltSounds, sizeof(ubyte), t, fp );
281 Num_vclips = cfile_read_int(fp);
282 vclip_read_n(Vclip, Num_vclips, fp);
284 Num_effects = cfile_read_int(fp);
285 eclip_read_n(Effects, Num_effects, fp);
287 Num_wall_anims = cfile_read_int(fp);
288 wclip_read_n(WallAnims, Num_wall_anims, fp);
290 N_robot_types = cfile_read_int(fp);
291 robot_info_read_n(Robot_info, N_robot_types, fp);
293 N_robot_joints = cfile_read_int(fp);
294 jointpos_read_n(Robot_joints, N_robot_joints, fp);
296 N_weapon_types = cfile_read_int(fp);
297 weapon_info_read_n(Weapon_info, N_weapon_types, fp, Piggy_hamfile_version);
299 N_powerup_types = cfile_read_int(fp);
300 powerup_type_info_read_n(Powerup_info, N_powerup_types, fp);
302 N_polygon_models = cfile_read_int(fp);
303 polymodel_read_n(Polygon_models, N_polygon_models, fp);
305 for (i=0; i<N_polygon_models; i++ ) {
306 Polygon_models[i].model_data = d_malloc(Polygon_models[i].model_data_size);
307 Assert( Polygon_models[i].model_data != NULL );
308 cfread( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
309 swap_polygon_model_data(Polygon_models[i].model_data);
310 g3_init_polygon_model(Polygon_models[i].model_data);
313 for (i = 0; i < N_polygon_models; i++)
314 Dying_modelnums[i] = cfile_read_int(fp);
315 for (i = 0; i < N_polygon_models; i++)
316 Dead_modelnums[i] = cfile_read_int(fp);
318 t = cfile_read_int(fp);
319 bitmap_index_read_n(Gauges, t, fp);
320 bitmap_index_read_n(Gauges_hires, t, fp);
322 N_ObjBitmaps = cfile_read_int(fp);
323 bitmap_index_read_n(ObjBitmaps, N_ObjBitmaps, fp);
324 for (i = 0; i < N_ObjBitmaps; i++)
325 ObjBitmapPtrs[i] = cfile_read_short(fp);
327 player_ship_read(&only_player_ship, fp);
329 Num_cockpits = cfile_read_int(fp);
330 bitmap_index_read_n(cockpit_bitmap, Num_cockpits, fp);
332 //@@ cfread( &Num_total_object_types, sizeof(int), 1, fp );
333 //@@ cfread( ObjType, sizeof(byte), Num_total_object_types, fp );
334 //@@ cfread( ObjId, sizeof(byte), Num_total_object_types, fp );
335 //@@ cfread( ObjStrength, sizeof(fix), Num_total_object_types, fp );
337 First_multi_bitmap_num = cfile_read_int(fp);
339 Num_reactors = cfile_read_int(fp);
340 reactor_read_n(Reactors, Num_reactors, fp);
342 Marker_model_num = cfile_read_int(fp);
344 //@@cfread( &N_controlcen_guns, sizeof(int), 1, fp );
345 //@@cfread( controlcen_gun_points, sizeof(vms_vector), N_controlcen_guns, fp );
346 //@@cfread( controlcen_gun_dirs, sizeof(vms_vector), N_controlcen_guns, fp );
348 if (Piggy_hamfile_version < 3) {
349 exit_modelnum = cfile_read_int(fp);
350 destroyed_exit_modelnum = cfile_read_int(fp);
356 //these values are the number of each item in the release of d2
357 //extra items added after the release get written in an additional hamfile
358 #define N_D2_ROBOT_TYPES 66
359 #define N_D2_ROBOT_JOINTS 1145
360 #define N_D2_POLYGON_MODELS 166
361 #define N_D2_OBJBITMAPS 422
362 #define N_D2_OBJBITMAPPTRS 502
363 #define N_D2_WEAPON_TYPES 62
365 //type==1 means 1.1, type==2 means 1.2 (with weapons)
366 void bm_read_extra_robots(char *fname,int type)
372 fp = cfopen(fname,"rb");
377 sig = cfile_read_int(fp);
378 if (sig != MAKE_SIG('X','H','A','M'))
380 version = cfile_read_int(fp);
387 t = cfile_read_int(fp);
388 N_weapon_types = N_D2_WEAPON_TYPES+t;
389 if (N_weapon_types >= MAX_WEAPON_TYPES)
390 Error("Too many weapons (%d) in <%s>. Max is %d.",t,fname,MAX_WEAPON_TYPES-N_D2_WEAPON_TYPES);
391 weapon_info_read_n(&Weapon_info[N_D2_WEAPON_TYPES], t, fp, 3);
393 //now read robot info
395 t = cfile_read_int(fp);
396 N_robot_types = N_D2_ROBOT_TYPES+t;
397 if (N_robot_types >= MAX_ROBOT_TYPES)
398 Error("Too many robots (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_TYPES-N_D2_ROBOT_TYPES);
399 robot_info_read_n(&Robot_info[N_D2_ROBOT_TYPES], t, fp);
401 t = cfile_read_int(fp);
402 N_robot_joints = N_D2_ROBOT_JOINTS+t;
403 if (N_robot_joints >= MAX_ROBOT_JOINTS)
404 Error("Too many robot joints (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_JOINTS-N_D2_ROBOT_JOINTS);
405 jointpos_read_n(&Robot_joints[N_D2_ROBOT_JOINTS], t, fp);
407 t = cfile_read_int(fp);
408 N_polygon_models = N_D2_POLYGON_MODELS+t;
409 if (N_polygon_models >= MAX_POLYGON_MODELS)
410 Error("Too many polygon models (%d) in <%s>. Max is %d.",t,fname,MAX_POLYGON_MODELS-N_D2_POLYGON_MODELS);
411 polymodel_read_n(&Polygon_models[N_D2_POLYGON_MODELS], t, fp);
413 for (i=N_D2_POLYGON_MODELS; i<N_polygon_models; i++ )
415 Polygon_models[i].model_data = d_malloc(Polygon_models[i].model_data_size);
416 Assert( Polygon_models[i].model_data != NULL );
417 cfread( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
418 swap_polygon_model_data(Polygon_models[i].model_data);
419 g3_init_polygon_model(Polygon_models[i].model_data);
422 for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++)
423 Dying_modelnums[i] = cfile_read_int(fp);
424 for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++)
425 Dead_modelnums[i] = cfile_read_int(fp);
427 t = cfile_read_int(fp);
428 if (N_D2_OBJBITMAPS+t >= MAX_OBJ_BITMAPS)
429 Error("Too many object bitmaps (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPS);
430 bitmap_index_read_n(&ObjBitmaps[N_D2_OBJBITMAPS], t, fp);
432 t = cfile_read_int(fp);
433 if (N_D2_OBJBITMAPPTRS+t >= MAX_OBJ_BITMAPS)
434 Error("Too many object bitmap pointers (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPPTRS);
435 for (i = N_D2_OBJBITMAPPTRS; i < (N_D2_OBJBITMAPPTRS + t); i++)
436 ObjBitmapPtrs[i] = cfile_read_short(fp);
441 extern void change_filename_extension( char *dest, char *src, char *new_ext );
443 int Robot_replacements_loaded = 0;
445 void load_robot_replacements(char *level_name)
449 char ifile_name[FILENAME_LEN];
451 change_filename_extension(ifile_name, level_name, ".HXM" );
453 fp = cfopen(ifile_name,"rb");
455 if (!fp) //no robot replacement file
458 t = cfile_read_int(fp); //read id "HXM!"
460 Error("ID of HXM! file incorrect");
462 t = cfile_read_int(fp); //read version
464 Error("HXM! version too old (%d)",t);
466 t = cfile_read_int(fp); //read number of robots
468 i = cfile_read_int(fp); //read robot number
469 if (i<0 || i>=N_robot_types)
470 Error("Robots number (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_robot_types-1);
471 robot_info_read_n(&Robot_info[i], 1, fp);
474 t = cfile_read_int(fp); //read number of joints
476 i = cfile_read_int(fp); //read joint number
477 if (i<0 || i>=N_robot_joints)
478 Error("Robots joint (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_robot_joints-1);
479 jointpos_read_n(&Robot_joints[i], 1, fp);
482 t = cfile_read_int(fp); //read number of polygon models
485 i = cfile_read_int(fp); //read model number
486 if (i<0 || i>=N_polygon_models)
487 Error("Polygon model (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_polygon_models-1);
488 polymodel_read(&Polygon_models[i], fp);
490 d_free(Polygon_models[i].model_data);
491 Polygon_models[i].model_data = d_malloc(Polygon_models[i].model_data_size);
492 Assert( Polygon_models[i].model_data != NULL );
494 cfread( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
495 swap_polygon_model_data(Polygon_models[i].model_data);
496 g3_init_polygon_model(Polygon_models[i].model_data);
498 Dying_modelnums[i] = cfile_read_int(fp);
499 Dead_modelnums[i] = cfile_read_int(fp);
502 t = cfile_read_int(fp); //read number of objbitmaps
504 i = cfile_read_int(fp); //read objbitmap number
505 if (i<0 || i>=MAX_OBJ_BITMAPS)
506 Error("Object bitmap number (%d) out of range in (%s). Range = [0..%d].",i,level_name,MAX_OBJ_BITMAPS-1);
507 bitmap_index_read(&ObjBitmaps[i], fp);
510 t = cfile_read_int(fp); //read number of objbitmapptrs
512 i = cfile_read_int(fp); //read objbitmapptr number
513 if (i<0 || i>=MAX_OBJ_BITMAPS)
514 Error("Object bitmap pointer (%d) out of range in (%s). Range = [0..%d].",i,level_name,MAX_OBJ_BITMAPS-1);
515 ObjBitmapPtrs[i] = cfile_read_short(fp);