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