This commit was generated by cvs2svn to compensate for changes in r2,
[btb/d2x.git] / main / bmread.c
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14
15 #ifdef RCS
16 char bmread_rcsid[] = "$Id: bmread.c,v 1.1.1.1 2001-01-19 03:30:01 bradleyb Exp $";
17 #endif
18
19 #include <conf.h>
20
21 #ifdef EDITOR
22
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <ctype.h>
29
30 #include "pstypes.h"
31 #include "inferno.h"
32 #include "gr.h"
33 #include "bm.h"
34 #include "gamepal.h"
35 #include "mem.h"
36 #include "mono.h"
37 #include "error.h"
38 #include "object.h"
39 #include "vclip.h"
40 #include "effects.h"
41 #include "polyobj.h"
42 #include "wall.h"
43 #include "textures.h"
44 #include "game.h"
45 #include "multi.h"
46
47 #include "iff.h"
48 #include "cfile.h"
49
50 #include "hostage.h"
51 #include "powerup.h"
52 #include "laser.h"
53 #include "sounds.h"
54 #include "piggy.h"
55 #include "aistruct.h"
56 #include "robot.h"
57 #include "weapon.h"
58 #include "gauges.h"
59 #include "player.h"
60 #include "endlevel.h"
61 #include "cntrlcen.h"
62 #include "compbit.h"
63 #include "args.h"
64
65
66 #include "editor\texpage.h"
67
68 #define BM_NONE                 -1
69 #define BM_COCKPIT               0
70 #define BM_TEXTURES              2
71 #define BM_UNUSED                        3
72 #define BM_VCLIP                         4
73 #define BM_EFFECTS          5
74 #define BM_ECLIP                         6
75 #define BM_WEAPON                        7
76 #define BM_DEMO                  8
77 #define BM_ROBOTEX          9
78 #define BM_WALL_ANIMS   12
79 #define BM_WCLIP                        13
80 #define BM_ROBOT                        14
81 #define BM_GAUGES                       20
82 #define BM_GAUGES_HIRES 21
83
84 #define MAX_BITMAPS_PER_BRUSH 30
85
86 extern player_ship only_player_ship;            // In bm.c
87
88 short           N_ObjBitmaps=0;
89 short           N_ObjBitmapPtrs=0;
90 static int                      Num_robot_ais = 0;
91 int     TmapList[MAX_TEXTURES];
92 char    Powerup_names[MAX_POWERUP_TYPES][POWERUP_NAME_LENGTH];
93 char    Robot_names[MAX_ROBOT_TYPES][ROBOT_NAME_LENGTH];
94
95 //---------------- Internal variables ---------------------------
96 static int                      Registered_only = 0;            //      Gets set by ! in column 1.
97 static int                      SuperX = -1;
98 static int                      Installed=0;
99 static char             *arg;
100 static short            tmap_count = 0;
101 static short            texture_count = 0;
102 static short            clip_count = 0;
103 static short            clip_num;
104 static short            sound_num;
105 static short            frames;
106 static float            time;
107 static int                      hit_sound = -1;
108 static byte             bm_flag = BM_NONE;
109 static int                      abm_flag = 0;
110 static int                      rod_flag = 0;
111 static short            wall_open_sound, wall_close_sound,wall_explodes,wall_blastable, wall_hidden;
112 float           vlighting=0;
113 static int                      obj_eclip;
114 static char             *dest_bm;               //clip number to play when destroyed
115 static int                      dest_vclip;             //what vclip to play when exploding
116 static int                      dest_eclip;             //what eclip to play when exploding
117 static fix                      dest_size;              //3d size of explosion
118 static int                      crit_clip;              //clip number to play when destroyed
119 static int                      crit_flag;              //flag if this is a destroyed eclip
120 static int                      tmap1_flag;             //flag if this is used as tmap_num (not tmap_num2)
121 static int                      num_sounds=0;
122
123 int     linenum;                //line int table currently being parsed
124
125 //------------------- Useful macros and variables ---------------
126 #define REMOVE_EOL(s)           remove_char((s),'\n')
127 #define REMOVE_COMMENTS(s)      remove_char((s),';')
128 #define REMOVE_DOTS(s)          remove_char((s),'.')
129
130 #define IFTOK(str) if (!strcmp(arg, str))
131 char *space = { " \t" };        
132 //--unused-- char *equal = { "=" };
133 char *equal_space = { " \t=" };
134
135
136 //      For the sake of LINT, defining prototypes to module's functions
137 void bm_read_robot_ai(void);
138 void bm_read_powerup(int unused_flag);
139 void bm_read_hostage(void);
140 void bm_read_robot(void);
141 void bm_read_weapon(int unused_flag);
142 void bm_read_reactor(void);
143 void bm_read_exitmodel(void);
144 void bm_read_player_ship(void);
145 void bm_read_some_file(void);
146 void bm_read_sound(void);
147 void verify_textures(void);
148
149
150 //----------------------------------------------------------------------
151 void remove_char( char * s, char c )
152 {
153         char *p;
154         p = strchr(s,c);
155         if (p) *p = '\0';
156 }
157
158 //---------------------------------------------------------------
159 int compute_average_pixel(grs_bitmap *new)
160 {
161         int     row, column, color;
162         char    *pptr;
163         int     total_red, total_green, total_blue;
164
165         pptr = (char *)new->bm_data;
166
167         total_red = 0;
168         total_green = 0;
169         total_blue = 0;
170
171         for (row=0; row<new->bm_h; row++)
172                 for (column=0; column<new->bm_w; column++) {
173                         color = *pptr++;
174                         total_red += gr_palette[color*3];
175                         total_green += gr_palette[color*3+1];
176                         total_blue += gr_palette[color*3+2];
177                 }
178
179         total_red /= (new->bm_h * new->bm_w);
180         total_green /= (new->bm_h * new->bm_w);
181         total_blue /= (new->bm_h * new->bm_w);
182
183         return BM_XRGB(total_red/2, total_green/2, total_blue/2);
184 }
185
186 //---------------------------------------------------------------
187 // Loads a bitmap from either the piggy file, a r64 file, or a
188 // whatever extension is passed.
189
190 bitmap_index bm_load_sub( char * filename )
191 {
192         bitmap_index bitmap_num;
193         grs_bitmap * new;
194         ubyte newpal[256*3];
195         int iff_error;          //reference parm to avoid warning message
196         char fname[20];
197
198         bitmap_num.index = 0;
199
200 #ifdef SHAREWARE
201         if (Registered_only) {
202                 //mprintf( 0, "Skipping registered-only bitmap '%s'\n", filename );
203                 return bitmap_num;
204         }
205 #endif
206
207         _splitpath(  filename, NULL, NULL, fname, NULL );
208
209         bitmap_num=piggy_find_bitmap( fname );
210         if (bitmap_num.index)   {
211                 //mprintf(( 0, "Found bitmap '%s' in pig!\n", fname ));
212                 return bitmap_num;
213         }
214    
215         MALLOC( new, grs_bitmap, 1 );
216         iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal);
217         new->bm_handle=0;
218         if (iff_error != IFF_NO_ERROR)          {
219                 mprintf((1, "File %s - IFF error: %s",filename,iff_errormsg(iff_error)));
220                 Error("File <%s> - IFF error: %s, line %d",filename,iff_errormsg(iff_error),linenum);
221         }
222
223         if ( iff_has_transparency )
224                 gr_remap_bitmap_good( new, newpal, iff_transparent_color, SuperX );
225         else
226                 gr_remap_bitmap_good( new, newpal, -1, SuperX );
227
228         new->avg_color = compute_average_pixel(new);
229
230         // -- mprintf((0, "N" ));
231         bitmap_num = piggy_register_bitmap( new, fname, 0 );
232         d_free( new );
233         return bitmap_num;
234 }
235
236 extern grs_bitmap bogus_bitmap;
237 extern ubyte bogus_bitmap_initialized;
238 extern digi_sound bogus_sound;
239
240 void ab_load( char * filename, bitmap_index bmp[], int *nframes )
241 {
242         grs_bitmap * bm[MAX_BITMAPS_PER_BRUSH];
243         bitmap_index bi;
244         int i;
245         int iff_error;          //reference parm to avoid warning message
246         ubyte newpal[768];
247         char fname[20];
248         char tempname[20];
249
250 #ifdef SHAREWARE
251         if (Registered_only) {
252                 Assert( bogus_bitmap_initialized != 0 );
253                 mprintf(( 0, "Skipping registered-only animation '%s'\n", filename ));
254                 bmp[0].index = 0;               //index of bogus bitmap==0 (I think)            //&bogus_bitmap;
255                 *nframes = 1;
256                 return;
257         }
258 #endif
259
260
261         _splitpath( filename, NULL, NULL, fname, NULL );
262         
263         for (i=0; i<MAX_BITMAPS_PER_BRUSH; i++ )        {
264                 sprintf( tempname, "%s#%d", fname, i );
265                 bi = piggy_find_bitmap( tempname );
266                 if ( !bi.index )        
267                         break;
268                 bmp[i] = bi;
269                 //mprintf(( 0, "Found animation frame %d, %s, in piggy file\n", i, tempname ));
270         }
271
272         if (i) {
273                 *nframes = i;
274                 return;
275         }
276
277 //      Note that last argument passes an address to the array newpal (which is a pointer).
278 //      type mismatch found using lint, will substitute this line with an adjusted
279 //      one.  If fatal error, then it can be easily changed.
280 //      iff_error = iff_read_animbrush(filename,bm,MAX_BITMAPS_PER_BRUSH,nframes,&newpal);
281    iff_error = iff_read_animbrush(filename,bm,MAX_BITMAPS_PER_BRUSH,nframes,newpal);
282         if (iff_error != IFF_NO_ERROR)  {
283                 mprintf((1,"File %s - IFF error: %s",filename,iff_errormsg(iff_error)));
284                 Error("File <%s> - IFF error: %s, line %d",filename,iff_errormsg(iff_error),linenum);
285         }
286
287         for (i=0;i< *nframes; i++)      {
288                 bitmap_index new_bmp;
289                 sprintf( tempname, "%s#%d", fname, i );
290                 if ( iff_has_transparency )
291                         gr_remap_bitmap_good( bm[i], newpal, iff_transparent_color, SuperX );
292                 else
293                         gr_remap_bitmap_good( bm[i], newpal, -1, SuperX );
294
295                 bm[i]->avg_color = compute_average_pixel(bm[i]);
296
297                 new_bmp = piggy_register_bitmap( bm[i], tempname, 0 );
298                 d_free( bm[i] );
299                 bmp[i] = new_bmp;
300                 if (!i)
301                         mprintf((0, "Registering %s in piggy file.", tempname ));
302                 else
303                         mprintf((0, "."));
304         }
305         mprintf((0, "\n"));
306 }
307
308 int ds_load( char * filename )  {
309         int i;
310         CFILE * cfp;
311         digi_sound new;
312         char fname[20];
313         char rawname[100];
314
315 #ifdef SHAREWARE
316         if (Registered_only) {
317                 //mprintf( 0, "Skipping registered-only sound '%s'\n", filename );
318                 return 0;       //don't know what I should return here          //&bogus_sound;
319         }
320 #endif
321
322         _splitpath(  filename, NULL, NULL, fname, NULL );
323         _makepath( rawname, NULL, NULL,fname, (digi_sample_rate==SAMPLE_RATE_22K)?".R22":".RAW" );
324
325         i=piggy_find_sound( fname );
326         if (i!=255)     {
327                 return i;
328         }
329
330         cfp = cfopen( rawname, "rb" );
331
332         if (cfp!=NULL) {
333                 new.length      = cfilelength( cfp );
334                 MALLOC( new.data, ubyte, new.length );
335                 cfread( new.data, 1, new.length, cfp );
336                 cfclose(cfp);
337                 // -- mprintf( (0, "S" ));
338                 // -- mprintf( (0, "<%s>", rawname ));
339         } else {
340                 mprintf( (1, "Warning: Couldn't find '%s'\n", filename ));
341                 return 255;
342         }
343         i = piggy_register_sound( &new, fname, 0 );
344         return i;
345 }
346
347 //parse a float
348 float get_float()
349 {
350         char *xarg;
351
352         xarg = strtok( NULL, space );
353         return atof( xarg );
354 }
355
356 //parse an int
357 int get_int()
358 {
359         char *xarg;
360
361         xarg = strtok( NULL, space );
362         return atoi( xarg );
363 }
364
365 // rotates a byte left one bit, preserving the bit falling off the right
366 //void
367 //rotate_left(char *c)
368 //{
369 //      int found;
370 //
371 //      found = 0;
372 //      if (*c & 0x80)
373 //              found = 1;
374 //      *c = *c << 1;
375 //      if (found)
376 //              *c |= 0x01;
377 //}
378
379 //loads a texture and returns the texture num 
380 int get_texture(char *name)
381 {
382         char short_name[FILENAME_LEN];
383         int i;
384
385         strcpy(short_name,name);
386         REMOVE_DOTS(short_name);
387         for (i=0;i<texture_count;i++)
388                 if (!stricmp(TmapInfo[i].filename,short_name))
389                         break;
390         if (i==texture_count) {
391                 Textures[texture_count] = bm_load_sub(name);
392                 strcpy( TmapInfo[texture_count].filename, short_name);
393                 texture_count++;
394                 Assert(texture_count < MAX_TEXTURES);
395                 NumTextures = texture_count;
396         }
397
398         return i;
399 }
400
401 #define LINEBUF_SIZE 600
402
403 #define DEFAULT_PIG_PALETTE     "groupa.256"
404
405 //-----------------------------------------------------------------
406 // Initializes all bitmaps from BITMAPS.TBL file.
407 // This is called when the editor is IN.  
408 // If no editor, bm_init() is called.
409 int bm_init_use_tbl()
410 {
411         CFILE   * InfoFile;
412         char    inputline[LINEBUF_SIZE];
413         int     i, have_bin_tbl;
414
415         gr_use_palette_table(DEFAULT_PIG_PALETTE);
416
417         load_palette(DEFAULT_PIG_PALETTE,-2,0);         //special: tell palette code which pig is loaded
418
419         init_polygon_models();
420
421         ObjType[0] = OL_PLAYER;
422         ObjId[0] = 0;
423         Num_total_object_types = 1;
424
425         for (i=0; i<MAX_SOUNDS; i++ )   {
426                 Sounds[i] = 255;
427                 AltSounds[i] = 255;
428         }
429
430         for (i=0; i<MAX_TEXTURES; i++ ) {
431                 TmapInfo[i].eclip_num = -1;
432                 TmapInfo[i].flags = 0;
433                 TmapInfo[i].slide_u = TmapInfo[i].slide_v = 0;
434                 TmapInfo[i].destroyed = -1;
435         }
436
437         for (i=0;i<MAX_REACTORS;i++)
438                 Reactors[i].model_num = -1;
439
440         Num_effects = 0;
441         for (i=0; i<MAX_EFFECTS; i++ ) {
442                 //Effects[i].bm_ptr = (grs_bitmap **) -1;
443                 Effects[i].changing_wall_texture = -1;
444                 Effects[i].changing_object_texture = -1;
445                 Effects[i].segnum = -1;
446                 Effects[i].vc.num_frames = -1;          //another mark of being unused
447         }
448
449         for (i=0;i<MAX_POLYGON_MODELS;i++)
450                 Dying_modelnums[i] = Dead_modelnums[i] = -1;
451
452         Num_vclips = 0;
453         for (i=0; i<VCLIP_MAXNUM; i++ ) {
454                 Vclip[i].num_frames = -1;
455                 Vclip[i].flags = 0;
456         }
457
458         for (i=0; i<MAX_WALL_ANIMS; i++ )
459                 WallAnims[i].num_frames = -1;
460         Num_wall_anims = 0;
461
462         setbuf(stdout, NULL);   // unbuffered output via printf
463
464         if (Installed)
465                 return 1;
466
467         Installed = 1;
468
469         piggy_init();           //don't care about error, since no pig is ok for editor
470
471 //      if ( FindArg( "-nobm" ) )       {
472 //              piggy_read_sounds();
473 //              return 0;
474 //      }
475
476         // Open BITMAPS.TBL for reading.
477         have_bin_tbl = 0;
478         InfoFile = cfopen( "BITMAPS.TBL", "rb" );
479         if (InfoFile == NULL) {
480                 InfoFile = cfopen("BITMAPS.BIN", "rb");
481                 if (InfoFile == NULL)
482                         Error("Missing BITMAPS.TBL and BITMAPS.BIN file\n");
483                 have_bin_tbl = 1;
484         }
485         linenum = 0;
486         
487         cfseek( InfoFile, 0L, SEEK_SET);
488
489         while (cfgets(inputline, LINEBUF_SIZE, InfoFile)) {
490                 int l;
491                 char *temp_ptr;
492
493                 linenum++;
494
495                 if (inputline[0]==' ' || inputline[0]=='\t') {
496                         char *t;
497                         for (t=inputline;*t && *t!='\n';t++)
498                                 if (! (*t==' ' || *t=='\t')) { 
499                                         mprintf((1,"Suspicious: line %d of BITMAPS.TBL starts with whitespace\n",linenum));
500                                         break;
501                                 }
502                 }
503
504                 if (have_bin_tbl) {                             // is this a binary tbl file
505                         for (i = 0; i < strlen(inputline) - 1; i++) {
506                                 encode_rotate_left(&(inputline[i]));
507                                 inputline[i] = inputline[i] ^ BITMAP_TBL_XOR;
508                                 encode_rotate_left(&(inputline[i]));
509                         }
510                 } else {
511                         while (inputline[(l=strlen(inputline))-2]=='\\') {
512                                 if (!isspace(inputline[l-3])) {         //if not space before backslash...
513                                         inputline[l-2] = ' ';                           //add one
514                                         l++;
515                                 }
516                                 cfgets(inputline+l-2,LINEBUF_SIZE-(l-2), InfoFile);
517                                 linenum++;
518                         }
519                 }
520
521                 REMOVE_EOL(inputline);
522                 if (strchr(inputline, ';')!=NULL) REMOVE_COMMENTS(inputline);
523
524                 if (strlen(inputline) == LINEBUF_SIZE-1)
525                         Error("Possible line truncation in BITMAPS.TBL on line %d\n",linenum);
526
527                 SuperX = -1;
528
529                 if ( (temp_ptr=strstr( inputline, "superx=" )) )        {
530                         SuperX = atoi( &temp_ptr[7] );
531                         Assert(SuperX == 254);
532                                 //the superx color isn't kept around, so the new piggy regeneration
533                                 //code doesn't know what it is, so it assumes that it's 254, so
534                                 //this code requires that it be 254
535                                                                                 
536                 }
537
538                 arg = strtok( inputline, space );
539                 if (arg[0] == '@') {
540                         arg++;
541                         Registered_only = 1;
542                 } else
543                         Registered_only = 0;
544
545                 while (arg != NULL )
546                         {
547                         // Check all possible flags and defines.
548                         if (*arg == '$') bm_flag = BM_NONE; // reset to no flags as default.
549
550                         IFTOK("$COCKPIT")                       bm_flag = BM_COCKPIT;
551                         else IFTOK("$GAUGES")           {bm_flag = BM_GAUGES;   clip_count = 0;}
552                         else IFTOK("$GAUGES_HIRES"){bm_flag = BM_GAUGES_HIRES; clip_count = 0;}
553                         else IFTOK("$SOUND")            bm_read_sound();
554                         else IFTOK("$DOOR_ANIMS")       bm_flag = BM_WALL_ANIMS;
555                         else IFTOK("$WALL_ANIMS")       bm_flag = BM_WALL_ANIMS;
556                         else IFTOK("$TEXTURES")         bm_flag = BM_TEXTURES;
557                         else IFTOK("$VCLIP")                    {bm_flag = BM_VCLIP;            vlighting = 0;  clip_count = 0;}
558                         else IFTOK("$ECLIP")                    {bm_flag = BM_ECLIP;            vlighting = 0;  clip_count = 0; obj_eclip=0; dest_bm=NULL; dest_vclip=-1; dest_eclip=-1; dest_size=-1; crit_clip=-1; crit_flag=0; sound_num=-1;}
559                         else IFTOK("$WCLIP")                    {bm_flag = BM_WCLIP;            vlighting = 0;  clip_count = 0; wall_explodes = wall_blastable = 0; wall_open_sound=wall_close_sound=-1; tmap1_flag=0; wall_hidden=0;}
560
561                         else IFTOK("$EFFECTS")          {bm_flag = BM_EFFECTS;  clip_num = 0;}
562                         else IFTOK("$ALIAS")                    bm_read_alias();
563
564                         #ifdef EDITOR
565                         else IFTOK("!METALS_FLAG")              TextureMetals = texture_count;
566                         else IFTOK("!LIGHTS_FLAG")              TextureLights = texture_count;
567                         else IFTOK("!EFFECTS_FLAG")     TextureEffects = texture_count;
568                         #endif
569
570                         else IFTOK("lighting")                  TmapInfo[texture_count-1].lighting = fl2f(get_float());
571                         else IFTOK("damage")                    TmapInfo[texture_count-1].damage = fl2f(get_float());
572                         else IFTOK("volatile")                  TmapInfo[texture_count-1].flags |= TMI_VOLATILE;
573                         else IFTOK("goal_blue")                 TmapInfo[texture_count-1].flags |= TMI_GOAL_BLUE;
574                         else IFTOK("goal_red")                  TmapInfo[texture_count-1].flags |= TMI_GOAL_RED;
575                         else IFTOK("water")                             TmapInfo[texture_count-1].flags |= TMI_WATER;
576                         else IFTOK("force_field")               TmapInfo[texture_count-1].flags |= TMI_FORCE_FIELD;
577                         else IFTOK("slide")                             {TmapInfo[texture_count-1].slide_u = fl2f(get_float())>>8; TmapInfo[texture_count-1].slide_v = fl2f(get_float())>>8;}
578                         else IFTOK("destroyed")                 {int t=texture_count-1; TmapInfo[t].destroyed = get_texture(strtok( NULL, space ));}
579                         //else IFTOK("Num_effects")             Num_effects = get_int();
580                         else IFTOK("Num_wall_anims")    Num_wall_anims = get_int();
581                         else IFTOK("clip_num")                  clip_num = get_int();
582                         else IFTOK("dest_bm")                   dest_bm = strtok( NULL, space );
583                         else IFTOK("dest_vclip")                dest_vclip = get_int();
584                         else IFTOK("dest_eclip")                dest_eclip = get_int();
585                         else IFTOK("dest_size")                 dest_size = fl2f(get_float());
586                         else IFTOK("crit_clip")                 crit_clip = get_int();
587                         else IFTOK("crit_flag")                 crit_flag = get_int();
588                         else IFTOK("sound_num")                 sound_num = get_int();
589                         else IFTOK("frames")                    frames = get_int();
590                         else IFTOK("time")                              time = get_float();
591                         else IFTOK("obj_eclip")                 obj_eclip = get_int();
592                         else IFTOK("hit_sound")                 hit_sound = get_int();
593                         else IFTOK("abm_flag")                  abm_flag = get_int();
594                         else IFTOK("tmap1_flag")                tmap1_flag = get_int();
595                         else IFTOK("vlighting")                 vlighting = get_float();
596                         else IFTOK("rod_flag")                  rod_flag = get_int();
597                         else IFTOK("superx")                    get_int();
598                         else IFTOK("open_sound")                wall_open_sound = get_int();
599                         else IFTOK("close_sound")               wall_close_sound = get_int();
600                         else IFTOK("explodes")                  wall_explodes = get_int();
601                         else IFTOK("blastable")                 wall_blastable = get_int();
602                         else IFTOK("hidden")                            wall_hidden = get_int();
603                         else IFTOK("$ROBOT_AI")                 bm_read_robot_ai();
604
605                         else IFTOK("$POWERUP")                  {bm_read_powerup(0);            continue;}
606                         else IFTOK("$POWERUP_UNUSED")   {bm_read_powerup(1);            continue;}
607                         else IFTOK("$HOSTAGE")                  {bm_read_hostage();             continue;}
608                         else IFTOK("$ROBOT")                            {bm_read_robot();                       continue;}
609                         else IFTOK("$WEAPON")                   {bm_read_weapon(0);             continue;}
610                         else IFTOK("$WEAPON_UNUSED")    {bm_read_weapon(1);             continue;}
611                         else IFTOK("$REACTOR")                  {bm_read_reactor();             continue;}
612                         else IFTOK("$MARKER")                   {bm_read_marker();              continue;}
613                         else IFTOK("$PLAYER_SHIP")              {bm_read_player_ship(); continue;}
614                         else IFTOK("$EXIT") {
615                                 #ifdef SHAREWARE
616                                         bm_read_exitmodel();    
617                                 #else
618                                         clear_to_end_of_line();
619                                 #endif
620                                 continue;
621                         }
622                         else    {               //not a special token, must be a bitmap!
623
624                                 // Remove any illegal/unwanted spaces and tabs at this point.
625                                 while ((*arg=='\t') || (*arg==' ')) arg++;
626                                 if (*arg == '\0') { break; }    
627
628                                 //check for '=' in token, indicating error
629                                 if (strchr(arg,'='))
630                                         Error("Unknown token <'%s'> on line %d of BITMAPS.TBL",arg,linenum);
631
632                                 // Otherwise, 'arg' is apparently a bitmap filename.
633                                 // Load bitmap and process it below:
634                                 bm_read_some_file();
635
636                         }
637
638                         arg = strtok( NULL, equal_space );
639                         continue;
640       }
641         }
642
643         NumTextures = texture_count;
644         Num_tmaps = tmap_count;
645
646         Textures[NumTextures++].index = 0;              //entry for bogus tmap
647
648         cfclose( InfoFile );
649
650         atexit(bm_close);
651
652         Assert(N_robot_types == Num_robot_ais);         //should be one ai info per robot
653
654         #ifdef SHAREWARE
655         init_endlevel();                //this is here so endlevel bitmaps go into pig
656         #endif
657         
658         verify_textures();
659
660         //check for refereced but unused clip count
661         for (i=0; i<MAX_EFFECTS; i++ )
662                 if (    (
663                                   (Effects[i].changing_wall_texture!=-1) ||
664                                   (Effects[i].changing_object_texture!=-1)     
665              )
666                          && (Effects[i].vc.num_frames==-1) )
667                         Error("EClip %d referenced (by polygon object?), but not defined",i);
668
669         #ifndef NDEBUG
670         {
671                 int used;
672                 for (i=used=0; i<num_sounds; i++ )
673                         if (Sounds[i] != 255)
674                                 used++;
675                 mprintf((0,"Sound slots used: %d of %d, highest index %d\n",used,MAX_SOUNDS,num_sounds));
676
677                 //make sure all alt sounds refer to valid main sounds
678                 for (i=used=0; i<num_sounds; i++ ) {
679                         int alt = AltSounds[i];
680                         Assert(alt==0 || alt==-1 || Sounds[alt]!=255);
681                 }
682         }
683         #endif
684
685         piggy_read_sounds();
686
687         #ifdef EDITOR
688         piggy_dump_all();
689         #endif
690
691         gr_use_palette_table(DEFAULT_PALETTE);
692
693         return 0;
694 }
695
696 void verify_textures()
697 {
698         grs_bitmap * bmp;
699         int i,j;
700         j=0;
701         for (i=0; i<Num_tmaps; i++ )    {
702                 bmp = &GameBitmaps[Textures[i].index];
703                 if ( (bmp->bm_w!=64)||(bmp->bm_h!=64)||(bmp->bm_rowsize!=64) )  {
704                         mprintf( (1, "ERROR: Texture '%s' isn't 64x64 !\n", TmapInfo[i].filename ));
705                         j++;
706                 } 
707         }
708         if (j)
709                 Error("%d textures were not 64x64.  See mono screen for list.",j);
710
711         for (i=0;i<Num_effects;i++)
712                 if (Effects[i].changing_object_texture != -1)
713                         if (GameBitmaps[ObjBitmaps[Effects[i].changing_object_texture].index].bm_w!=64 || GameBitmaps[ObjBitmaps[Effects[i].changing_object_texture].index].bm_h!=64)
714                                 Error("Effect %d is used on object, but is not 64x64",i);
715
716 }
717
718 bm_read_alias()
719 {
720         char *t;
721
722         Assert(Num_aliases < MAX_ALIASES);
723
724         t = strtok( NULL, space );  strncpy(alias_list[Num_aliases].alias_name,t,sizeof(alias_list[Num_aliases].alias_name));
725         t = strtok( NULL, space );  strncpy(alias_list[Num_aliases].file_name,t,sizeof(alias_list[Num_aliases].file_name));
726
727         Num_aliases++;
728 }
729
730 //--unused-- void dump_all_transparent_textures()
731 //--unused-- {
732 //--unused--    FILE * fp;
733 //--unused--    int i,j,k;
734 //--unused--    ubyte * p;
735 //--unused--    fp = fopen( "XPARENT.LST", "wt" );
736 //--unused--    for (i=0; i<Num_tmaps; i++ )    {
737 //--unused--            k = 0; 
738 //--unused--            p = Textures[i]->bm_data;
739 //--unused--            for (j=0; j<64*64; j++ )
740 //--unused--                    if ( (*p++)==255 ) k++;
741 //--unused--            if ( k )        {
742 //--unused--                    fprintf( fp, "'%s' has %d transparent pixels\n", TmapInfo[i].filename, k );
743 //--unused--            }                               
744 //--unused--    }
745 //--unused--    fclose(fp);     
746 //--unused-- }
747
748
749 void bm_close()
750 {
751         if (Installed)
752         {
753                 Installed=0;
754         }
755 }
756
757 void set_lighting_flag(byte *bp)
758 {
759         if (vlighting < 0)
760                 *bp |= BM_FLAG_NO_LIGHTING;
761         else
762                 *bp &= (0xff ^ BM_FLAG_NO_LIGHTING);
763 }
764
765 void set_texture_name(char *name)
766 {
767         strcpy ( TmapInfo[texture_count].filename, name );
768         REMOVE_DOTS(TmapInfo[texture_count].filename);
769 }
770
771 void bm_read_eclip()
772 {
773         bitmap_index bitmap;
774         int dest_bm_num;
775
776         Assert(clip_num < MAX_EFFECTS);
777
778         if (clip_num+1 > Num_effects)
779                 Num_effects = clip_num+1;
780
781         Effects[clip_num].flags = 0;
782
783         //load the dest bitmap first, so that after this routine, the last-loaded
784         //texture will be the monitor, so that lighting parameter will be applied
785         //to the correct texture
786         if (dest_bm) {                  //deal with bitmap for blown up clip
787                 char short_name[FILENAME_LEN];
788                 int i;
789                 strcpy(short_name,dest_bm);
790                 REMOVE_DOTS(short_name);
791                 for (i=0;i<texture_count;i++)
792                         if (!stricmp(TmapInfo[i].filename,short_name))
793                                 break;
794                 if (i==texture_count) {
795                         Textures[texture_count] = bm_load_sub(dest_bm);
796                         strcpy( TmapInfo[texture_count].filename, short_name);
797                         texture_count++;
798                         Assert(texture_count < MAX_TEXTURES);
799                         NumTextures = texture_count;
800                 }
801                 else if (Textures[i].index == 0)                //was found, but registered out
802                         Textures[i] = bm_load_sub(dest_bm);
803                 dest_bm_num = i;
804         }
805
806         if (!abm_flag)  { 
807                 bitmap = bm_load_sub(arg);
808
809                 Effects[clip_num].vc.play_time = fl2f(time);
810                 Effects[clip_num].vc.num_frames = frames;
811                 Effects[clip_num].vc.frame_time = fl2f(time)/frames;
812
813                 Assert(clip_count < frames);
814                 Effects[clip_num].vc.frames[clip_count] = bitmap;
815                 set_lighting_flag(&GameBitmaps[bitmap.index].bm_flags);
816
817                 Assert(!obj_eclip);             //obj eclips for non-abm files not supported!
818                 Assert(crit_flag==0);
819
820                 if (clip_count == 0) {
821                         Effects[clip_num].changing_wall_texture = texture_count;
822                         Assert(tmap_count < MAX_TEXTURES);
823                         TmapList[tmap_count++] = texture_count;
824                         Textures[texture_count] = bitmap;
825                         set_texture_name(arg);
826                         Assert(texture_count < MAX_TEXTURES);
827                         texture_count++;
828                         TmapInfo[texture_count].eclip_num = clip_num;
829                         NumTextures = texture_count;
830                 }
831
832                 clip_count++;
833
834         } else {
835                 bitmap_index bm[MAX_BITMAPS_PER_BRUSH];
836                 abm_flag = 0;
837
838                 ab_load( arg, bm, &Effects[clip_num].vc.num_frames );
839
840                 //printf("EC%d.", clip_num);
841                 Effects[clip_num].vc.play_time = fl2f(time);
842                 Effects[clip_num].vc.frame_time = Effects[clip_num].vc.play_time/Effects[clip_num].vc.num_frames;
843
844                 clip_count = 0; 
845                 set_lighting_flag( &GameBitmaps[bm[clip_count].index].bm_flags);
846                 Effects[clip_num].vc.frames[clip_count] = bm[clip_count];
847
848                 if (!obj_eclip && !crit_flag) {
849                         Effects[clip_num].changing_wall_texture = texture_count;
850                         Assert(tmap_count < MAX_TEXTURES);
851                         TmapList[tmap_count++] = texture_count;
852                         Textures[texture_count] = bm[clip_count];
853                         set_texture_name( arg );
854                         Assert(texture_count < MAX_TEXTURES);
855                         TmapInfo[texture_count].eclip_num = clip_num;
856                         texture_count++;
857                         NumTextures = texture_count;
858                 }
859
860                 if (obj_eclip) {
861
862                         if (Effects[clip_num].changing_object_texture == -1) {          //first time referenced
863                                 Effects[clip_num].changing_object_texture = N_ObjBitmaps;               // XChange ObjectBitmaps
864                                 N_ObjBitmaps++;
865                         }
866
867                         ObjBitmaps[Effects[clip_num].changing_object_texture] = Effects[clip_num].vc.frames[0];
868                 }
869
870                 //if for an object, Effects_bm_ptrs set in object load 
871
872                 for(clip_count=1;clip_count < Effects[clip_num].vc.num_frames; clip_count++) {
873                         set_lighting_flag( &GameBitmaps[bm[clip_count].index].bm_flags);
874                         Effects[clip_num].vc.frames[clip_count] = bm[clip_count];
875                 }
876
877         }
878
879         Effects[clip_num].crit_clip = crit_clip;
880         Effects[clip_num].sound_num = sound_num;
881
882         if (dest_bm) {                  //deal with bitmap for blown up clip
883
884                 Effects[clip_num].dest_bm_num = dest_bm_num;
885
886                 if (dest_vclip==-1)
887                         Error("Desctuction vclip missing on line %d",linenum);
888                 if (dest_size==-1)
889                         Error("Desctuction vclip missing on line %d",linenum);
890
891                 Effects[clip_num].dest_vclip = dest_vclip;
892                 Effects[clip_num].dest_size = dest_size;
893
894                 Effects[clip_num].dest_eclip = dest_eclip;
895         }
896         else {
897                 Effects[clip_num].dest_bm_num = -1;
898                 Effects[clip_num].dest_eclip = -1;
899         }
900
901         if (crit_flag)
902                 Effects[clip_num].flags |= EF_CRITICAL;
903 }
904
905
906 void bm_read_gauges()
907 {
908         bitmap_index bitmap;
909         int i, num_abm_frames;
910
911         if (!abm_flag)  { 
912                 bitmap = bm_load_sub(arg);
913                 Assert(clip_count < MAX_GAUGE_BMS);
914                 Gauges[clip_count] = bitmap;
915                 clip_count++;
916         } else {
917                 bitmap_index bm[MAX_BITMAPS_PER_BRUSH];
918                 abm_flag = 0;
919                 ab_load( arg, bm, &num_abm_frames );
920                 for (i=clip_count; i<clip_count+num_abm_frames; i++) {
921                         Assert(i < MAX_GAUGE_BMS);
922                         Gauges[i] = bm[i-clip_count];
923                 }
924                 clip_count += num_abm_frames;
925         }
926 }
927
928 void bm_read_gauges_hires()
929 {
930         bitmap_index bitmap;
931         int i, num_abm_frames;
932
933         if (!abm_flag)  { 
934                 bitmap = bm_load_sub(arg);
935                 Assert(clip_count < MAX_GAUGE_BMS);
936                 Gauges_hires[clip_count] = bitmap;
937                 clip_count++;
938         } else {
939                 bitmap_index bm[MAX_BITMAPS_PER_BRUSH];
940                 abm_flag = 0;
941                 ab_load( arg, bm, &num_abm_frames );
942                 for (i=clip_count; i<clip_count+num_abm_frames; i++) {
943                         Assert(i < MAX_GAUGE_BMS);
944                         Gauges_hires[i] = bm[i-clip_count];
945                 }
946                 clip_count += num_abm_frames;
947         }
948 }
949
950 void bm_read_wclip()
951 {
952         bitmap_index bitmap;
953         Assert(clip_num < MAX_WALL_ANIMS);
954
955         WallAnims[clip_num].flags = 0;
956
957         if (wall_explodes)      WallAnims[clip_num].flags |= WCF_EXPLODES;
958         if (wall_blastable)     WallAnims[clip_num].flags |= WCF_BLASTABLE;
959         if (wall_hidden)                WallAnims[clip_num].flags |= WCF_HIDDEN;
960         if (tmap1_flag)         WallAnims[clip_num].flags |= WCF_TMAP1;
961
962         if (!abm_flag)  {
963                 bitmap = bm_load_sub(arg);
964                 if ( (WallAnims[clip_num].num_frames>-1) && (clip_count==0) )
965                         Error( "Wall Clip %d is already used!", clip_num );
966                 WallAnims[clip_num].play_time = fl2f(time);
967                 WallAnims[clip_num].num_frames = frames;
968                 //WallAnims[clip_num].frame_time = fl2f(time)/frames;
969                 Assert(clip_count < frames);
970                 WallAnims[clip_num].frames[clip_count++] = texture_count;
971                 WallAnims[clip_num].open_sound = wall_open_sound;
972                 WallAnims[clip_num].close_sound = wall_close_sound;
973                 Textures[texture_count] = bitmap;
974                 set_lighting_flag(&GameBitmaps[bitmap.index].bm_flags);
975                 set_texture_name( arg );
976                 Assert(texture_count < MAX_TEXTURES);
977                 texture_count++;
978                 NumTextures = texture_count;
979                 if (clip_num >= Num_wall_anims) Num_wall_anims = clip_num+1;
980         } else {
981                 bitmap_index bm[MAX_BITMAPS_PER_BRUSH];
982                 int nframes;
983                 if ( (WallAnims[clip_num].num_frames>-1)  )
984                         Error( "AB_Wall clip %d is already used!", clip_num );
985                 abm_flag = 0;
986                 ab_load( arg, bm, &nframes );
987                 WallAnims[clip_num].num_frames = nframes;
988                 //printf("WC");
989                 WallAnims[clip_num].play_time = fl2f(time);
990                 //WallAnims[clip_num].frame_time = fl2f(time)/nframes;
991                 WallAnims[clip_num].open_sound = wall_open_sound;
992                 WallAnims[clip_num].close_sound = wall_close_sound;
993
994                 WallAnims[clip_num].close_sound = wall_close_sound;
995                 strcpy(WallAnims[clip_num].filename, arg);
996                 REMOVE_DOTS(WallAnims[clip_num].filename);      
997
998                 if (clip_num >= Num_wall_anims) Num_wall_anims = clip_num+1;
999
1000                 set_lighting_flag(&GameBitmaps[bm[clip_count].index].bm_flags);
1001
1002                 for (clip_count=0;clip_count < WallAnims[clip_num].num_frames; clip_count++)    {
1003                         //printf("%d", clip_count);
1004                         Textures[texture_count] = bm[clip_count];
1005                         set_lighting_flag(&GameBitmaps[bm[clip_count].index].bm_flags);
1006                         WallAnims[clip_num].frames[clip_count] = texture_count;
1007                         REMOVE_DOTS(arg);
1008                         sprintf( TmapInfo[texture_count].filename, "%s#%d", arg, clip_count);
1009                         Assert(texture_count < MAX_TEXTURES);
1010                         texture_count++;
1011                         NumTextures = texture_count;
1012                 }
1013         }
1014 }
1015
1016 void bm_read_vclip()
1017 {
1018         bitmap_index bi;
1019         Assert(clip_num < VCLIP_MAXNUM);
1020
1021         if (clip_num >= Num_vclips)
1022                 Num_vclips = clip_num+1;
1023
1024         if (!abm_flag)  {
1025                 if ( (Vclip[clip_num].num_frames>-1) && (clip_count==0)  )
1026                         Error( "Vclip %d is already used!", clip_num );
1027                 bi = bm_load_sub(arg);
1028                 Vclip[clip_num].play_time = fl2f(time);
1029                 Vclip[clip_num].num_frames = frames;
1030                 Vclip[clip_num].frame_time = fl2f(time)/frames;
1031                 Vclip[clip_num].light_value = fl2f(vlighting);
1032                 Vclip[clip_num].sound_num = sound_num;
1033                 set_lighting_flag(&GameBitmaps[bi.index].bm_flags);
1034                 Assert(clip_count < frames);
1035                 Vclip[clip_num].frames[clip_count++] = bi;
1036                 if (rod_flag) {
1037                         rod_flag=0;
1038                         Vclip[clip_num].flags |= VF_ROD;
1039                 }                       
1040
1041         } else  {
1042                 bitmap_index bm[MAX_BITMAPS_PER_BRUSH];
1043                 abm_flag = 0;
1044                 if ( (Vclip[clip_num].num_frames>-1)  )
1045                         Error( "AB_Vclip %d is already used!", clip_num );
1046                 ab_load( arg, bm, &Vclip[clip_num].num_frames );
1047
1048                 if (rod_flag) {
1049                         //int i;
1050                         rod_flag=0;
1051                         Vclip[clip_num].flags |= VF_ROD;
1052                 }                       
1053                 //printf("VC");
1054                 Vclip[clip_num].play_time = fl2f(time);
1055                 Vclip[clip_num].frame_time = fl2f(time)/Vclip[clip_num].num_frames;
1056                 Vclip[clip_num].light_value = fl2f(vlighting);
1057                 Vclip[clip_num].sound_num = sound_num;
1058                 set_lighting_flag(&GameBitmaps[bm[clip_count].index].bm_flags);
1059
1060                 for (clip_count=0;clip_count < Vclip[clip_num].num_frames; clip_count++) {
1061                         //printf("%d", clip_count);
1062                         set_lighting_flag(&GameBitmaps[bm[clip_count].index].bm_flags);
1063                         Vclip[clip_num].frames[clip_count] = bm[clip_count];
1064                 }
1065         }
1066 }
1067
1068 // ------------------------------------------------------------------------------
1069 void get4fix(fix *fixp)
1070 {
1071         char    *curtext;
1072         int     i;
1073
1074         for (i=0; i<NDL; i++) {
1075                 curtext = strtok(NULL, space);
1076                 fixp[i] = fl2f(atof(curtext));
1077         }
1078 }
1079
1080 // ------------------------------------------------------------------------------
1081 void get4byte(byte *bytep)
1082 {
1083         char    *curtext;
1084         int     i;
1085
1086         for (i=0; i<NDL; i++) {
1087                 curtext = strtok(NULL, space);
1088                 bytep[i] = atoi(curtext);
1089         }
1090 }
1091
1092 // ------------------------------------------------------------------------------
1093 //      Convert field of view from an angle in 0..360 to cosine.
1094 void adjust_field_of_view(fix *fovp)
1095 {
1096         int             i;
1097         fixang  tt;
1098         float           ff;
1099         fix             temp;
1100
1101         for (i=0; i<NDL; i++) {
1102                 ff = - f2fl(fovp[i]);
1103                 if (ff > 179) {
1104                         mprintf((1, "Warning: Bogus field of view (%7.3f).  Must be in 0..179.\n", ff));
1105                         ff = 179;
1106                 }
1107                 ff = ff/360;
1108                 tt = fl2f(ff);
1109                 fix_sincos(tt, &temp, &fovp[i]);
1110         }
1111 }
1112
1113 void clear_to_end_of_line(void)
1114 {
1115         arg = strtok( NULL, space );
1116         while (arg != NULL)
1117                 arg = strtok( NULL, space );
1118 }
1119
1120 void bm_read_sound()
1121 {
1122         int sound_num;
1123         int alt_sound_num;
1124
1125         sound_num = get_int();
1126         alt_sound_num = get_int();
1127
1128         if ( sound_num>=MAX_SOUNDS )
1129                 Error( "Too many sound files.\n" );
1130
1131         if (sound_num >= num_sounds)
1132                 num_sounds = sound_num+1;
1133
1134         if (Sounds[sound_num] != 255)
1135                 Error("Sound num %d already used, bitmaps.tbl, line %d\n",sound_num,linenum);
1136
1137         arg = strtok(NULL, space);
1138
1139         Sounds[sound_num] = ds_load(arg);
1140
1141         if ( alt_sound_num == 0 )
1142                 AltSounds[sound_num] = sound_num;
1143         else if (alt_sound_num < 0 )
1144                 AltSounds[sound_num] = 255;
1145         else
1146                 AltSounds[sound_num] = alt_sound_num;
1147
1148         if (Sounds[sound_num] == 255)
1149                 Error("Can't load soundfile <%s>",arg);
1150 }
1151
1152 // ------------------------------------------------------------------------------
1153 void bm_read_robot_ai() 
1154 {
1155         char                    *robotnum_text;
1156         int                     robotnum;
1157         robot_info      *robptr;
1158
1159         robotnum_text = strtok(NULL, space);
1160         robotnum = atoi(robotnum_text);
1161         Assert(robotnum < MAX_ROBOT_TYPES);
1162         robptr = &Robot_info[robotnum];
1163
1164         Assert(robotnum == Num_robot_ais);              //make sure valid number
1165
1166 #ifdef SHAREWARE
1167         if (Registered_only) {
1168                 Num_robot_ais++;
1169                 clear_to_end_of_line();
1170                 return;
1171         }
1172 #endif
1173
1174         Num_robot_ais++;
1175
1176         get4fix(robptr->field_of_view);
1177         get4fix(robptr->firing_wait);
1178         get4fix(robptr->firing_wait2);
1179         get4byte(robptr->rapidfire_count);
1180         get4fix(robptr->turn_time);
1181 //      get4fix(robptr->fire_power);
1182 //      get4fix(robptr->shield);
1183         get4fix(robptr->max_speed);
1184         get4fix(robptr->circle_distance);
1185         get4byte(robptr->evade_speed);
1186
1187         robptr->always_0xabcd   = 0xabcd;
1188
1189         adjust_field_of_view(robptr->field_of_view);
1190
1191 }
1192
1193 //      ----------------------------------------------------------------------------------------------
1194 //this will load a bitmap for a polygon models.  it puts the bitmap into
1195 //the array ObjBitmaps[], and also deals with animating bitmaps
1196 //returns a pointer to the bitmap
1197 grs_bitmap *load_polymodel_bitmap(char *name)
1198 {
1199         Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS);
1200
1201 //      Assert( N_ObjBitmaps == N_ObjBitmapPtrs );
1202
1203         if (name[0] == '%') {           //an animating bitmap!
1204                 int eclip_num;
1205
1206                 eclip_num = atoi(name+1);
1207
1208                 if (Effects[eclip_num].changing_object_texture == -1) {         //first time referenced
1209                         Effects[eclip_num].changing_object_texture = N_ObjBitmaps;
1210                         ObjBitmapPtrs[N_ObjBitmapPtrs++] = N_ObjBitmaps;
1211                         N_ObjBitmaps++;
1212                 } else {
1213                         ObjBitmapPtrs[N_ObjBitmapPtrs++] = Effects[eclip_num].changing_object_texture;
1214                 }
1215                 Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS);
1216                 Assert(N_ObjBitmapPtrs < MAX_OBJ_BITMAPS);
1217                 return NULL;
1218         }
1219         else    {
1220                 ObjBitmaps[N_ObjBitmaps] = bm_load_sub(name);
1221                 if (GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_w!=64 || GameBitmaps[ObjBitmaps[N_ObjBitmaps].index].bm_h!=64)
1222                         Error("Bitmap <%s> is not 64x64",name);
1223                 ObjBitmapPtrs[N_ObjBitmapPtrs++] = N_ObjBitmaps;
1224                 N_ObjBitmaps++;
1225                 Assert(N_ObjBitmaps < MAX_OBJ_BITMAPS);
1226                 Assert(N_ObjBitmapPtrs < MAX_OBJ_BITMAPS);
1227                 return &GameBitmaps[ObjBitmaps[N_ObjBitmaps-1].index];
1228         }
1229 }
1230
1231 #define MAX_MODEL_VARIANTS      4
1232
1233 // ------------------------------------------------------------------------------
1234 void bm_read_robot()    
1235 {
1236         char                    *model_name[MAX_MODEL_VARIANTS];
1237         int                     n_models,i;
1238         int                     first_bitmap_num[MAX_MODEL_VARIANTS];
1239         char                    *equal_ptr;
1240         int                     exp1_vclip_num=-1;
1241         int                     exp1_sound_num=-1;
1242         int                     exp2_vclip_num=-1;
1243         int                     exp2_sound_num=-1;
1244         fix                     lighting = F1_0/2;              // Default
1245         fix                     strength = F1_0*10;             // Default strength
1246         fix                     mass = f1_0*4;
1247         fix                     drag = f1_0/2;
1248         short           weapon_type = 0, weapon_type2 = -1;
1249         int                     g,s;
1250         char                    name[ROBOT_NAME_LENGTH];
1251         int                     contains_count=0, contains_id=0, contains_prob=0, contains_type=0, behavior=AIB_NORMAL;
1252         int                     companion = 0, smart_blobs=0, energy_blobs=0, badass=0, energy_drain=0, kamikaze=0, thief=0, pursuit=0, lightcast=0, death_roll=0;
1253         fix                     glow=0, aim=F1_0;
1254         int                     deathroll_sound = SOUND_BOSS_SHARE_DIE; //default
1255         int                     score_value=1000;
1256         int                     cloak_type=0;           //      Default = this robot does not cloak
1257         int                     attack_type=0;          //      Default = this robot attacks by firing (1=lunge)
1258         int                     boss_flag=0;                            //      Default = robot is not a boss.
1259         int                     see_sound = ROBOT_SEE_SOUND_DEFAULT;
1260         int                     attack_sound = ROBOT_ATTACK_SOUND_DEFAULT;
1261         int                     claw_sound = ROBOT_CLAW_SOUND_DEFAULT;
1262         int                     taunt_sound = ROBOT_SEE_SOUND_DEFAULT;
1263         ubyte flags=0;
1264
1265         Assert(N_robot_types < MAX_ROBOT_TYPES);
1266
1267 #ifdef SHAREWARE
1268         if (Registered_only) {
1269                 Robot_info[N_robot_types].model_num = -1;
1270                 N_robot_types++;
1271                 Assert(N_robot_types < MAX_ROBOT_TYPES);
1272                 Num_total_object_types++;
1273                 Assert(Num_total_object_types < MAX_OBJTYPE);
1274                 clear_to_end_of_line();
1275                 return;
1276         }
1277 #endif
1278
1279         model_name[0] = strtok( NULL, space );
1280         first_bitmap_num[0] = N_ObjBitmapPtrs;
1281         n_models = 1;
1282
1283         // Process bitmaps 
1284         bm_flag=BM_ROBOT;
1285         arg = strtok( NULL, space ); 
1286         while (arg!=NULL)       {
1287                 equal_ptr = strchr( arg, '=' );
1288                 if ( equal_ptr )        {
1289                         *equal_ptr='\0';
1290                         equal_ptr++;
1291                         // if we have john=cool, arg is 'john' and equal_ptr is 'cool'
1292                         if (!stricmp( arg, "exp1_vclip" ))      {
1293                                 exp1_vclip_num = atoi(equal_ptr);
1294                         } else if (!stricmp( arg, "exp2_vclip" ))       {
1295                                 exp2_vclip_num = atoi(equal_ptr);
1296                         } else if (!stricmp( arg, "exp1_sound" ))       {
1297                                 exp1_sound_num = atoi(equal_ptr);
1298                         } else if (!stricmp( arg, "exp2_sound" ))       {
1299                                 exp2_sound_num = atoi(equal_ptr);
1300                         } else if (!stricmp( arg, "lighting" )) {
1301                                 lighting = fl2f(atof(equal_ptr));
1302                                 if ( (lighting < 0) || (lighting > F1_0 )) {
1303                                         mprintf( (1, "In bitmaps.tbl, lighting value of %.2f is out of range 0..1.\n", f2fl(lighting)));
1304                                         Error( "In bitmaps.tbl, lighting value of %.2f is out of range 0..1.\n", f2fl(lighting));
1305                                 }
1306                         } else if (!stricmp( arg, "weapon_type" )) {
1307                                 weapon_type = atoi(equal_ptr);
1308                         } else if (!stricmp( arg, "weapon_type2" )) {
1309                                 weapon_type2 = atoi(equal_ptr);
1310                         } else if (!stricmp( arg, "strength" )) {
1311                                 strength = i2f(atoi(equal_ptr));
1312                         } else if (!stricmp( arg, "mass" )) {
1313                                 mass = fl2f(atof(equal_ptr));
1314                         } else if (!stricmp( arg, "drag" )) {
1315                                 drag = fl2f(atof(equal_ptr));
1316                         } else if (!stricmp( arg, "contains_id" )) {
1317                                 contains_id = atoi(equal_ptr);
1318                         } else if (!stricmp( arg, "contains_type" )) {
1319                                 contains_type = atoi(equal_ptr);
1320                         } else if (!stricmp( arg, "contains_count" )) {
1321                                 contains_count = atoi(equal_ptr);
1322                         } else if (!stricmp( arg, "companion" )) {
1323                                 companion = atoi(equal_ptr);
1324                         } else if (!stricmp( arg, "badass" )) {
1325                                 badass = atoi(equal_ptr);
1326                         } else if (!stricmp( arg, "lightcast" )) {
1327                                 lightcast = atoi(equal_ptr);
1328                         } else if (!stricmp( arg, "glow" )) {
1329                                 glow = fl2f(atof(equal_ptr));
1330                         } else if (!stricmp( arg, "death_roll" )) {
1331                                 death_roll = atoi(equal_ptr);
1332                         } else if (!stricmp( arg, "deathroll_sound" )) {
1333                                 deathroll_sound = atoi(equal_ptr);
1334                         } else if (!stricmp( arg, "thief" )) {
1335                                 thief = atoi(equal_ptr);
1336                         } else if (!stricmp( arg, "kamikaze" )) {
1337                                 kamikaze = atoi(equal_ptr);
1338                         } else if (!stricmp( arg, "pursuit" )) {
1339                                 pursuit = atoi(equal_ptr);
1340                         } else if (!stricmp( arg, "smart_blobs" )) {
1341                                 smart_blobs = atoi(equal_ptr);
1342                         } else if (!stricmp( arg, "energy_blobs" )) {
1343                                 energy_blobs = atoi(equal_ptr);
1344                         } else if (!stricmp( arg, "energy_drain" )) {
1345                                 energy_drain = atoi(equal_ptr);
1346                         } else if (!stricmp( arg, "contains_prob" )) {
1347                                 contains_prob = atoi(equal_ptr);
1348                         } else if (!stricmp( arg, "cloak_type" )) {
1349                                 cloak_type = atoi(equal_ptr);
1350                         } else if (!stricmp( arg, "attack_type" )) {
1351                                 attack_type = atoi(equal_ptr);
1352                         } else if (!stricmp( arg, "boss" )) {
1353                                 boss_flag = atoi(equal_ptr);
1354                         } else if (!stricmp( arg, "score_value" )) {
1355                                 score_value = atoi(equal_ptr);
1356                         } else if (!stricmp( arg, "see_sound" )) {
1357                                 see_sound = atoi(equal_ptr);
1358                         } else if (!stricmp( arg, "attack_sound" )) {
1359                                 attack_sound = atoi(equal_ptr);
1360                         } else if (!stricmp( arg, "claw_sound" )) {
1361                                 claw_sound = atoi(equal_ptr);
1362                         } else if (!stricmp( arg, "taunt_sound" )) {
1363                                 taunt_sound = atoi(equal_ptr);
1364                         } else if (!stricmp( arg, "aim" )) {
1365                                 aim = fl2f(atof(equal_ptr));
1366                         } else if (!stricmp( arg, "big_radius" )) {
1367                                 if (atoi(equal_ptr))
1368                                         flags |= RIF_BIG_RADIUS;
1369                         } else if (!stricmp( arg, "behavior" )) {
1370                                 if (!stricmp(equal_ptr, "STILL"))
1371                                         behavior = AIB_STILL;
1372                                 else if (!stricmp(equal_ptr, "NORMAL"))
1373                                         behavior = AIB_NORMAL;
1374                                 else if (!stricmp(equal_ptr, "BEHIND"))
1375                                         behavior = AIB_BEHIND;
1376                                 else if (!stricmp(equal_ptr, "RUN_FROM"))
1377                                         behavior = AIB_RUN_FROM;
1378                                 else if (!stricmp(equal_ptr, "SNIPE"))
1379                                         behavior = AIB_SNIPE;
1380                                 else if (!stricmp(equal_ptr, "STATION"))
1381                                         behavior = AIB_STATION;
1382                                 else if (!stricmp(equal_ptr, "FOLLOW"))
1383                                         behavior = AIB_FOLLOW;
1384                                 else
1385                                         Int3(); //      Error.  Illegal behavior type for current robot.
1386                         } else if (!stricmp( arg, "name" )) {
1387                                 Assert(strlen(equal_ptr) < ROBOT_NAME_LENGTH);  //      Oops, name too long.
1388                                 strcpy(name, &equal_ptr[1]);
1389                                 name[strlen(name)-1] = 0;
1390                         } else if (!stricmp( arg, "simple_model" )) {
1391                                 model_name[n_models] = equal_ptr;
1392                                 first_bitmap_num[n_models] = N_ObjBitmapPtrs;
1393                                 n_models++;
1394                                 Assert(n_models < MAX_MODEL_VARIANTS);
1395                         } else {
1396                                 Int3();
1397                                 mprintf( (1, "Invalid parameter, %s=%s in bitmaps.tbl\n", arg, equal_ptr ));
1398                         }               
1399                 } else {                        // Must be a texture specification...
1400                         load_polymodel_bitmap(arg);
1401                 }
1402                 arg = strtok( NULL, space );
1403         }
1404
1405         //clear out anim info
1406         for (g=0;g<MAX_GUNS+1;g++)
1407                 for (s=0;s<N_ANIM_STATES;s++)
1408                         Robot_info[N_robot_types].anim_states[g][s].n_joints = 0;       //inialize to zero
1409
1410         first_bitmap_num[n_models] = N_ObjBitmapPtrs;
1411
1412         for (i=0;i<n_models;i++) {
1413                 int n_textures;
1414                 int model_num,last_model_num;
1415
1416                 n_textures = first_bitmap_num[i+1] - first_bitmap_num[i];
1417
1418                 model_num = load_polygon_model(model_name[i],n_textures,first_bitmap_num[i],(i==0)?&Robot_info[N_robot_types]:NULL);
1419
1420                 if (i==0)
1421                         Robot_info[N_robot_types].model_num = model_num;
1422                 else
1423                         Polygon_models[last_model_num].simpler_model = model_num+1;
1424
1425                 last_model_num = model_num;
1426         }
1427
1428         if ((glow > i2f(15)) || (glow < 0) || (glow != 0 && glow < 0x1000)) {
1429                 mprintf((0,"Invalid glow value %x for robot %d\n",glow,N_robot_types));
1430                 Int3();
1431         }
1432
1433         ObjType[Num_total_object_types] = OL_ROBOT;
1434         ObjId[Num_total_object_types] = N_robot_types;
1435
1436         Robot_info[N_robot_types].exp1_vclip_num = exp1_vclip_num;
1437         Robot_info[N_robot_types].exp2_vclip_num = exp2_vclip_num;
1438         Robot_info[N_robot_types].exp1_sound_num = exp1_sound_num;
1439         Robot_info[N_robot_types].exp2_sound_num = exp2_sound_num;
1440         Robot_info[N_robot_types].lighting = lighting;
1441         Robot_info[N_robot_types].weapon_type = weapon_type;
1442         Robot_info[N_robot_types].weapon_type2 = weapon_type2;
1443         Robot_info[N_robot_types].strength = strength;
1444         Robot_info[N_robot_types].mass = mass;
1445         Robot_info[N_robot_types].drag = drag;
1446         Robot_info[N_robot_types].cloak_type = cloak_type;
1447         Robot_info[N_robot_types].attack_type = attack_type;
1448         Robot_info[N_robot_types].boss_flag = boss_flag;
1449
1450         Robot_info[N_robot_types].contains_id = contains_id;
1451         Robot_info[N_robot_types].contains_count = contains_count;
1452         Robot_info[N_robot_types].contains_prob = contains_prob;
1453         Robot_info[N_robot_types].companion = companion;
1454         Robot_info[N_robot_types].badass = badass;
1455         Robot_info[N_robot_types].lightcast = lightcast;
1456         Robot_info[N_robot_types].glow = (glow>>12);            //convert to 4:4
1457         Robot_info[N_robot_types].death_roll = death_roll;
1458         Robot_info[N_robot_types].deathroll_sound = deathroll_sound;
1459         Robot_info[N_robot_types].thief = thief;
1460         Robot_info[N_robot_types].flags = flags;
1461         Robot_info[N_robot_types].kamikaze = kamikaze;
1462         Robot_info[N_robot_types].pursuit = pursuit;
1463         Robot_info[N_robot_types].smart_blobs = smart_blobs;
1464         Robot_info[N_robot_types].energy_blobs = energy_blobs;
1465         Robot_info[N_robot_types].energy_drain = energy_drain;
1466         Robot_info[N_robot_types].score_value = score_value;
1467         Robot_info[N_robot_types].see_sound = see_sound;
1468         Robot_info[N_robot_types].attack_sound = attack_sound;
1469         Robot_info[N_robot_types].claw_sound = claw_sound;
1470         Robot_info[N_robot_types].taunt_sound = taunt_sound;
1471         Robot_info[N_robot_types].behavior = behavior;          //      Default behavior for this robot, if coming out of matcen.
1472         Robot_info[N_robot_types].aim = min(f2i(aim*255), 255);         //      how well this robot type can aim.  255=perfect
1473
1474         if (contains_type)
1475                 Robot_info[N_robot_types].contains_type = OBJ_ROBOT;
1476         else
1477                 Robot_info[N_robot_types].contains_type = OBJ_POWERUP;
1478
1479         strcpy(Robot_names[N_robot_types], name);
1480
1481         N_robot_types++;
1482         Num_total_object_types++;
1483
1484         Assert(N_robot_types < MAX_ROBOT_TYPES);
1485         Assert(Num_total_object_types < MAX_OBJTYPE);
1486
1487         bm_flag = BM_NONE;
1488 }
1489
1490 //read a reactor model
1491 void bm_read_reactor()
1492 {
1493         char *model_name, *model_name_dead=NULL;
1494         int first_bitmap_num, first_bitmap_num_dead, n_normal_bitmaps;
1495         char *equal_ptr;
1496         short model_num;
1497         short explosion_vclip_num = -1;
1498         short explosion_sound_num = SOUND_ROBOT_DESTROYED;
1499         fix     lighting = F1_0/2;              // Default
1500         int type=-1;
1501         fix strength=0;
1502
1503         Assert(Num_reactors < MAX_REACTORS);
1504
1505 #ifdef SHAREWARE
1506         if (Registered_only) {
1507                 Num_reactors++;
1508                 clear_to_end_of_line();
1509                 return;
1510         }
1511 #endif
1512
1513         model_name = strtok( NULL, space );
1514
1515         // Process bitmaps 
1516         bm_flag = BM_NONE;
1517         arg = strtok( NULL, space ); 
1518         first_bitmap_num = N_ObjBitmapPtrs;
1519
1520         type = OL_CONTROL_CENTER;
1521
1522         while (arg!=NULL)       {
1523
1524                 equal_ptr = strchr( arg, '=' );
1525
1526                 if ( equal_ptr )        {
1527                         *equal_ptr='\0';
1528                         equal_ptr++;
1529
1530                         // if we have john=cool, arg is 'john' and equal_ptr is 'cool'
1531
1532                         //@@if (!stricmp(arg,"type")) {
1533                         //@@    if (!stricmp(equal_ptr,"controlcen"))
1534                         //@@            type = OL_CONTROL_CENTER;
1535                         //@@    else if (!stricmp(equal_ptr,"clutter"))
1536                         //@@            type = OL_CLUTTER;
1537                         //@@}
1538
1539                         if (!stricmp( arg, "exp_vclip" ))       {
1540                                 explosion_vclip_num = atoi(equal_ptr);
1541                         } else if (!stricmp( arg, "dead_pof" )) {
1542                                 model_name_dead = equal_ptr;
1543                                 first_bitmap_num_dead=N_ObjBitmapPtrs;
1544                         } else if (!stricmp( arg, "exp_sound" ))        {
1545                                 explosion_sound_num = atoi(equal_ptr);
1546                         } else if (!stricmp( arg, "lighting" )) {
1547                                 lighting = fl2f(atof(equal_ptr));
1548                                 if ( (lighting < 0) || (lighting > F1_0 )) {
1549                                         mprintf( (1, "In bitmaps.tbl, lighting value of %.2f is out of range 0..1.\n", f2fl(lighting)));
1550                                         Error( "In bitmaps.tbl, lighting value of %.2f is out of range 0..1.\n", f2fl(lighting));
1551                                 }
1552                         } else if (!stricmp( arg, "strength" )) {
1553                                 strength = fl2f(atof(equal_ptr));
1554                         } else {
1555                                 Int3();
1556                                 mprintf( (1, "Invalid parameter, %s=%s in bitmaps.tbl\n", arg, equal_ptr ));
1557                         }               
1558                 } else {                        // Must be a texture specification...
1559                         load_polymodel_bitmap(arg);
1560                 }
1561                 arg = strtok( NULL, space );
1562         }
1563
1564         if ( model_name_dead )
1565                 n_normal_bitmaps = first_bitmap_num_dead-first_bitmap_num;
1566         else
1567                 n_normal_bitmaps = N_ObjBitmapPtrs-first_bitmap_num;
1568
1569         model_num = load_polygon_model(model_name,n_normal_bitmaps,first_bitmap_num,NULL);
1570
1571         if ( model_name_dead )
1572                 Dead_modelnums[model_num]  = load_polygon_model(model_name_dead,N_ObjBitmapPtrs-first_bitmap_num_dead,first_bitmap_num_dead,NULL);
1573         else
1574                 Dead_modelnums[model_num] = -1;
1575
1576         if (type == -1)
1577                 Error("No object type specfied for object in BITMAPS.TBL on line %d\n",linenum);
1578
1579         Reactors[Num_reactors].model_num = model_num;
1580         Reactors[Num_reactors].n_guns = read_model_guns(model_name,Reactors[Num_reactors].gun_points,Reactors[Num_reactors].gun_dirs,NULL);
1581
1582         ObjType[Num_total_object_types] = type;
1583         ObjId[Num_total_object_types] = Num_reactors;
1584         ObjStrength[Num_total_object_types] = strength;
1585         
1586         //printf( "Object type %d is a control center\n", Num_total_object_types );
1587         Num_total_object_types++;
1588         Assert(Num_total_object_types < MAX_OBJTYPE);
1589
1590         Num_reactors++;
1591 }
1592
1593 //read the marker object
1594 void bm_read_marker()
1595 {
1596         char *model_name;
1597         int first_bitmap_num, n_normal_bitmaps;
1598         char *equal_ptr;
1599
1600         model_name = strtok( NULL, space );
1601
1602         // Process bitmaps 
1603         bm_flag = BM_NONE;
1604         arg = strtok( NULL, space ); 
1605         first_bitmap_num = N_ObjBitmapPtrs;
1606
1607         while (arg!=NULL)       {
1608
1609                 equal_ptr = strchr( arg, '=' );
1610
1611                 if ( equal_ptr )        {
1612                         *equal_ptr='\0';
1613                         equal_ptr++;
1614
1615                         // if we have john=cool, arg is 'john' and equal_ptr is 'cool'
1616                         mprintf( (1, "Invalid parameter, %s=%s in bitmaps.tbl\n", arg, equal_ptr ));
1617                         Int3();
1618
1619                 } else {                        // Must be a texture specification...
1620                         load_polymodel_bitmap(arg);
1621                 }
1622                 arg = strtok( NULL, space );
1623         }
1624
1625         n_normal_bitmaps = N_ObjBitmapPtrs-first_bitmap_num;
1626
1627         Marker_model_num = load_polygon_model(model_name,n_normal_bitmaps,first_bitmap_num,NULL);
1628 }
1629
1630 #ifdef SHAREWARE
1631 //read the exit model
1632 void bm_read_exitmodel()
1633 {
1634         char *model_name, *model_name_dead=NULL;
1635         int first_bitmap_num, first_bitmap_num_dead, n_normal_bitmaps;
1636         char *equal_ptr;
1637         short model_num;
1638
1639         model_name = strtok( NULL, space );
1640
1641         // Process bitmaps 
1642         bm_flag = BM_NONE;
1643         arg = strtok( NULL, space ); 
1644         first_bitmap_num = N_ObjBitmapPtrs;
1645
1646         while (arg!=NULL)       {
1647
1648                 equal_ptr = strchr( arg, '=' );
1649
1650                 if ( equal_ptr )        {
1651                         *equal_ptr='\0';
1652                         equal_ptr++;
1653
1654                         // if we have john=cool, arg is 'john' and equal_ptr is 'cool'
1655
1656                         if (!stricmp( arg, "dead_pof" ))        {
1657                                 model_name_dead = equal_ptr;
1658                                 first_bitmap_num_dead=N_ObjBitmapPtrs;
1659                         } else {
1660                                 Int3();
1661                                 mprintf( (1, "Invalid parameter, %s=%s in bitmaps.tbl\n", arg, equal_ptr ));
1662                         }               
1663                 } else {                        // Must be a texture specification...
1664                         load_polymodel_bitmap(arg);
1665                 }
1666                 arg = strtok( NULL, space );
1667         }
1668
1669         if ( model_name_dead )
1670                 n_normal_bitmaps = first_bitmap_num_dead-first_bitmap_num;
1671         else
1672                 n_normal_bitmaps = N_ObjBitmapPtrs-first_bitmap_num;
1673
1674         model_num = load_polygon_model(model_name,n_normal_bitmaps,first_bitmap_num,NULL);
1675
1676         if ( model_name_dead )
1677                 Dead_modelnums[model_num]  = load_polygon_model(model_name_dead,N_ObjBitmapPtrs-first_bitmap_num_dead,first_bitmap_num_dead,NULL);
1678         else
1679                 Dead_modelnums[model_num] = -1;
1680
1681 //@@    ObjType[Num_total_object_types] = type;
1682 //@@    ObjId[Num_total_object_types] = model_num;
1683 //@@    ObjStrength[Num_total_object_types] = strength;
1684 //@@    
1685 //@@    //printf( "Object type %d is a control center\n", Num_total_object_types );
1686 //@@    Num_total_object_types++;
1687 //@@    Assert(Num_total_object_types < MAX_OBJTYPE);
1688
1689         exit_modelnum = model_num;
1690         destroyed_exit_modelnum = Dead_modelnums[model_num];
1691
1692 }
1693 #endif
1694
1695 void bm_read_player_ship()
1696 {
1697         char    *model_name_dying=NULL;
1698         char    *model_name[MAX_MODEL_VARIANTS];
1699         int     n_models=0,i;
1700         int     first_bitmap_num[MAX_MODEL_VARIANTS];
1701         char *equal_ptr;
1702         robot_info ri;
1703         int last_multi_bitmap_num=-1;
1704
1705         // Process bitmaps 
1706         bm_flag = BM_NONE;
1707
1708         arg = strtok( NULL, space ); 
1709
1710         Player_ship->mass = Player_ship->drag = 0;      //stupid defaults
1711         Player_ship->expl_vclip_num = -1;
1712
1713         while (arg!=NULL)       {
1714
1715                 equal_ptr = strchr( arg, '=' );
1716
1717                 if ( equal_ptr )        {
1718
1719                         *equal_ptr='\0';
1720                         equal_ptr++;
1721
1722                         // if we have john=cool, arg is 'john' and equal_ptr is 'cool'
1723
1724                         if (!stricmp( arg, "model" )) {
1725                                 Assert(n_models==0);
1726                                 model_name[0] = equal_ptr;
1727                                 first_bitmap_num[0] = N_ObjBitmapPtrs;
1728                                 n_models = 1;
1729                         } else if (!stricmp( arg, "simple_model" )) {
1730                                 model_name[n_models] = equal_ptr;
1731                                 first_bitmap_num[n_models] = N_ObjBitmapPtrs;
1732                                 n_models++;
1733                                 Assert(n_models < MAX_MODEL_VARIANTS);
1734
1735                                 if (First_multi_bitmap_num!=-1 && last_multi_bitmap_num==-1)
1736                                         last_multi_bitmap_num=N_ObjBitmapPtrs;
1737                         }
1738                         else if (!stricmp( arg, "mass" ))
1739                                 Player_ship->mass = fl2f(atof(equal_ptr));
1740                         else if (!stricmp( arg, "drag" ))
1741                                 Player_ship->drag = fl2f(atof(equal_ptr));
1742 //                      else if (!stricmp( arg, "low_thrust" ))
1743 //                              Player_ship->low_thrust = fl2f(atof(equal_ptr));
1744                         else if (!stricmp( arg, "max_thrust" ))
1745                                 Player_ship->max_thrust = fl2f(atof(equal_ptr));
1746                         else if (!stricmp( arg, "reverse_thrust" ))
1747                                 Player_ship->reverse_thrust = fl2f(atof(equal_ptr));
1748                         else if (!stricmp( arg, "brakes" ))
1749                                 Player_ship->brakes = fl2f(atof(equal_ptr));
1750                         else if (!stricmp( arg, "wiggle" ))
1751                                 Player_ship->wiggle = fl2f(atof(equal_ptr));
1752                         else if (!stricmp( arg, "max_rotthrust" ))
1753                                 Player_ship->max_rotthrust = fl2f(atof(equal_ptr));
1754                         else if (!stricmp( arg, "dying_pof" ))
1755                                 model_name_dying = equal_ptr;
1756                         else if (!stricmp( arg, "expl_vclip_num" ))
1757                                 Player_ship->expl_vclip_num=atoi(equal_ptr);
1758                         else {
1759                                 Int3();
1760                                 mprintf( (1, "Invalid parameter, %s=%s in bitmaps.tbl\n", arg, equal_ptr ));
1761                         }               
1762                 }
1763                 else if (!stricmp( arg, "multi_textures" )) {
1764
1765                         First_multi_bitmap_num = N_ObjBitmapPtrs;
1766                         first_bitmap_num[n_models] = N_ObjBitmapPtrs;
1767
1768                 }
1769                 else                    // Must be a texture specification...
1770
1771                         load_polymodel_bitmap(arg);
1772
1773                 arg = strtok( NULL, space );
1774         }
1775
1776         Assert(model_name != NULL);
1777
1778         if (First_multi_bitmap_num!=-1 && last_multi_bitmap_num==-1)
1779                 last_multi_bitmap_num=N_ObjBitmapPtrs;
1780
1781         if (First_multi_bitmap_num==-1)
1782                 first_bitmap_num[n_models] = N_ObjBitmapPtrs;
1783
1784         Assert(last_multi_bitmap_num-First_multi_bitmap_num == (MAX_NUM_NET_PLAYERS-1)*2);
1785
1786         for (i=0;i<n_models;i++) {
1787                 int n_textures;
1788                 int model_num,last_model_num;
1789
1790                 n_textures = first_bitmap_num[i+1] - first_bitmap_num[i];
1791
1792                 model_num = load_polygon_model(model_name[i],n_textures,first_bitmap_num[i],(i==0)?&ri:NULL);
1793
1794                 if (i==0)
1795                         Player_ship->model_num = model_num;
1796                 else
1797                         Polygon_models[last_model_num].simpler_model = model_num+1;
1798
1799                 last_model_num = model_num;
1800         }
1801
1802         if ( model_name_dying ) {
1803                 Assert(n_models);
1804                 Dying_modelnums[Player_ship->model_num]  = load_polygon_model(model_name_dying,first_bitmap_num[1]-first_bitmap_num[0],first_bitmap_num[0],NULL);
1805         }
1806
1807         Assert(ri.n_guns == N_PLAYER_GUNS);
1808
1809         //calc player gun positions
1810
1811         {
1812                 polymodel *pm;
1813                 robot_info *r;
1814                 vms_vector pnt;
1815                 int mn;                         //submodel number
1816                 int gun_num;
1817         
1818                 r = &ri;
1819                 pm = &Polygon_models[Player_ship->model_num];
1820
1821                 for (gun_num=0;gun_num<r->n_guns;gun_num++) {
1822
1823                         pnt = r->gun_points[gun_num];
1824                         mn = r->gun_submodels[gun_num];
1825                 
1826                         //instance up the tree for this gun
1827                         while (mn != 0) {
1828                                 vm_vec_add2(&pnt,&pm->submodel_offsets[mn]);
1829                                 mn = pm->submodel_parents[mn];
1830                         }
1831
1832                         Player_ship->gun_points[gun_num] = pnt;
1833                 
1834                 }
1835         }
1836
1837
1838 }
1839
1840 void bm_read_some_file()
1841 {
1842
1843         switch (bm_flag) {
1844         case BM_NONE:
1845                 Error("Trying to read bitmap <%s> with bm_flag==BM_NONE on line %d of BITMAPS.TBL",arg,linenum);
1846                 break;
1847         case BM_COCKPIT:        {
1848                 bitmap_index bitmap;
1849                 bitmap = bm_load_sub(arg);
1850                 Assert( Num_cockpits < N_COCKPIT_BITMAPS );
1851                 cockpit_bitmap[Num_cockpits++] = bitmap;
1852                 //bm_flag = BM_NONE;
1853                 return;
1854                 }
1855                 break;
1856         case BM_GAUGES:
1857                 bm_read_gauges();
1858                 return;
1859                 break;
1860         case BM_GAUGES_HIRES:
1861                 bm_read_gauges_hires();
1862                 return;
1863                 break;
1864         case BM_WEAPON:
1865                 bm_read_weapon(0);
1866                 return;
1867                 break;
1868         case BM_VCLIP:
1869                 bm_read_vclip();
1870                 return;
1871                 break;                                  
1872         case BM_ECLIP:
1873                 bm_read_eclip();
1874                 return;
1875                 break;
1876         case BM_TEXTURES:                       {
1877                 bitmap_index bitmap;
1878                 bitmap = bm_load_sub(arg);
1879                 Assert(tmap_count < MAX_TEXTURES);
1880                 TmapList[tmap_count++] = texture_count;
1881                 Textures[texture_count] = bitmap;
1882                 set_texture_name( arg );
1883                 Assert(texture_count < MAX_TEXTURES);
1884                 texture_count++;
1885                 NumTextures = texture_count;
1886                 return;
1887                 }
1888                 break;
1889         case BM_WCLIP:
1890                 bm_read_wclip();
1891                 return;
1892                 break;
1893         }
1894
1895         Error("Trying to read bitmap <%s> with unknown bm_flag <%x> on line %d of BITMAPS.TBL",arg,bm_flag,linenum);
1896 }
1897
1898 // ------------------------------------------------------------------------------
1899 //      If unused_flag is set, then this is just a placeholder.  Don't actually reference vclips or load bbms.
1900 void bm_read_weapon(int unused_flag)
1901 {
1902         int     i,n;
1903         int     n_models=0;
1904         char    *equal_ptr;
1905         char    *pof_file_inner=NULL;
1906         char    *model_name[MAX_MODEL_VARIANTS];
1907         int     first_bitmap_num[MAX_MODEL_VARIANTS];
1908         int     lighted;                                        //flag for whether is a texture is lighted
1909
1910         Assert(N_weapon_types < MAX_WEAPON_TYPES);
1911
1912         n = N_weapon_types;
1913         N_weapon_types++;
1914         Assert(N_weapon_types <= MAX_WEAPON_TYPES);
1915
1916         if (unused_flag) {
1917                 clear_to_end_of_line();
1918                 return;
1919         }
1920
1921 #ifdef SHAREWARE
1922         if (Registered_only) {
1923                 clear_to_end_of_line();
1924                 return;
1925         }
1926 #endif
1927
1928         // Initialize weapon array
1929         Weapon_info[n].render_type = WEAPON_RENDER_NONE;                // 0=laser, 1=blob, 2=object
1930         Weapon_info[n].bitmap.index = 0;
1931         Weapon_info[n].model_num = -1;
1932         Weapon_info[n].model_num_inner = -1;
1933         Weapon_info[n].blob_size = 0x1000;                                                                      // size of blob
1934         Weapon_info[n].flash_vclip = -1;
1935         Weapon_info[n].flash_sound = SOUND_LASER_FIRED;
1936         Weapon_info[n].flash_size = 0;
1937         Weapon_info[n].robot_hit_vclip = -1;
1938         Weapon_info[n].robot_hit_sound = -1;
1939         Weapon_info[n].wall_hit_vclip = -1;
1940         Weapon_info[n].wall_hit_sound = -1;
1941         Weapon_info[n].impact_size = 0;
1942         for (i=0; i<NDL; i++) {
1943                 Weapon_info[n].strength[i] = F1_0;
1944                 Weapon_info[n].speed[i] = F1_0*10;
1945         }
1946         Weapon_info[n].mass = F1_0;
1947         Weapon_info[n].thrust = 0;
1948         Weapon_info[n].drag = 0;
1949         Weapon_info[n].persistent = 0;
1950
1951         Weapon_info[n].energy_usage = 0;                                        //      How much fuel is consumed to fire this weapon.
1952         Weapon_info[n].ammo_usage = 0;                                  //      How many units of ammunition it uses.
1953         Weapon_info[n].fire_wait = F1_0/4;                              //      Time until this weapon can be fired again.
1954         Weapon_info[n].fire_count = 1;                                  //      Number of bursts fired from EACH GUN per firing.  For weapons which fire from both sides, 3*fire_count shots will be fired.
1955         Weapon_info[n].damage_radius = 0;                               //      Radius of damage for missiles, not lasers.  Does damage to objects within this radius of hit point.
1956 //--01/19/95, mk--      Weapon_info[n].damage_force = 0;                                        //      Force (movement) due to explosion
1957         Weapon_info[n].destroyable = 1;                                 //      Weapons default to destroyable
1958         Weapon_info[n].matter = 0;                                                      //      Weapons default to not being constructed of matter (they are energy!)
1959         Weapon_info[n].bounce = 0;                                                      //      Weapons default to not bouncing off walls
1960
1961         Weapon_info[n].flags = 0;
1962
1963         Weapon_info[n].lifetime = WEAPON_DEFAULT_LIFETIME;                                      //      Number of bursts fired from EACH GUN per firing.  For weapons which fire from both sides, 3*fire_count shots will be fired.
1964
1965         Weapon_info[n].po_len_to_width_ratio = F1_0*10;
1966
1967         Weapon_info[n].picture.index = 0;
1968         Weapon_info[n].hires_picture.index = 0;
1969         Weapon_info[n].homing_flag = 0;
1970
1971         Weapon_info[n].flash = 0;
1972         Weapon_info[n].multi_damage_scale = F1_0;
1973         Weapon_info[n].afterburner_size = 0;
1974         Weapon_info[n].children = -1;
1975
1976         // Process arguments
1977         arg = strtok( NULL, space ); 
1978
1979         lighted = 1;                    //assume first texture is lighted
1980
1981         Weapon_info[n].speedvar = 128;
1982
1983         while (arg!=NULL)       {
1984                 equal_ptr = strchr( arg, '=' );
1985                 if ( equal_ptr )        {
1986                         *equal_ptr='\0';
1987                         equal_ptr++;
1988                         // if we have john=cool, arg is 'john' and equal_ptr is 'cool'
1989                         if (!stricmp( arg, "laser_bmp" ))       {
1990                                 // Load bitmap with name equal_ptr
1991
1992                                 Weapon_info[n].bitmap = bm_load_sub(equal_ptr);         //load_polymodel_bitmap(equal_ptr);
1993                                 Weapon_info[n].render_type = WEAPON_RENDER_LASER;
1994
1995                         } else if (!stricmp( arg, "blob_bmp" )) {
1996                                 // Load bitmap with name equal_ptr
1997
1998                                 Weapon_info[n].bitmap = bm_load_sub(equal_ptr);         //load_polymodel_bitmap(equal_ptr);
1999                                 Weapon_info[n].render_type = WEAPON_RENDER_BLOB;
2000
2001                         } else if (!stricmp( arg, "weapon_vclip" ))     {
2002                                 // Set vclip to play for this weapon.
2003                                 Weapon_info[n].bitmap.index = 0;
2004                                 Weapon_info[n].render_type = WEAPON_RENDER_VCLIP;
2005                                 Weapon_info[n].weapon_vclip = atoi(equal_ptr);
2006
2007                         } else if (!stricmp( arg, "none_bmp" )) {
2008                                 Weapon_info[n].bitmap = bm_load_sub(equal_ptr);
2009                                 Weapon_info[n].render_type = WEAPON_RENDER_NONE;
2010
2011                         } else if (!stricmp( arg, "weapon_pof" ))       {
2012                                 // Load pof file
2013                                 Assert(n_models==0);
2014                                 model_name[0] = equal_ptr;
2015                                 first_bitmap_num[0] = N_ObjBitmapPtrs;
2016                                 n_models=1;
2017                         } else if (!stricmp( arg, "simple_model" )) {
2018                                 model_name[n_models] = equal_ptr;
2019                                 first_bitmap_num[n_models] = N_ObjBitmapPtrs;
2020                                 n_models++;
2021                                 Assert(n_models < MAX_MODEL_VARIANTS);
2022                         } else if (!stricmp( arg, "weapon_pof_inner" )) {
2023                                 // Load pof file
2024                                 pof_file_inner = equal_ptr;
2025                         } else if (!stricmp( arg, "strength" )) {
2026                                 for (i=0; i<NDL-1; i++) {
2027                                         Weapon_info[n].strength[i] = fl2f(atof(equal_ptr));
2028                                         equal_ptr = strtok(NULL, space);
2029                                 }
2030                                 Weapon_info[n].strength[i] = i2f(atoi(equal_ptr));
2031                         } else if (!stricmp( arg, "mass" )) {
2032                                 Weapon_info[n].mass = fl2f(atof(equal_ptr));
2033                         } else if (!stricmp( arg, "drag" )) {
2034                                 Weapon_info[n].drag = fl2f(atof(equal_ptr));
2035                         } else if (!stricmp( arg, "thrust" )) {
2036                                 Weapon_info[n].thrust = fl2f(atof(equal_ptr));
2037                         } else if (!stricmp( arg, "matter" )) {
2038                                 Weapon_info[n].matter = atoi(equal_ptr);
2039                         } else if (!stricmp( arg, "bounce" )) {
2040                                 Weapon_info[n].bounce = atoi(equal_ptr);
2041                         } else if (!stricmp( arg, "speed" )) {
2042                                 for (i=0; i<NDL-1; i++) {
2043                                         Weapon_info[n].speed[i] = i2f(atoi(equal_ptr));
2044                                         equal_ptr = strtok(NULL, space);
2045                                 }
2046                                 Weapon_info[n].speed[i] = i2f(atoi(equal_ptr));
2047                         } else if (!stricmp( arg, "speedvar" )) {
2048                                 Weapon_info[n].speedvar = (atoi(equal_ptr) * 128) / 100;
2049                         } else if (!stricmp( arg, "flash_vclip" ))      {
2050                                 Weapon_info[n].flash_vclip = atoi(equal_ptr);
2051                         } else if (!stricmp( arg, "flash_sound" ))      {
2052                                 Weapon_info[n].flash_sound = atoi(equal_ptr);
2053                         } else if (!stricmp( arg, "flash_size" ))       {
2054                                 Weapon_info[n].flash_size = fl2f(atof(equal_ptr));
2055                         } else if (!stricmp( arg, "blob_size" ))        {
2056                                 Weapon_info[n].blob_size = fl2f(atof(equal_ptr));
2057                         } else if (!stricmp( arg, "robot_hit_vclip" ))  {
2058                                 Weapon_info[n].robot_hit_vclip = atoi(equal_ptr);
2059                         } else if (!stricmp( arg, "robot_hit_sound" ))  {
2060                                 Weapon_info[n].robot_hit_sound = atoi(equal_ptr);
2061                         } else if (!stricmp( arg, "wall_hit_vclip" ))   {
2062                                 Weapon_info[n].wall_hit_vclip = atoi(equal_ptr);
2063                         } else if (!stricmp( arg, "wall_hit_sound" ))   {
2064                                 Weapon_info[n].wall_hit_sound = atoi(equal_ptr);
2065                         } else if (!stricmp( arg, "impact_size" ))      {
2066                                 Weapon_info[n].impact_size = fl2f(atof(equal_ptr));
2067                         } else if (!stricmp( arg, "lighted" ))  {
2068                                 lighted = atoi(equal_ptr);
2069                         } else if (!stricmp( arg, "lw_ratio" )) {
2070                                 Weapon_info[n].po_len_to_width_ratio = fl2f(atof(equal_ptr));
2071                         } else if (!stricmp( arg, "lightcast" ))        {
2072                                 Weapon_info[n].light = fl2f(atof(equal_ptr));
2073                         } else if (!stricmp( arg, "persistent" ))       {
2074                                 Weapon_info[n].persistent = atoi(equal_ptr);
2075                         } else if (!stricmp(arg, "energy_usage" )) {
2076                                 Weapon_info[n].energy_usage = fl2f(atof(equal_ptr));
2077                         } else if (!stricmp(arg, "ammo_usage" )) {
2078                                 Weapon_info[n].ammo_usage = atoi(equal_ptr);
2079                         } else if (!stricmp(arg, "fire_wait" )) {
2080                                 Weapon_info[n].fire_wait = fl2f(atof(equal_ptr));
2081                         } else if (!stricmp(arg, "fire_count" )) {
2082                                 Weapon_info[n].fire_count = atoi(equal_ptr);
2083                         } else if (!stricmp(arg, "damage_radius" )) {
2084                                 Weapon_info[n].damage_radius = fl2f(atof(equal_ptr));
2085 //--01/19/95, mk--                      } else if (!stricmp(arg, "damage_force" )) {
2086 //--01/19/95, mk--                              Weapon_info[n].damage_force = fl2f(atof(equal_ptr));
2087                         } else if (!stricmp(arg, "lifetime" )) {
2088                                 Weapon_info[n].lifetime = fl2f(atof(equal_ptr));
2089                         } else if (!stricmp(arg, "destroyable" )) {
2090                                 Weapon_info[n].destroyable = atoi(equal_ptr);
2091                         } else if (!stricmp(arg, "picture" )) {
2092                                 Weapon_info[n].picture = bm_load_sub(equal_ptr);
2093                         } else if (!stricmp(arg, "hires_picture" )) {
2094                                 Weapon_info[n].hires_picture = bm_load_sub(equal_ptr);
2095                         } else if (!stricmp(arg, "homing" )) {
2096                                 Weapon_info[n].homing_flag = !!atoi(equal_ptr);
2097                         } else if (!stricmp(arg, "flash" )) {
2098                                 Weapon_info[n].flash = atoi(equal_ptr);
2099                         } else if (!stricmp(arg, "multi_damage_scale" )) {
2100                                 Weapon_info[n].multi_damage_scale = fl2f(atof(equal_ptr));
2101                         } else if (!stricmp(arg, "afterburner_size" )) {
2102                                 Weapon_info[n].afterburner_size = f2i(16*fl2f(atof(equal_ptr)));
2103                         } else if (!stricmp(arg, "children" )) {
2104                                 Weapon_info[n].children = atoi(equal_ptr);
2105                         } else if (!stricmp(arg, "placable" )) {
2106                                 if (atoi(equal_ptr)) {
2107                                         Weapon_info[n].flags |= WIF_PLACABLE;
2108
2109                                         Assert(Num_total_object_types < MAX_OBJTYPE);
2110                                         ObjType[Num_total_object_types] = OL_WEAPON;
2111                                         ObjId[Num_total_object_types] = n;
2112                                         Num_total_object_types++;
2113                                 }
2114                         } else {
2115                                 Int3();
2116                                 mprintf( (1, "Invalid parameter, %s=%s in bitmaps.tbl\n", arg, equal_ptr ));
2117                         }               
2118                 } else {                        // Must be a texture specification...
2119                         grs_bitmap *bm;
2120
2121                         bm = load_polymodel_bitmap(arg);
2122                         if (! lighted)
2123                                 bm->bm_flags |= BM_FLAG_NO_LIGHTING;
2124
2125                         lighted = 1;                    //default for next bitmap is lighted
2126                 }
2127                 arg = strtok( NULL, space );
2128         }
2129
2130         first_bitmap_num[n_models] = N_ObjBitmapPtrs;
2131
2132         for (i=0;i<n_models;i++) {
2133                 int n_textures;
2134                 int model_num,last_model_num;
2135
2136                 n_textures = first_bitmap_num[i+1] - first_bitmap_num[i];
2137
2138                 model_num = load_polygon_model(model_name[i],n_textures,first_bitmap_num[i],NULL);
2139
2140                 if (i==0) {
2141                         Weapon_info[n].render_type = WEAPON_RENDER_POLYMODEL;
2142                         Weapon_info[n].model_num = model_num;
2143                 }
2144                 else
2145                         Polygon_models[last_model_num].simpler_model = model_num+1;
2146
2147                 last_model_num = model_num;
2148         }
2149
2150         if ( pof_file_inner )   {
2151                 Assert(n_models);
2152                 Weapon_info[n].model_num_inner = load_polygon_model(pof_file_inner,first_bitmap_num[1]-first_bitmap_num[0],first_bitmap_num[0],NULL);
2153         }
2154
2155         if ((Weapon_info[n].ammo_usage == 0) && (Weapon_info[n].energy_usage == 0))
2156                 mprintf((1, "Warning: Weapon %i has ammo and energy usage of 0.\n", n));
2157
2158 // -- render type of none is now legal --       Assert( Weapon_info[n].render_type != WEAPON_RENDER_NONE );
2159 }
2160
2161
2162
2163
2164
2165 // ------------------------------------------------------------------------------
2166 #define DEFAULT_POWERUP_SIZE i2f(3)
2167
2168 void bm_read_powerup(int unused_flag)
2169 {
2170         int n;
2171         char    *equal_ptr;
2172
2173         Assert(N_powerup_types < MAX_POWERUP_TYPES);
2174
2175         n = N_powerup_types;
2176         N_powerup_types++;
2177
2178         if (unused_flag) {
2179                 clear_to_end_of_line();
2180                 return;
2181         }
2182
2183         // Initialize powerup array
2184         Powerup_info[n].light = F1_0/3;         //      Default lighting value.
2185         Powerup_info[n].vclip_num = -1;
2186         Powerup_info[n].hit_sound = -1;
2187         Powerup_info[n].size = DEFAULT_POWERUP_SIZE;
2188         Powerup_names[n][0] = 0;
2189
2190         // Process arguments
2191         arg = strtok( NULL, space ); 
2192
2193         while (arg!=NULL)       {
2194                 equal_ptr = strchr( arg, '=' );
2195                 if ( equal_ptr )        {
2196                         *equal_ptr='\0';
2197                         equal_ptr++;
2198                         // if we have john=cool, arg is 'john' and equal_ptr is 'cool'
2199                         if (!stricmp( arg, "vclip_num" ))       {
2200                                 Powerup_info[n].vclip_num = atoi(equal_ptr);
2201                         } else if (!stricmp( arg, "light" ))    {
2202                                 Powerup_info[n].light = fl2f(atof(equal_ptr));
2203                         } else if (!stricmp( arg, "hit_sound" ))        {
2204                                 Powerup_info[n].hit_sound = atoi(equal_ptr);
2205                         } else if (!stricmp( arg, "name" )) {
2206                                 Assert(strlen(equal_ptr) < POWERUP_NAME_LENGTH);        //      Oops, name too long.
2207                                 strcpy(Powerup_names[n], &equal_ptr[1]);
2208                                 Powerup_names[n][strlen(Powerup_names[n])-1] = 0;
2209                         } else if (!stricmp( arg, "size" ))     {
2210                                 Powerup_info[n].size = fl2f(atof(equal_ptr));
2211                         } else {
2212                                 Int3();
2213                                 mprintf( (1, "Invalid parameter, %s=%s in bitmaps.tbl\n", arg, equal_ptr ));
2214                         }               
2215                 } else {                        // Must be a texture specification...
2216                         Int3();
2217                         mprintf( (1, "Invalid argument, %s in bitmaps.tbl\n", arg ));
2218                 }
2219                 arg = strtok( NULL, space );
2220         }
2221
2222         ObjType[Num_total_object_types] = OL_POWERUP;
2223         ObjId[Num_total_object_types] = n;
2224         //printf( "Object type %d is a powerup\n", Num_total_object_types );
2225         Num_total_object_types++;
2226         Assert(Num_total_object_types < MAX_OBJTYPE);
2227
2228 }
2229
2230 void bm_read_hostage()  
2231 {
2232         int n;
2233         char    *equal_ptr;
2234
2235         Assert(N_hostage_types < MAX_HOSTAGE_TYPES);
2236
2237         n = N_hostage_types;
2238         N_hostage_types++;
2239
2240         // Process arguments
2241         arg = strtok( NULL, space ); 
2242
2243         while (arg!=NULL)       {
2244                 equal_ptr = strchr( arg, '=' );
2245                 if ( equal_ptr )        {
2246                         *equal_ptr='\0';
2247                         equal_ptr++;
2248
2249                         if (!stricmp( arg, "vclip_num" ))
2250
2251                                 Hostage_vclip_num[n] = atoi(equal_ptr);
2252
2253                         else {
2254                                 Int3();
2255                                 mprintf( (1, "Invalid parameter, %s=%s in bitmaps.tbl\n", arg, equal_ptr ));
2256                         }
2257
2258                 } else {
2259                         Int3();
2260                         mprintf( (1, "Invalid argument, %s in bitmaps.tbl at line %d\n", arg, linenum ));
2261                 }
2262                 arg = strtok( NULL, space );
2263         }
2264
2265         ObjType[Num_total_object_types] = OL_HOSTAGE;
2266         ObjId[Num_total_object_types] = n;
2267         //printf( "Object type %d is a hostage\n", Num_total_object_types );
2268         Num_total_object_types++;
2269         Assert(Num_total_object_types < MAX_OBJTYPE);
2270
2271 }
2272
2273 //these values are the number of each item in the release of d2
2274 //extra items added after the release get written in an additional hamfile
2275 #define N_D2_ROBOT_TYPES                66
2276 #define N_D2_ROBOT_JOINTS               1145
2277 #define N_D2_POLYGON_MODELS     166
2278 #define N_D2_OBJBITMAPS                 422
2279 #define N_D2_OBJBITMAPPTRS              502
2280 #define N_D2_WEAPON_TYPES               62
2281
2282 void bm_write_all(FILE *fp)
2283 {
2284         int i,t;
2285         FILE *tfile;
2286         int s=0;
2287
2288 tfile = fopen("hamfile.lst","wt");
2289
2290         t = NumTextures-1;      //don't save bogus texture
2291         fwrite( &t, sizeof(int), 1, fp );
2292         fwrite( Textures, sizeof(bitmap_index), t, fp );
2293         for (i=0;i<t;i++)
2294                 fwrite( &TmapInfo[i], sizeof(*TmapInfo)-sizeof(TmapInfo->filename)-sizeof(TmapInfo->pad2), 1, fp );
2295
2296 fprintf(tfile,"NumTextures = %d, Textures array = %d, TmapInfo array = %d\n",NumTextures,sizeof(bitmap_index)*NumTextures,sizeof(tmap_info)*NumTextures);
2297
2298         t = MAX_SOUNDS;
2299         fwrite( &t, sizeof(int), 1, fp );
2300         fwrite( Sounds, sizeof(ubyte), t, fp );
2301         fwrite( AltSounds, sizeof(ubyte), t, fp );
2302
2303 fprintf(tfile,"Num Sounds = %d, Sounds array = %d, AltSounds array = %d\n",t,t,t);
2304
2305         fwrite( &Num_vclips, sizeof(int), 1, fp );
2306         fwrite( Vclip, sizeof(vclip), Num_vclips, fp );
2307
2308 fprintf(tfile,"Num_vclips = %d, Vclip array = %d\n",Num_vclips,sizeof(vclip)*Num_vclips);
2309
2310         fwrite( &Num_effects, sizeof(int), 1, fp );
2311         fwrite( Effects, sizeof(eclip), Num_effects, fp );
2312
2313 fprintf(tfile,"Num_effects = %d, Effects array = %d\n",Num_effects,sizeof(eclip)*Num_effects);
2314
2315         fwrite( &Num_wall_anims, sizeof(int), 1, fp );
2316         fwrite( WallAnims, sizeof(wclip), Num_wall_anims, fp );
2317
2318 fprintf(tfile,"Num_wall_anims = %d, WallAnims array = %d\n",Num_wall_anims,sizeof(wclip)*Num_wall_anims);
2319
2320         t = N_D2_ROBOT_TYPES;
2321         fwrite( &t, sizeof(int), 1, fp );
2322         fwrite( Robot_info, sizeof(robot_info), t, fp );
2323
2324 fprintf(tfile,"N_robot_types = %d, Robot_info array = %d\n",t,sizeof(robot_info)*N_robot_types);
2325
2326         t = N_D2_ROBOT_JOINTS;
2327         fwrite( &t, sizeof(int), 1, fp );
2328         fwrite( Robot_joints, sizeof(jointpos), t, fp );
2329
2330 fprintf(tfile,"N_robot_joints = %d, Robot_joints array = %d\n",t,sizeof(jointpos)*N_robot_joints);
2331
2332         t = N_D2_WEAPON_TYPES;
2333         fwrite( &t, sizeof(int), 1, fp );
2334         fwrite( Weapon_info, sizeof(weapon_info), t, fp );
2335
2336 fprintf(tfile,"N_weapon_types = %d, Weapon_info array = %d\n",N_weapon_types,sizeof(weapon_info)*N_weapon_types);
2337
2338         fwrite( &N_powerup_types, sizeof(int), 1, fp );
2339         fwrite( Powerup_info, sizeof(powerup_type_info), N_powerup_types, fp );
2340         
2341 fprintf(tfile,"N_powerup_types = %d, Powerup_info array = %d\n",N_powerup_types,sizeof(powerup_info)*N_powerup_types);
2342
2343         t = N_D2_POLYGON_MODELS;
2344         fwrite( &t, sizeof(int), 1, fp );
2345         fwrite( Polygon_models, sizeof(polymodel), t, fp );
2346
2347 fprintf(tfile,"N_polygon_models = %d, Polygon_models array = %d\n",t,sizeof(polymodel)*t);
2348
2349         for (i=0; i<t; i++ )    {
2350                 g3_uninit_polygon_model(Polygon_models[i].model_data);  //get RGB colors
2351                 fwrite( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
2352 fprintf(tfile,"  Model %d, data size = %d\n",i,Polygon_models[i].model_data_size); s+=Polygon_models[i].model_data_size;
2353                 g3_init_polygon_model(Polygon_models[i].model_data);    //map colors again
2354         }
2355 fprintf(tfile,"Total model size = %d\n",s);
2356
2357         fwrite( Dying_modelnums, sizeof(int), t, fp );
2358         fwrite( Dead_modelnums, sizeof(int), t, fp );
2359
2360 fprintf(tfile,"Dying_modelnums array = %d, Dead_modelnums array = %d\n",sizeof(int)*t,sizeof(int)*t);
2361
2362         t = MAX_GAUGE_BMS;
2363         fwrite( &t, sizeof(int), 1, fp );
2364         fwrite( Gauges, sizeof(bitmap_index), t, fp );
2365         fwrite( Gauges_hires, sizeof(bitmap_index), t, fp );
2366
2367 fprintf(tfile,"Num gauge bitmaps = %d, Gauges array = %d, Gauges_hires array = %d\n",t,sizeof(bitmap_index)*t,sizeof(bitmap_index)*t);
2368
2369         t = MAX_OBJ_BITMAPS;
2370         fwrite( &t, sizeof(int), 1, fp );
2371         fwrite( ObjBitmaps, sizeof(bitmap_index), t, fp );
2372         fwrite( ObjBitmapPtrs, sizeof(ushort), t, fp );
2373
2374 fprintf(tfile,"Num obj bitmaps = %d, ObjBitmaps array = %d, ObjBitmapPtrs array = %d\n",t,sizeof(bitmap_index)*t,sizeof(ushort)*t);
2375
2376         fwrite( &only_player_ship, sizeof(player_ship), 1, fp );
2377
2378 fprintf(tfile,"player_ship size = %d\n",sizeof(player_ship));
2379
2380         fwrite( &Num_cockpits, sizeof(int), 1, fp );
2381         fwrite( cockpit_bitmap, sizeof(bitmap_index), Num_cockpits, fp );
2382
2383 fprintf(tfile,"Num_cockpits = %d, cockpit_bitmaps array = %d\n",Num_cockpits,sizeof(bitmap_index)*Num_cockpits);
2384
2385 //@@    fwrite( &Num_total_object_types, sizeof(int), 1, fp );
2386 //@@    fwrite( ObjType, sizeof(byte), Num_total_object_types, fp );
2387 //@@    fwrite( ObjId, sizeof(byte), Num_total_object_types, fp );
2388 //@@    fwrite( ObjStrength, sizeof(fix), Num_total_object_types, fp );
2389
2390 fprintf(tfile,"Num_total_object_types = %d, ObjType array = %d, ObjId array = %d, ObjStrength array = %d\n",Num_total_object_types,Num_total_object_types,Num_total_object_types,sizeof(fix)*Num_total_object_types);
2391
2392         fwrite( &First_multi_bitmap_num, sizeof(int), 1, fp );
2393
2394         fwrite( &Num_reactors, sizeof(Num_reactors), 1, fp );
2395         fwrite( Reactors, sizeof(*Reactors), Num_reactors, fp);
2396
2397 fprintf(tfile,"Num_reactors = %d, Reactors array = %d\n",Num_reactors,sizeof(*Reactors)*Num_reactors);
2398
2399         fwrite( &Marker_model_num, sizeof(Marker_model_num), 1, fp);
2400
2401         //@@fwrite( &N_controlcen_guns, sizeof(int), 1, fp );
2402         //@@fwrite( controlcen_gun_points, sizeof(vms_vector), N_controlcen_guns, fp );
2403         //@@fwrite( controlcen_gun_dirs, sizeof(vms_vector), N_controlcen_guns, fp );
2404
2405         #ifdef SHAREWARE
2406         fwrite( &exit_modelnum, sizeof(int), 1, fp );
2407         fwrite( &destroyed_exit_modelnum, sizeof(int), 1, fp );
2408         #endif
2409
2410 fclose(tfile);
2411
2412         bm_write_extra_robots();
2413 }
2414
2415 bm_write_extra_robots()
2416 {
2417         FILE *fp;
2418         int t,i;
2419
2420         fp = fopen("robots.ham","wb");
2421
2422         t = 'XHAM';
2423         fwrite( &t, sizeof(int), 1, fp );
2424         t = 1;  //version
2425         fwrite( &t, sizeof(int), 1, fp );
2426
2427         //write weapon info
2428         t = N_weapon_types - N_D2_WEAPON_TYPES;
2429         fwrite( &t, sizeof(int), 1, fp );
2430         fwrite( &Weapon_info[N_D2_WEAPON_TYPES], sizeof(weapon_info), t, fp );
2431
2432         //now write robot info
2433
2434         t = N_robot_types - N_D2_ROBOT_TYPES;
2435         fwrite( &t, sizeof(int), 1, fp );
2436         fwrite( &Robot_info[N_D2_ROBOT_TYPES], sizeof(robot_info), t, fp );
2437
2438         t = N_robot_joints - N_D2_ROBOT_JOINTS;
2439         fwrite( &t, sizeof(int), 1, fp );
2440         fwrite( &Robot_joints[N_D2_ROBOT_JOINTS], sizeof(jointpos), t, fp );
2441
2442         t = N_polygon_models - N_D2_POLYGON_MODELS;
2443         fwrite( &t, sizeof(int), 1, fp );
2444         fwrite( &Polygon_models[N_D2_POLYGON_MODELS], sizeof(polymodel), t, fp );
2445
2446         for (i=N_D2_POLYGON_MODELS; i<N_polygon_models; i++ )   {
2447                 g3_uninit_polygon_model(Polygon_models[i].model_data);  //get RGB colors
2448                 fwrite( Polygon_models[i].model_data, sizeof(ubyte), Polygon_models[i].model_data_size, fp );
2449                 g3_init_polygon_model(Polygon_models[i].model_data);    //map colors again
2450         }
2451
2452         fwrite( &Dying_modelnums[N_D2_POLYGON_MODELS], sizeof(int), t, fp );
2453         fwrite( &Dead_modelnums[N_D2_POLYGON_MODELS], sizeof(int), t, fp );
2454
2455         t = N_ObjBitmaps - N_D2_OBJBITMAPS;
2456         fwrite( &t, sizeof(int), 1, fp );
2457         fwrite( &ObjBitmaps[N_D2_OBJBITMAPS], sizeof(bitmap_index), t, fp );
2458
2459         t = N_ObjBitmapPtrs - N_D2_OBJBITMAPPTRS;
2460         fwrite( &t, sizeof(int), 1, fp );
2461         fwrite( &ObjBitmapPtrs[N_D2_OBJBITMAPPTRS], sizeof(ushort), t, fp );
2462
2463         fwrite( ObjBitmapPtrs, sizeof(ushort), t, fp );
2464
2465         fclose(fp);
2466 }
2467
2468 #endif