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.
61 ubyte Sounds[MAX_SOUNDS];
62 ubyte AltSounds[MAX_SOUNDS];
65 int Num_total_object_types;
66 byte ObjType[MAX_OBJTYPE];
67 byte ObjId[MAX_OBJTYPE];
68 fix ObjStrength[MAX_OBJTYPE];
71 //for each model, a model number for dying & dead variants, or -1 if none
72 int Dying_modelnums[MAX_POLYGON_MODELS];
73 int Dead_modelnums[MAX_POLYGON_MODELS];
75 //the polygon model number to use for the marker
76 int Marker_model_num = -1;
78 //right now there's only one player ship, but we can have another by
79 //adding an array and setting the pointer to the active ship.
80 player_ship only_player_ship,*Player_ship=&only_player_ship;
82 //----------------- Miscellaneous bitmap pointers ---------------
84 bitmap_index cockpit_bitmap[N_COCKPIT_BITMAPS];
86 //---------------- Variables for wall textures ------------------
88 tmap_info TmapInfo[MAX_TEXTURES];
90 //---------------- Variables for object textures ----------------
92 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 * reads a tmap_info structure from a CFILE
100 void tmap_info_read(tmap_info *ti, CFILE *fp)
102 ti->flags = cfile_read_byte(fp);
103 ti->pad[0] = cfile_read_byte(fp);
104 ti->pad[1] = cfile_read_byte(fp);
105 ti->pad[2] = cfile_read_byte(fp);
106 ti->lighting = cfile_read_fix(fp);
107 ti->damage = cfile_read_fix(fp);
108 ti->eclip_num = cfile_read_short(fp);
109 ti->destroyed = cfile_read_short(fp);
110 ti->slide_u = cfile_read_short(fp);
111 ti->slide_v = cfile_read_short(fp);
117 extern int exit_modelnum,destroyed_exit_modelnum, Num_bitmap_files;
118 int N_ObjBitmaps, extra_bitmap_num;
120 bitmap_index exitmodel_bm_load_sub( char * filename )
122 bitmap_index bitmap_num;
125 int i, iff_error; //reference parm to avoid warning message
127 bitmap_num.index = 0;
129 MALLOC( new, grs_bitmap, 1 );
130 iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal);
132 if (iff_error != IFF_NO_ERROR) {
133 Error("Error loading exit model bitmap <%s> - IFF error: %s",filename,iff_errormsg(iff_error));
136 if ( iff_has_transparency )
137 gr_remap_bitmap_good( new, newpal, iff_transparent_color, 254 );
139 gr_remap_bitmap_good( new, newpal, -1, 254 );
141 new->avg_color = 0; //compute_average_pixel(new);
143 bitmap_num.index = extra_bitmap_num;
145 GameBitmaps[extra_bitmap_num++] = *new;
151 grs_bitmap *load_exit_model_bitmap(char *name)
153 Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS);
156 ObjBitmaps[N_ObjBitmaps] = exitmodel_bm_load_sub(name);
157 if (GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_w!=64 || GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_h!=64)
158 Error("Bitmap <%s> is not 64x64",name);
159 ObjBitmapPtrs[N_ObjBitmaps] = N_ObjBitmaps;
161 Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS);
162 return &GameBitmaps[ObjBitmaps[N_ObjBitmaps-1].index];
166 void load_exit_models()
173 start_num = N_ObjBitmaps;
174 extra_bitmap_num = Num_bitmap_files;
175 load_exit_model_bitmap("steel1.bbm");
176 load_exit_model_bitmap("rbot061.bbm");
177 load_exit_model_bitmap("rbot062.bbm");
179 load_exit_model_bitmap("steel1.bbm");
180 load_exit_model_bitmap("rbot061.bbm");
181 load_exit_model_bitmap("rbot063.bbm");
183 exit_hamfile = cfopen(":Data:exit.ham","rb");
185 exit_modelnum = N_polygon_models++;
186 destroyed_exit_modelnum = N_polygon_models++;
189 cfread( &Polygon_models[exit_modelnum], sizeof(polymodel), 1, exit_hamfile );
190 cfread( &Polygon_models[destroyed_exit_modelnum], sizeof(polymodel), 1, exit_hamfile );
192 for (i = exit_modelnum; i <= destroyed_exit_modelnum; i++) {
193 Polygon_models[i].n_models = cfile_read_int(exit_hamfile);
194 Polygon_models[i].model_data_size = cfile_read_int(exit_hamfile);
195 Polygon_models[i].model_data = (ubyte *)read_int_swap(exit_hamfile);
196 for (j = 0; j < MAX_SUBMODELS; j++)
197 Polygon_models[i].submodel_ptrs[j] = cfile_read_int(exit_hamfile);
198 for (j = 0; j < MAX_SUBMODELS; j++)
199 cfile_read_vector(&(Polygon_models[i].submodel_offsets), exit_hamfile);
200 for (j = 0; j < MAX_SUBMODELS; j++)
201 cfile_read_vector(&(Polygon_models[i].submodel_norms), exit_hamfile);
202 for (j = 0; j < MAX_SUBMODELS; j++)
203 cfile_read_vector(&(Polygon_models[i].submodel_pnts), exit_hamfile);
204 for (j = 0; j < MAX_SUBMODELS; j++)
205 Polygon_models[i].submodel_rads[j] = cfile_read_fix(exit_hamfile);
206 for (j = 0; j < MAX_SUBMODELS; j++)
207 Polygon_models[i].submodel_parents[j] = cfile_read_byte(exit_hamfile);
208 for (j = 0; j < MAX_SUBMODELS; j++)
209 cfile_read_vector(&(Polygon_models[i].submodel_mins), exit_hamfile);
210 for (j = 0; j < MAX_SUBMODELS; j++)
211 cfile_read_vector(&(Polygon_models[i].submodel_maxs), exit_hamfile);
212 cfile_read_vector(&(Polygon_models[i].mins), exit_hamfile);
213 cfile_read_vector(&(Polygon_models[i].maxs), exit_hamfile);
214 Polygon_models[i].rad = cfile_read_fix(exit_hamfile);
215 Polygon_models[i].n_textures = cfile_read_byte(exit_hamfile);
216 Polygon_models[i].first_texture = cfile_read_short(exit_hamfile);
217 Polygon_models[i].simpler_model = cfile_read_byte(exit_hamfile);
219 Polygon_models[exit_modelnum].first_texture = start_num;
220 Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3;
223 Polygon_models[exit_modelnum].model_data = d_malloc(Polygon_models[exit_modelnum].model_data_size);
224 Assert( Polygon_models[exit_modelnum].model_data != NULL );
225 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);
229 g3_init_polygon_model(Polygon_models[exit_modelnum].model_data);
231 Polygon_models[destroyed_exit_modelnum].model_data = d_malloc(Polygon_models[destroyed_exit_modelnum].model_data_size);
232 Assert( Polygon_models[destroyed_exit_modelnum].model_data != NULL );
233 cfread( Polygon_models[destroyed_exit_modelnum].model_data, sizeof(ubyte), Polygon_models[destroyed_exit_modelnum].model_data_size, exit_hamfile );
235 swap_polygon_model_data(Polygon_models[destroyed_exit_modelnum].model_data);
237 g3_init_polygon_model(Polygon_models[destroyed_exit_modelnum].model_data);
239 cfclose(exit_hamfile);
246 //-----------------------------------------------------------------
247 // Read data from piggy.
248 // This is called when the editor is OUT.
249 // If editor is in, bm_init_use_table() is called.
252 init_polygon_models();
253 if (! piggy_init()) // This calls bm_read_all
254 Error("Cannot open pig and/or ham file");
259 init_endlevel(); //this is in bm_init_use_tbl(), so I gues it goes here
265 void bm_read_all(CFILE * fp)
269 NumTextures = cfile_read_int(fp);
270 for (i = 0; i < NumTextures; i++)
271 bitmap_index_read(&Textures[i], fp);
272 for (i = 0; i < NumTextures; i++)
273 tmap_info_read(&TmapInfo[i], fp);
275 t = cfile_read_int(fp);
276 cfread( Sounds, sizeof(ubyte), t, fp );
277 cfread( AltSounds, sizeof(ubyte), t, fp );
279 Num_vclips = cfile_read_int(fp);
280 for (i = 0; i < Num_vclips; i++)
281 vclip_read(&Vclip[i], fp);
283 Num_effects = cfile_read_int(fp);
284 for (i = 0; i < Num_effects; i++)
285 eclip_read(&Effects[i], fp);
287 Num_wall_anims = cfile_read_int(fp);
288 for (i = 0; i < Num_wall_anims; i++)
289 wclip_read(&WallAnims[i], fp);
291 N_robot_types = cfile_read_int(fp);
292 for (i = 0; i < N_robot_types; i++)
293 robot_info_read(&Robot_info[i], fp);
295 N_robot_joints = cfile_read_int(fp);
296 for (i = 0; i < N_robot_joints; i++)
297 jointpos_read(&Robot_joints[i], fp);
299 N_weapon_types = cfile_read_int(fp);
300 for (i = 0; i < N_weapon_types; i++)
301 weapon_info_read(&Weapon_info[i], fp);
303 N_powerup_types = cfile_read_int(fp);
304 for (i = 0; i < N_powerup_types; i++)
305 powerup_type_info_read(&Powerup_info[i], fp);
307 N_polygon_models = cfile_read_int(fp);
308 for (i = 0; i < N_polygon_models; i++)
309 polymodel_read(&Polygon_models[i], fp);
311 for (i=0; i<N_polygon_models; i++ ) {
312 Polygon_models[i].model_data = d_malloc(Polygon_models[i].model_data_size);
313 Assert( Polygon_models[i].model_data != NULL );
314 cfread( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
315 #ifdef WORDS_BIGENDIAN
316 swap_polygon_model_data(Polygon_models[i].model_data);
318 g3_init_polygon_model(Polygon_models[i].model_data);
321 for (i = 0; i < N_polygon_models; i++)
322 Dying_modelnums[i] = cfile_read_int(fp);
323 for (i = 0; i < N_polygon_models; i++)
324 Dead_modelnums[i] = cfile_read_int(fp);
326 t = cfile_read_int(fp);
327 for (i = 0; i < t; i++)
328 bitmap_index_read(&Gauges[i], fp);
329 for (i = 0; i < t; i++)
330 bitmap_index_read(&Gauges_hires[i], fp);
332 t = cfile_read_int(fp);
333 for (i = 0; i < t; i++)
334 bitmap_index_read(&ObjBitmaps[i], fp);
335 for (i = 0; i < t; i++)
336 ObjBitmapPtrs[i] = cfile_read_short(fp);
342 player_ship_read(&only_player_ship, fp);
344 Num_cockpits = cfile_read_int(fp);
345 for (i = 0; i < Num_cockpits; i++)
346 bitmap_index_read(&cockpit_bitmap[i], fp);
348 //@@ cfread( &Num_total_object_types, sizeof(int), 1, fp );
349 //@@ cfread( ObjType, sizeof(byte), Num_total_object_types, fp );
350 //@@ cfread( ObjId, sizeof(byte), Num_total_object_types, fp );
351 //@@ cfread( ObjStrength, sizeof(fix), Num_total_object_types, fp );
353 First_multi_bitmap_num = cfile_read_int(fp);
355 Num_reactors = cfile_read_int(fp);
356 for (i = 0; i < Num_reactors; i++)
357 reactor_read(&Reactors[i], fp);
359 Marker_model_num = cfile_read_int(fp);
361 //@@cfread( &N_controlcen_guns, sizeof(int), 1, fp );
362 //@@cfread( controlcen_gun_points, sizeof(vms_vector), N_controlcen_guns, fp );
363 //@@cfread( controlcen_gun_dirs, sizeof(vms_vector), N_controlcen_guns, fp );
366 exit_modelnum = cfile_read_int(fp);
367 destroyed_exit_modelnum = cfile_read_int(fp);
373 //these values are the number of each item in the release of d2
374 //extra items added after the release get written in an additional hamfile
375 #define N_D2_ROBOT_TYPES 66
376 #define N_D2_ROBOT_JOINTS 1145
377 #define N_D2_POLYGON_MODELS 166
378 #define N_D2_OBJBITMAPS 422
379 #define N_D2_OBJBITMAPPTRS 502
380 #define N_D2_WEAPON_TYPES 62
382 //type==1 means 1.1, type==2 means 1.2 (with weaons)
383 void bm_read_extra_robots(char *fname,int type)
393 fp = cfopen(fname,"rb");
398 sig = cfile_read_int(fp);
399 if (sig != MAKE_SIG('X','H','A','M'))
401 version = cfile_read_int(fp);
408 t = cfile_read_int(fp);
409 N_weapon_types = N_D2_WEAPON_TYPES+t;
410 if (N_weapon_types >= MAX_WEAPON_TYPES)
411 Error("Too many weapons (%d) in <%s>. Max is %d.",t,fname,MAX_WEAPON_TYPES-N_D2_WEAPON_TYPES);
412 for (i = N_D2_WEAPON_TYPES; i < t + N_D2_WEAPON_TYPES; i++)
413 weapon_info_read(&Weapon_info[i], fp);
415 //now read robot info
417 t = cfile_read_int(fp);
418 N_robot_types = N_D2_ROBOT_TYPES+t;
419 if (N_robot_types >= MAX_ROBOT_TYPES)
420 Error("Too many robots (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_TYPES-N_D2_ROBOT_TYPES);
421 for (i = N_D2_ROBOT_TYPES; i < t + N_D2_ROBOT_TYPES; i++)
422 robot_info_read(&Robot_info[i], fp);
424 t = cfile_read_int(fp);
425 N_robot_joints = N_D2_ROBOT_JOINTS+t;
426 if (N_robot_joints >= MAX_ROBOT_JOINTS)
427 Error("Too many robot joints (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_JOINTS-N_D2_ROBOT_JOINTS);
428 for (i = N_D2_ROBOT_JOINTS; i < t + N_D2_ROBOT_JOINTS; i++)
429 jointpos_read(&Robot_joints[i], fp);
431 t = cfile_read_int(fp);
432 N_polygon_models = N_D2_POLYGON_MODELS+t;
433 if (N_polygon_models >= MAX_POLYGON_MODELS)
434 Error("Too many polygon models (%d) in <%s>. Max is %d.",t,fname,MAX_POLYGON_MODELS-N_D2_POLYGON_MODELS);
435 for (i = N_D2_POLYGON_MODELS; i < t + N_D2_POLYGON_MODELS; i++)
436 polymodel_read(&Polygon_models[i], fp);
438 for (i=N_D2_POLYGON_MODELS; i<N_polygon_models; i++ )
440 Polygon_models[i].model_data = d_malloc(Polygon_models[i].model_data_size);
441 Assert( Polygon_models[i].model_data != NULL );
442 cfread( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
444 #ifdef WORDS_BIGENDIAN
445 swap_polygon_model_data(Polygon_models[i].model_data);
448 g3_init_polygon_model(Polygon_models[i].model_data);
451 for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++)
452 Dying_modelnums[i] = cfile_read_int(fp);
453 for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++)
454 Dead_modelnums[i] = cfile_read_int(fp);
456 t = cfile_read_int(fp);
457 if (N_D2_OBJBITMAPS+t >= MAX_OBJ_BITMAPS)
458 Error("Too many object bitmaps (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPS);
459 for (i = N_D2_OBJBITMAPS; i < (N_D2_OBJBITMAPS + t); i++)
460 bitmap_index_read(&ObjBitmaps[i], fp);
462 t = cfile_read_int(fp);
463 if (N_D2_OBJBITMAPPTRS+t >= MAX_OBJ_BITMAPS)
464 Error("Too many object bitmap pointers (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPPTRS);
465 for (i = N_D2_OBJBITMAPPTRS; i < (N_D2_OBJBITMAPPTRS + t); i++)
466 ObjBitmapPtrs[i] = cfile_read_short(fp);
471 extern void change_filename_extension( char *dest, char *src, char *new_ext );
473 int Robot_replacements_loaded = 0;
475 void load_robot_replacements(char *level_name)
479 char ifile_name[FILENAME_LEN];
481 change_filename_extension(ifile_name, level_name, ".HXM" );
483 fp = cfopen(ifile_name,"rb");
485 if (!fp) //no robot replacement file
488 t = cfile_read_int(fp); //read id "HXM!"
490 Error("ID of HXM! file incorrect");
492 t = cfile_read_int(fp); //read version
494 Error("HXM! version too old (%d)",t);
496 t = cfile_read_int(fp); //read number of robots
498 i = cfile_read_int(fp); //read robot number
499 if (i<0 || i>=N_robot_types)
500 Error("Robots number (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_robot_types-1);
501 robot_info_read(&Robot_info[i], fp);
504 t = cfile_read_int(fp); //read number of joints
506 i = cfile_read_int(fp); //read joint number
507 if (i<0 || i>=N_robot_joints)
508 Error("Robots joint (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_robot_joints-1);
509 jointpos_read(&Robot_joints[i], fp);
512 t = cfile_read_int(fp); //read number of polygon models
515 i = cfile_read_int(fp); //read model number
516 if (i<0 || i>=N_polygon_models)
517 Error("Polygon model (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_polygon_models-1);
518 polymodel_read(&Polygon_models[i], fp);
520 d_free(Polygon_models[i].model_data);
521 Polygon_models[i].model_data = d_malloc(Polygon_models[i].model_data_size);
522 Assert( Polygon_models[i].model_data != NULL );
524 cfread( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
525 #ifdef WORDS_BIGENDIAN
526 swap_polygon_model_data(Polygon_models[i].model_data);
528 g3_init_polygon_model(Polygon_models[i].model_data);
530 Dying_modelnums[i] = cfile_read_int(fp);
531 Dead_modelnums[i] = cfile_read_int(fp);
534 t = cfile_read_int(fp); //read number of objbitmaps
536 i = cfile_read_int(fp); //read objbitmap number
537 if (i<0 || i>=MAX_OBJ_BITMAPS)
538 Error("Object bitmap number (%d) out of range in (%s). Range = [0..%d].",i,level_name,MAX_OBJ_BITMAPS-1);
539 bitmap_index_read(&ObjBitmaps[i], fp);
542 t = cfile_read_int(fp); //read number of objbitmapptrs
544 i = cfile_read_int(fp); //read objbitmapptr number
545 if (i<0 || i>=MAX_OBJ_BITMAPS)
546 Error("Object bitmap pointer (%d) out of range in (%s). Range = [0..%d].",i,level_name,MAX_OBJ_BITMAPS-1);
547 ObjBitmapPtrs[i] = cfile_read_short(fp);