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