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