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