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++;
188 polymodel_read(&Polygon_models[exit_modelnum], exit_hamfile);
189 polymodel_read(&Polygon_models[destroyed_exit_modelnum], exit_hamfile);
190 #ifdef MACINTOSH //not sure what these are for
191 Polygon_models[exit_modelnum].first_texture = start_num;
192 Polygon_models[destroyed_exit_modelnum].first_texture = start_num+3;
195 Polygon_models[exit_modelnum].model_data = d_malloc(Polygon_models[exit_modelnum].model_data_size);
196 Assert( Polygon_models[exit_modelnum].model_data != NULL );
197 cfread( Polygon_models[exit_modelnum].model_data, sizeof(ubyte), Polygon_models[exit_modelnum].model_data_size, exit_hamfile );
198 #ifdef WORDS_BIGENDIAN
199 swap_polygon_model_data(Polygon_models[exit_modelnum].model_data);
201 g3_init_polygon_model(Polygon_models[exit_modelnum].model_data);
203 Polygon_models[destroyed_exit_modelnum].model_data = d_malloc(Polygon_models[destroyed_exit_modelnum].model_data_size);
204 Assert( Polygon_models[destroyed_exit_modelnum].model_data != NULL );
205 cfread( Polygon_models[destroyed_exit_modelnum].model_data, sizeof(ubyte), Polygon_models[destroyed_exit_modelnum].model_data_size, exit_hamfile );
206 #ifdef WORDS_BIGENDIAN
207 swap_polygon_model_data(Polygon_models[destroyed_exit_modelnum].model_data);
209 g3_init_polygon_model(Polygon_models[destroyed_exit_modelnum].model_data);
211 cfclose(exit_hamfile);
218 //-----------------------------------------------------------------
219 // Read data from piggy.
220 // This is called when the editor is OUT.
221 // If editor is in, bm_init_use_table() is called.
224 init_polygon_models();
225 if (! piggy_init()) // This calls bm_read_all
226 Error("Cannot open pig and/or ham file");
231 init_endlevel(); //this is in bm_init_use_tbl(), so I gues it goes here
237 void bm_read_all(CFILE * fp)
241 NumTextures = cfile_read_int(fp);
242 for (i = 0; i < NumTextures; i++)
243 bitmap_index_read(&Textures[i], fp);
244 for (i = 0; i < NumTextures; i++)
245 tmap_info_read(&TmapInfo[i], fp);
247 t = cfile_read_int(fp);
248 cfread( Sounds, sizeof(ubyte), t, fp );
249 cfread( AltSounds, sizeof(ubyte), t, fp );
251 Num_vclips = cfile_read_int(fp);
252 for (i = 0; i < Num_vclips; i++)
253 vclip_read(&Vclip[i], fp);
255 Num_effects = cfile_read_int(fp);
256 for (i = 0; i < Num_effects; i++)
257 eclip_read(&Effects[i], fp);
259 Num_wall_anims = cfile_read_int(fp);
260 for (i = 0; i < Num_wall_anims; i++)
261 wclip_read(&WallAnims[i], fp);
263 N_robot_types = cfile_read_int(fp);
264 for (i = 0; i < N_robot_types; i++)
265 robot_info_read(&Robot_info[i], fp);
267 N_robot_joints = cfile_read_int(fp);
268 for (i = 0; i < N_robot_joints; i++)
269 jointpos_read(&Robot_joints[i], fp);
271 N_weapon_types = cfile_read_int(fp);
272 for (i = 0; i < N_weapon_types; i++)
273 weapon_info_read(&Weapon_info[i], fp);
275 N_powerup_types = cfile_read_int(fp);
276 for (i = 0; i < N_powerup_types; i++)
277 powerup_type_info_read(&Powerup_info[i], fp);
279 N_polygon_models = cfile_read_int(fp);
280 for (i = 0; i < N_polygon_models; i++)
281 polymodel_read(&Polygon_models[i], fp);
283 for (i=0; i<N_polygon_models; i++ ) {
284 Polygon_models[i].model_data = d_malloc(Polygon_models[i].model_data_size);
285 Assert( Polygon_models[i].model_data != NULL );
286 cfread( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
287 #ifdef WORDS_BIGENDIAN
288 swap_polygon_model_data(Polygon_models[i].model_data);
290 g3_init_polygon_model(Polygon_models[i].model_data);
293 for (i = 0; i < N_polygon_models; i++)
294 Dying_modelnums[i] = cfile_read_int(fp);
295 for (i = 0; i < N_polygon_models; i++)
296 Dead_modelnums[i] = cfile_read_int(fp);
298 t = cfile_read_int(fp);
299 for (i = 0; i < t; i++)
300 bitmap_index_read(&Gauges[i], fp);
301 for (i = 0; i < t; i++)
302 bitmap_index_read(&Gauges_hires[i], fp);
304 t = cfile_read_int(fp);
305 for (i = 0; i < t; i++)
306 bitmap_index_read(&ObjBitmaps[i], fp);
307 for (i = 0; i < t; i++)
308 ObjBitmapPtrs[i] = cfile_read_short(fp);
314 player_ship_read(&only_player_ship, fp);
316 Num_cockpits = cfile_read_int(fp);
317 for (i = 0; i < Num_cockpits; i++)
318 bitmap_index_read(&cockpit_bitmap[i], fp);
320 //@@ cfread( &Num_total_object_types, sizeof(int), 1, fp );
321 //@@ cfread( ObjType, sizeof(byte), Num_total_object_types, fp );
322 //@@ cfread( ObjId, sizeof(byte), Num_total_object_types, fp );
323 //@@ cfread( ObjStrength, sizeof(fix), Num_total_object_types, fp );
325 First_multi_bitmap_num = cfile_read_int(fp);
327 Num_reactors = cfile_read_int(fp);
328 for (i = 0; i < Num_reactors; i++)
329 reactor_read(&Reactors[i], fp);
331 Marker_model_num = cfile_read_int(fp);
333 //@@cfread( &N_controlcen_guns, sizeof(int), 1, fp );
334 //@@cfread( controlcen_gun_points, sizeof(vms_vector), N_controlcen_guns, fp );
335 //@@cfread( controlcen_gun_dirs, sizeof(vms_vector), N_controlcen_guns, fp );
338 exit_modelnum = cfile_read_int(fp);
339 destroyed_exit_modelnum = cfile_read_int(fp);
345 //these values are the number of each item in the release of d2
346 //extra items added after the release get written in an additional hamfile
347 #define N_D2_ROBOT_TYPES 66
348 #define N_D2_ROBOT_JOINTS 1145
349 #define N_D2_POLYGON_MODELS 166
350 #define N_D2_OBJBITMAPS 422
351 #define N_D2_OBJBITMAPPTRS 502
352 #define N_D2_WEAPON_TYPES 62
354 //type==1 means 1.1, type==2 means 1.2 (with weaons)
355 void bm_read_extra_robots(char *fname,int type)
365 fp = cfopen(fname,"rb");
370 sig = cfile_read_int(fp);
371 if (sig != MAKE_SIG('X','H','A','M'))
373 version = cfile_read_int(fp);
380 t = cfile_read_int(fp);
381 N_weapon_types = N_D2_WEAPON_TYPES+t;
382 if (N_weapon_types >= MAX_WEAPON_TYPES)
383 Error("Too many weapons (%d) in <%s>. Max is %d.",t,fname,MAX_WEAPON_TYPES-N_D2_WEAPON_TYPES);
384 for (i = N_D2_WEAPON_TYPES; i < t + N_D2_WEAPON_TYPES; i++)
385 weapon_info_read(&Weapon_info[i], fp);
387 //now read robot info
389 t = cfile_read_int(fp);
390 N_robot_types = N_D2_ROBOT_TYPES+t;
391 if (N_robot_types >= MAX_ROBOT_TYPES)
392 Error("Too many robots (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_TYPES-N_D2_ROBOT_TYPES);
393 for (i = N_D2_ROBOT_TYPES; i < t + N_D2_ROBOT_TYPES; i++)
394 robot_info_read(&Robot_info[i], fp);
396 t = cfile_read_int(fp);
397 N_robot_joints = N_D2_ROBOT_JOINTS+t;
398 if (N_robot_joints >= MAX_ROBOT_JOINTS)
399 Error("Too many robot joints (%d) in <%s>. Max is %d.",t,fname,MAX_ROBOT_JOINTS-N_D2_ROBOT_JOINTS);
400 for (i = N_D2_ROBOT_JOINTS; i < t + N_D2_ROBOT_JOINTS; i++)
401 jointpos_read(&Robot_joints[i], fp);
403 t = cfile_read_int(fp);
404 N_polygon_models = N_D2_POLYGON_MODELS+t;
405 if (N_polygon_models >= MAX_POLYGON_MODELS)
406 Error("Too many polygon models (%d) in <%s>. Max is %d.",t,fname,MAX_POLYGON_MODELS-N_D2_POLYGON_MODELS);
407 for (i = N_D2_POLYGON_MODELS; i < t + N_D2_POLYGON_MODELS; i++)
408 polymodel_read(&Polygon_models[i], fp);
410 for (i=N_D2_POLYGON_MODELS; i<N_polygon_models; i++ )
412 Polygon_models[i].model_data = d_malloc(Polygon_models[i].model_data_size);
413 Assert( Polygon_models[i].model_data != NULL );
414 cfread( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
416 #ifdef WORDS_BIGENDIAN
417 swap_polygon_model_data(Polygon_models[i].model_data);
420 g3_init_polygon_model(Polygon_models[i].model_data);
423 for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++)
424 Dying_modelnums[i] = cfile_read_int(fp);
425 for (i = N_D2_POLYGON_MODELS; i < N_polygon_models; i++)
426 Dead_modelnums[i] = cfile_read_int(fp);
428 t = cfile_read_int(fp);
429 if (N_D2_OBJBITMAPS+t >= MAX_OBJ_BITMAPS)
430 Error("Too many object bitmaps (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPS);
431 for (i = N_D2_OBJBITMAPS; i < (N_D2_OBJBITMAPS + t); i++)
432 bitmap_index_read(&ObjBitmaps[i], fp);
434 t = cfile_read_int(fp);
435 if (N_D2_OBJBITMAPPTRS+t >= MAX_OBJ_BITMAPS)
436 Error("Too many object bitmap pointers (%d) in <%s>. Max is %d.",t,fname,MAX_OBJ_BITMAPS-N_D2_OBJBITMAPPTRS);
437 for (i = N_D2_OBJBITMAPPTRS; i < (N_D2_OBJBITMAPPTRS + t); i++)
438 ObjBitmapPtrs[i] = cfile_read_short(fp);
443 extern void change_filename_extension( char *dest, char *src, char *new_ext );
445 int Robot_replacements_loaded = 0;
447 void load_robot_replacements(char *level_name)
451 char ifile_name[FILENAME_LEN];
453 change_filename_extension(ifile_name, level_name, ".HXM" );
455 fp = cfopen(ifile_name,"rb");
457 if (!fp) //no robot replacement file
460 t = cfile_read_int(fp); //read id "HXM!"
462 Error("ID of HXM! file incorrect");
464 t = cfile_read_int(fp); //read version
466 Error("HXM! version too old (%d)",t);
468 t = cfile_read_int(fp); //read number of robots
470 i = cfile_read_int(fp); //read robot number
471 if (i<0 || i>=N_robot_types)
472 Error("Robots number (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_robot_types-1);
473 robot_info_read(&Robot_info[i], fp);
476 t = cfile_read_int(fp); //read number of joints
478 i = cfile_read_int(fp); //read joint number
479 if (i<0 || i>=N_robot_joints)
480 Error("Robots joint (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_robot_joints-1);
481 jointpos_read(&Robot_joints[i], fp);
484 t = cfile_read_int(fp); //read number of polygon models
487 i = cfile_read_int(fp); //read model number
488 if (i<0 || i>=N_polygon_models)
489 Error("Polygon model (%d) out of range in (%s). Range = [0..%d].",i,level_name,N_polygon_models-1);
490 polymodel_read(&Polygon_models[i], fp);
492 d_free(Polygon_models[i].model_data);
493 Polygon_models[i].model_data = d_malloc(Polygon_models[i].model_data_size);
494 Assert( Polygon_models[i].model_data != NULL );
496 cfread( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
497 #ifdef WORDS_BIGENDIAN
498 swap_polygon_model_data(Polygon_models[i].model_data);
500 g3_init_polygon_model(Polygon_models[i].model_data);
502 Dying_modelnums[i] = cfile_read_int(fp);
503 Dead_modelnums[i] = cfile_read_int(fp);
506 t = cfile_read_int(fp); //read number of objbitmaps
508 i = cfile_read_int(fp); //read objbitmap number
509 if (i<0 || i>=MAX_OBJ_BITMAPS)
510 Error("Object bitmap number (%d) out of range in (%s). Range = [0..%d].",i,level_name,MAX_OBJ_BITMAPS-1);
511 bitmap_index_read(&ObjBitmaps[i], fp);
514 t = cfile_read_int(fp); //read number of objbitmapptrs
516 i = cfile_read_int(fp); //read objbitmapptr number
517 if (i<0 || i>=MAX_OBJ_BITMAPS)
518 Error("Object bitmap pointer (%d) out of range in (%s). Range = [0..%d].",i,level_name,MAX_OBJ_BITMAPS-1);
519 ObjBitmapPtrs[i] = cfile_read_short(fp);