1 /* $Id: dumpmine.c,v 1.10 2005-01-10 17:47:27 schaffner Exp $ */
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.
17 * Functions to dump text description of mine.
18 * An editor-only function, called at mine load time.
19 * To be read by a human to verify the correctness and completeness of a mine.
28 static char rcsid[] = "$Id: dumpmine.c,v 1.10 2005-01-10 17:47:27 schaffner Exp $";
44 #include "editor/editor.h"
67 extern ubyte bogus_data[64*64];
69 void dump_used_textures_level(FILE *my_file, int level_num);
70 void say_totals(FILE *my_file, char *level_name);
72 // ----------------------------------------------------------------------------
73 char *object_types(int objnum)
75 int type = Objects[objnum].type;
77 Assert((type >= 0) && (type < MAX_OBJECT_TYPES));
78 return Object_type_names[type];
81 // ----------------------------------------------------------------------------
82 char *object_ids(int objnum)
84 int type = Objects[objnum].type;
85 int id = Objects[objnum].id;
89 return Robot_names[id];
92 return Powerup_names[id];
99 void err_printf(FILE *my_file, char * format, ... )
104 va_start(args, format );
105 vsprintf(message,format,args);
108 mprintf((1, "%s", message));
109 fprintf(my_file, "%s", message);
113 void warning_printf(FILE *my_file, char * format, ... )
118 va_start(args, format );
119 vsprintf(message,format,args);
122 mprintf((0, "%s", message));
123 fprintf(my_file, "%s", message);
126 // ----------------------------------------------------------------------------
127 void write_exit_text(FILE *my_file)
131 fprintf(my_file, "-----------------------------------------------------------------------------\n");
132 fprintf(my_file, "Exit stuff\n");
134 // ---------- Find exit triggers ----------
136 for (i=0; i<Num_triggers; i++)
137 if (Triggers[i].type == TT_EXIT) {
140 fprintf(my_file, "Trigger %2i, is an exit trigger with %i links.\n", i, Triggers[i].num_links);
142 if (Triggers[i].num_links != 0)
143 err_printf(my_file, "Error: Exit triggers must have 0 links, this one has %i links.\n", Triggers[i].num_links);
145 // Find wall pointing to this trigger.
147 for (j=0; j<Num_walls; j++)
148 if (Walls[j].trigger == i) {
150 fprintf(my_file, "Exit trigger %i is in segment %i, on side %i, bound to wall %i\n", i, Walls[j].segnum, Walls[j].sidenum, j);
153 err_printf(my_file, "Error: Trigger %i is not bound to any wall.\n", i);
155 err_printf(my_file, "Error: Trigger %i is bound to %i walls.\n", i, count2);
160 err_printf(my_file, "Error: No exit trigger in this mine.\n");
162 err_printf(my_file, "Error: More than one exit trigger in this mine.\n");
164 fprintf(my_file, "\n");
166 // ---------- Find exit doors ----------
168 for (i=0; i<=Highest_segment_index; i++)
169 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
170 if (Segments[i].children[j] == -2) {
171 fprintf(my_file, "Segment %3i, side %i is an exit door.\n", i, j);
176 err_printf(my_file, "Error: No external wall in this mine.\n");
177 else if (count != 1) {
178 // -- warning_printf(my_file, "Warning: %i external walls in this mine.\n", count);
179 // -- warning_printf(my_file, "(If %i are secret exits, then no problem.)\n", count-1);
181 fprintf(my_file, "\n");
184 // ----------------------------------------------------------------------------
185 void write_key_text(FILE *my_file)
188 int red_count, blue_count, gold_count;
189 int red_count2, blue_count2, gold_count2;
190 int blue_segnum=-1, blue_sidenum=-1, red_segnum=-1, red_sidenum=-1, gold_segnum=-1, gold_sidenum=-1;
193 fprintf(my_file, "-----------------------------------------------------------------------------\n");
194 fprintf(my_file, "Key stuff:\n");
200 for (i=0; i<Num_walls; i++) {
201 if (Walls[i].keys & KEY_BLUE) {
202 fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the blue key.\n", i, Walls[i].segnum, Walls[i].sidenum);
203 if (blue_segnum == -1) {
204 blue_segnum = Walls[i].segnum;
205 blue_sidenum = Walls[i].sidenum;
208 connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[blue_segnum]);
209 if (connect_side != blue_sidenum) {
210 warning_printf(my_file, "Warning: This blue door at seg %i, is different than the one at seg %i, side %i\n", Walls[i].segnum, blue_segnum, blue_sidenum);
215 if (Walls[i].keys & KEY_RED) {
216 fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the red key.\n", i, Walls[i].segnum, Walls[i].sidenum);
217 if (red_segnum == -1) {
218 red_segnum = Walls[i].segnum;
219 red_sidenum = Walls[i].sidenum;
222 connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[red_segnum]);
223 if (connect_side != red_sidenum) {
224 warning_printf(my_file, "Warning: This red door at seg %i, is different than the one at seg %i, side %i\n", Walls[i].segnum, red_segnum, red_sidenum);
229 if (Walls[i].keys & KEY_GOLD) {
230 fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the gold key.\n", i, Walls[i].segnum, Walls[i].sidenum);
231 if (gold_segnum == -1) {
232 gold_segnum = Walls[i].segnum;
233 gold_sidenum = Walls[i].sidenum;
236 connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[gold_segnum]);
237 if (connect_side != gold_sidenum) {
238 warning_printf(my_file, "Warning: This gold door at seg %i, is different than the one at seg %i, side %i\n", Walls[i].segnum, gold_segnum, gold_sidenum);
246 warning_printf(my_file, "Warning: %i doors are keyed to the blue key.\n", blue_count);
249 warning_printf(my_file, "Warning: %i doors are keyed to the red key.\n", red_count);
252 warning_printf(my_file, "Warning: %i doors are keyed to the gold key.\n", gold_count);
258 for (i=0; i<=Highest_object_index; i++) {
259 if (Objects[i].type == OBJ_POWERUP)
260 if (Objects[i].id == POW_KEY_BLUE) {
261 fprintf(my_file, "The BLUE key is object %i in segment %i\n", i, Objects[i].segnum);
264 if (Objects[i].type == OBJ_POWERUP)
265 if (Objects[i].id == POW_KEY_RED) {
266 fprintf(my_file, "The RED key is object %i in segment %i\n", i, Objects[i].segnum);
269 if (Objects[i].type == OBJ_POWERUP)
270 if (Objects[i].id == POW_KEY_GOLD) {
271 fprintf(my_file, "The GOLD key is object %i in segment %i\n", i, Objects[i].segnum);
275 if (Objects[i].contains_count) {
276 if (Objects[i].contains_type == OBJ_POWERUP) {
277 switch (Objects[i].contains_id) {
279 fprintf(my_file, "The BLUE key is contained in object %i (a %s %s) in segment %i\n", i, Object_type_names[Objects[i].type], Robot_names[Objects[i].id], Objects[i].segnum);
280 blue_count2 += Objects[i].contains_count;
283 fprintf(my_file, "The GOLD key is contained in object %i (a %s %s) in segment %i\n", i, Object_type_names[Objects[i].type], Robot_names[Objects[i].id], Objects[i].segnum);
284 gold_count2 += Objects[i].contains_count;
287 fprintf(my_file, "The RED key is contained in object %i (a %s %s) in segment %i\n", i, Object_type_names[Objects[i].type], Robot_names[Objects[i].id], Objects[i].segnum);
288 red_count2 += Objects[i].contains_count;
298 if (blue_count2 == 0)
299 err_printf(my_file, "Error: There is a door keyed to the blue key, but no blue key!\n");
303 err_printf(my_file, "Error: There is a door keyed to the red key, but no red key!\n");
306 if (gold_count2 == 0)
307 err_printf(my_file, "Error: There is a door keyed to the gold key, but no gold key!\n");
310 err_printf(my_file, "Error: There are %i blue keys!\n", blue_count2);
313 err_printf(my_file, "Error: There are %i red keys!\n", red_count2);
316 err_printf(my_file, "Error: There are %i gold keys!\n", gold_count2);
319 // ----------------------------------------------------------------------------
320 void write_control_center_text(FILE *my_file)
322 int i, count, objnum, count2;
324 fprintf(my_file, "-----------------------------------------------------------------------------\n");
325 fprintf(my_file, "Control Center stuff:\n");
328 for (i=0; i<=Highest_segment_index; i++)
329 if (Segment2s[i].special == SEGMENT_IS_CONTROLCEN) {
331 fprintf(my_file, "Segment %3i is a control center.\n", i);
332 objnum = Segments[i].objects;
334 while (objnum != -1) {
335 if (Objects[objnum].type == OBJ_CNTRLCEN)
337 objnum = Objects[objnum].next;
340 fprintf(my_file, "No control center object in control center segment.\n");
341 else if (count2 != 1)
342 fprintf(my_file, "%i control center objects in control center segment.\n", count2);
346 err_printf(my_file, "Error: No control center in this mine.\n");
348 err_printf(my_file, "Error: More than one control center in this mine.\n");
351 // ----------------------------------------------------------------------------
352 void write_fuelcen_text(FILE *my_file)
356 fprintf(my_file, "-----------------------------------------------------------------------------\n");
357 fprintf(my_file, "Fuel Center stuff: (Note: This means fuel, repair, materialize, control centers!)\n");
359 for (i=0; i<Num_fuelcenters; i++) {
360 fprintf(my_file, "Fuelcenter %i: Type=%i (%s), segment = %3i\n", i, Station[i].Type, Special_names[Station[i].Type], Station[i].segnum);
361 if (Segment2s[Station[i].segnum].special != Station[i].Type)
362 err_printf(my_file, "Error: Conflicting data: Segment %i has special type %i (%s), expected to be %i\n", Station[i].segnum, Segment2s[Station[i].segnum].special, Special_names[Segment2s[Station[i].segnum].special], Station[i].Type);
366 // ----------------------------------------------------------------------------
367 void write_segment_text(FILE *my_file)
371 fprintf(my_file, "-----------------------------------------------------------------------------\n");
372 fprintf(my_file, "Segment stuff:\n");
374 for (i=0; i<=Highest_segment_index; i++) {
376 fprintf(my_file, "Segment %4i: ", i);
377 if (Segment2s[i].special != 0)
378 fprintf(my_file, "special = %3i (%s), value = %3i ", Segment2s[i].special, Special_names[Segment2s[i].special], Segment2s[i].value);
380 if (Segment2s[i].matcen_num != -1)
381 fprintf(my_file, "matcen = %3i, ", Segment2s[i].matcen_num);
383 fprintf(my_file, "\n");
386 for (i=0; i<=Highest_segment_index; i++) {
389 objnum = Segments[i].objects;
390 fprintf(my_file, "Segment %4i: ", i);
393 fprintf(my_file, "Objects: ");
394 while (objnum != -1) {
395 fprintf(my_file, "[%8s %8s %3i] ", object_types(objnum), object_ids(objnum), objnum);
396 objnum = Objects[objnum].next;
398 fprintf(my_file, "\nAborted after %i links\n", depth);
403 fprintf(my_file, "\n");
407 // ----------------------------------------------------------------------------
408 // This routine is bogus. It assumes that all centers are matcens,
409 // which is not true. The setting of segnum is bogus.
410 void write_matcen_text(FILE *my_file)
414 fprintf(my_file, "-----------------------------------------------------------------------------\n");
415 fprintf(my_file, "Materialization centers:\n");
416 for (i=0; i<Num_robot_centers; i++) {
417 int trigger_count=0, segnum, fuelcen_num;
419 fprintf(my_file, "FuelCenter[%02i].Segment = %04i ", i, Station[i].segnum);
420 fprintf(my_file, "Segment2[%04i].matcen_num = %02i ", Station[i].segnum, Segment2s[Station[i].segnum].matcen_num);
422 fuelcen_num = RobotCenters[i].fuelcen_num;
423 if (Station[fuelcen_num].Type != SEGMENT_IS_ROBOTMAKER)
424 err_printf(my_file, "Error: Matcen %i corresponds to Station %i, which has type %i (%s).\n", i, fuelcen_num, Station[fuelcen_num].Type, Special_names[Station[fuelcen_num].Type]);
426 segnum = Station[fuelcen_num].segnum;
428 // Find trigger for this materialization center.
429 for (j=0; j<Num_triggers; j++) {
430 if (Triggers[j].type == TT_MATCEN) {
431 for (k=0; k<Triggers[j].num_links; k++)
432 if (Triggers[j].seg[k] == segnum) {
433 fprintf(my_file, "Trigger = %2i ", j );
438 fprintf(my_file, "\n");
440 if (trigger_count == 0)
441 err_printf(my_file, "Error: Matcen %i in segment %i has no trigger!\n", i, segnum);
446 // ----------------------------------------------------------------------------
447 void write_wall_text(FILE *my_file)
450 sbyte wall_flags[MAX_WALLS];
452 fprintf(my_file, "-----------------------------------------------------------------------------\n");
453 fprintf(my_file, "Walls:\n");
454 for (i=0; i<Num_walls; i++) {
457 fprintf(my_file, "Wall %03i: seg=%3i, side=%2i, linked_wall=%3i, type=%s, flags=%4x, hps=%3i, trigger=%2i, clip_num=%2i, keys=%2i, state=%i\n", i,
458 Walls[i].segnum, Walls[i].sidenum, Walls[i].linked_wall, Wall_names[Walls[i].type], Walls[i].flags, Walls[i].hps >> 16, Walls[i].trigger, Walls[i].clip_num, Walls[i].keys, Walls[i].state);
460 if (Walls[i].trigger >= Num_triggers)
461 fprintf(my_file, "Wall %03d points to invalid trigger %d\n",i,Walls[i].trigger);
463 segnum = Walls[i].segnum;
464 sidenum = Walls[i].sidenum;
466 if (Segments[segnum].sides[sidenum].wall_num != i)
467 err_printf(my_file, "Error: Wall %i points at segment %i, side %i, but that segment doesn't point back (it's wall_num = %i)\n", i, segnum, sidenum, Segments[segnum].sides[sidenum].wall_num);
470 for (i=0; i<MAX_WALLS; i++)
473 for (i=0; i<=Highest_segment_index; i++) {
474 segment *segp = &Segments[i];
475 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++) {
476 side *sidep = &segp->sides[j];
477 if (sidep->wall_num != -1)
478 if (wall_flags[sidep->wall_num])
479 err_printf(my_file, "Error: Wall %i appears in two or more segments, including segment %i, side %i.\n", sidep->wall_num, i, j);
481 wall_flags[sidep->wall_num] = 1;
487 //typedef struct trigger {
494 // short seg[MAX_WALLS_PER_LINK];
495 // short side[MAX_WALLS_PER_LINK];
498 // ----------------------------------------------------------------------------
499 void write_player_text(FILE *my_file)
501 int i, num_players=0;
503 fprintf(my_file, "-----------------------------------------------------------------------------\n");
504 fprintf(my_file, "Players:\n");
505 for (i=0; i<=Highest_object_index; i++) {
506 if (Objects[i].type == OBJ_PLAYER) {
508 fprintf(my_file, "Player %2i is object #%3i in segment #%3i.\n", Objects[i].id, i, Objects[i].segnum);
512 if (num_players != MAX_PLAYERS)
513 err_printf(my_file, "Error: %i player objects. %i are required.\n", num_players, MAX_PLAYERS);
514 if (num_players > MAX_MULTI_PLAYERS)
515 err_printf(my_file, "Error: %i player objects. %i are required.\n", num_players, MAX_PLAYERS);
518 // ----------------------------------------------------------------------------
519 void write_trigger_text(FILE *my_file)
523 fprintf(my_file, "-----------------------------------------------------------------------------\n");
524 fprintf(my_file, "Triggers:\n");
525 for (i=0; i<Num_triggers; i++) {
526 fprintf(my_file, "Trigger %03i: type=%02x flags=%04x, value=%08x, time=%8x, num_links=%i ", i,
527 Triggers[i].type, Triggers[i].flags, Triggers[i].value, Triggers[i].time, Triggers[i].num_links);
529 for (j=0; j<Triggers[i].num_links; j++)
530 fprintf(my_file, "[%03i:%i] ", Triggers[i].seg[j], Triggers[i].side[j]);
532 // Find which wall this trigger is connected to.
533 for (w=0; w<Num_walls; w++)
534 if (Walls[w].trigger == i)
538 err_printf(my_file, "\nError: Trigger %i is not connected to any wall, so it can never be triggered.\n", i);
540 fprintf(my_file, "Attached to seg:side = %i:%i, wall %i\n", Walls[w].segnum, Walls[w].sidenum, Segments[Walls[w].segnum].sides[Walls[w].sidenum].wall_num);
546 // ----------------------------------------------------------------------------
547 void write_game_text_file(char *filename)
549 char my_filename[128];
555 // mprintf((0, "Writing text file for mine [%s]\n", filename));
557 namelen = strlen(filename);
559 Assert (namelen > 4);
561 Assert (filename[namelen-4] == '.');
563 strcpy(my_filename, filename);
564 strcpy( &my_filename[namelen-4], ".txm");
566 // mprintf((0, "Writing text file [%s]\n", my_filename));
568 my_file = fopen( my_filename, "wt" );
569 // -- mprintf((1, "Fileno = %i\n", fileno(my_file)));
572 char ErrorMessage[200];
574 sprintf(ErrorMessage, "ERROR: Unable to open %s\nErrno = %i", my_filename, errno);
576 gr_palette_load(gr_palette);
577 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
583 dump_used_textures_level(my_file, 0);
584 say_totals(my_file, Gamesave_current_filename);
586 fprintf(my_file, "\nNumber of segments: %4i\n", Highest_segment_index+1);
587 fprintf(my_file, "Number of objects: %4i\n", Highest_object_index+1);
588 fprintf(my_file, "Number of walls: %4i\n", Num_walls);
589 fprintf(my_file, "Number of open doors: %4i\n", Num_open_doors);
590 fprintf(my_file, "Number of triggers: %4i\n", Num_triggers);
591 fprintf(my_file, "Number of matcens: %4i\n", Num_robot_centers);
592 fprintf(my_file, "\n");
594 write_segment_text(my_file);
596 write_fuelcen_text(my_file);
598 write_matcen_text(my_file);
600 write_player_text(my_file);
602 write_wall_text(my_file);
604 write_trigger_text(my_file);
606 write_exit_text(my_file);
608 // ---------- Find control center segment ----------
609 write_control_center_text(my_file);
611 // ---------- Show keyed walls ----------
612 write_key_text(my_file);
616 mprintf((1, "Close value = %i\n", r));
622 // -- // ---------------
623 // -- // Note: This only works for a loaded level because the objects array must be valid.
624 // -- void determine_used_textures_robots(int *tmap_buf)
629 // -- Assert(N_polygon_models);
631 // -- for (objnum=0; objnum <= Highest_object_index; objnum++) {
634 // -- if (Objects[objnum].render_type == RT_POLYOBJ) {
635 // -- model_num = Objects[objnum].rtype.pobj_info.model_num;
637 // -- po=&Polygon_models[model_num];
639 // -- for (i=0;i<po->n_textures;i++) {
642 // -- tli = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]];
643 // -- Assert((tli>=0) && (tli<= Num_tmaps));
644 // -- tmap_buf[tli]++;
651 // --05/17/95--// -----------------------------------------------------------------------------
652 // --05/17/95--void determine_used_textures_level(int load_level_flag, int shareware_flag, int level_num, int *tmap_buf, int *wall_buf, sbyte *level_tmap_buf, int max_tmap)
654 // --05/17/95-- int segnum, sidenum;
655 // --05/17/95-- int i, j;
657 // --05/17/95-- for (i=0; i<max_tmap; i++)
658 // --05/17/95-- tmap_buf[i] = 0;
660 // --05/17/95-- if (load_level_flag) {
661 // --05/17/95-- if (shareware_flag)
662 // --05/17/95-- load_level(Shareware_level_names[level_num]);
664 // --05/17/95-- load_level(Registered_level_names[level_num]);
667 // --05/17/95-- for (segnum=0; segnum<=Highest_segment_index; segnum++) {
668 // --05/17/95-- segment *segp = &Segments[segnum];
670 // --05/17/95-- for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
671 // --05/17/95-- side *sidep = &segp->sides[sidenum];
673 // --05/17/95-- if (sidep->wall_num != -1) {
674 // --05/17/95-- int clip_num = Walls[sidep->wall_num].clip_num;
675 // --05/17/95-- if (clip_num != -1) {
677 // --05/17/95-- int num_frames = WallAnims[clip_num].num_frames;
679 // --05/17/95-- wall_buf[clip_num] = 1;
681 // --05/17/95-- for (j=0; j<num_frames; j++) {
682 // --05/17/95-- int tmap_num;
684 // --05/17/95-- tmap_num = WallAnims[clip_num].frames[j];
685 // --05/17/95-- tmap_buf[tmap_num]++;
686 // --05/17/95-- if (level_tmap_buf[tmap_num] == -1)
687 // --05/17/95-- level_tmap_buf[tmap_num] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS;
692 // --05/17/95-- if (sidep->tmap_num >= 0)
693 // --05/17/95-- if (sidep->tmap_num < max_tmap) {
694 // --05/17/95-- tmap_buf[sidep->tmap_num]++;
695 // --05/17/95-- if (level_tmap_buf[sidep->tmap_num] == -1)
696 // --05/17/95-- level_tmap_buf[sidep->tmap_num] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS;
697 // --05/17/95-- } else
698 // --05/17/95-- Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
700 // --05/17/95-- if ((sidep->tmap_num2 & 0x3fff) != 0)
701 // --05/17/95-- if ((sidep->tmap_num2 & 0x3fff) < max_tmap) {
702 // --05/17/95-- tmap_buf[sidep->tmap_num2 & 0x3fff]++;
703 // --05/17/95-- if (level_tmap_buf[sidep->tmap_num2 & 0x3fff] == -1)
704 // --05/17/95-- level_tmap_buf[sidep->tmap_num2 & 0x3fff] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS;
705 // --05/17/95-- } else
706 // --05/17/95-- Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
711 // Adam: Change NUM_ADAM_LEVELS to the number of levels.
712 #define NUM_ADAM_LEVELS 30
714 // Adam: Stick the names here.
715 char *Adam_level_names[NUM_ADAM_LEVELS] = {
753 typedef struct BitmapFile {
757 extern BitmapFile AllBitmaps[ MAX_BITMAP_FILES ];
759 int Ignore_tmap_num2_error;
761 // ----------------------------------------------------------------------------
762 void determine_used_textures_level(int load_level_flag, int shareware_flag, int level_num, int *tmap_buf, int *wall_buf, sbyte *level_tmap_buf, int max_tmap)
764 int segnum, sidenum, objnum=max_tmap;
767 Assert(shareware_flag != -17);
769 for (i=0; i<MAX_BITMAP_FILES; i++)
772 if (load_level_flag) {
773 load_level(Adam_level_names[level_num]);
778 for (objnum=0; objnum<=Highest_object_index; objnum++) {
779 object *objp = &Objects[objnum];
781 if (objp->render_type == RT_POLYOBJ) {
782 polymodel *po = &Polygon_models[objp->rtype.pobj_info.model_num];
784 for (i=0; i<po->n_textures; i++) {
786 int tli = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index;
787 // -- mprintf((0, "%s ", AllBitmaps[ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index].name));
789 if ((tli < MAX_BITMAP_FILES) && (tli >= 0)) {
791 if (level_tmap_buf[tli] == -1)
792 level_tmap_buf[tli] = level_num;
794 Int3(); // Hmm, It seems this texture is bogus!
801 Ignore_tmap_num2_error = 0;
803 // Process walls and segment sides.
804 for (segnum=0; segnum<=Highest_segment_index; segnum++) {
805 segment *segp = &Segments[segnum];
807 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
808 side *sidep = &segp->sides[sidenum];
810 if (sidep->wall_num != -1) {
811 int clip_num = Walls[sidep->wall_num].clip_num;
812 if (clip_num != -1) {
814 // -- int num_frames = WallAnims[clip_num].num_frames;
816 wall_buf[clip_num] = 1;
818 for (j=0; j<1; j++) { // Used to do through num_frames, but don't really want all the door01#3 stuff.
821 tmap_num = Textures[WallAnims[clip_num].frames[j]].index;
822 Assert((tmap_num >= 0) && (tmap_num < MAX_BITMAP_FILES));
823 tmap_buf[tmap_num]++;
824 if (level_tmap_buf[tmap_num] == -1)
825 level_tmap_buf[tmap_num] = level_num;
828 } else if (segp->children[sidenum] == -1) {
830 if (sidep->tmap_num >= 0)
831 if (sidep->tmap_num < MAX_BITMAP_FILES) {
832 Assert(Textures[sidep->tmap_num].index < MAX_BITMAP_FILES);
833 tmap_buf[Textures[sidep->tmap_num].index]++;
834 if (level_tmap_buf[Textures[sidep->tmap_num].index] == -1)
835 level_tmap_buf[Textures[sidep->tmap_num].index] = level_num;
837 Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
839 if ((sidep->tmap_num2 & 0x3fff) != 0)
840 if ((sidep->tmap_num2 & 0x3fff) < MAX_BITMAP_FILES) {
841 Assert(Textures[sidep->tmap_num2 & 0x3fff].index < MAX_BITMAP_FILES);
842 tmap_buf[Textures[sidep->tmap_num2 & 0x3fff].index]++;
843 if (level_tmap_buf[Textures[sidep->tmap_num2 & 0x3fff].index] == -1)
844 level_tmap_buf[Textures[sidep->tmap_num2 & 0x3fff].index] = level_num;
846 if (!Ignore_tmap_num2_error)
847 Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
848 Ignore_tmap_num2_error = 1;
849 sidep->tmap_num2 = 0;
856 // ----------------------------------------------------------------------------
857 void merge_buffers(int *dest, int *src, int num)
861 for (i=0; i<num; i++)
866 // ----------------------------------------------------------------------------
867 void say_used_tmaps(FILE *my_file, int *tb)
870 // -- mk, 08/14/95 -- int count = 0;
872 for (i=0; i<MAX_BITMAP_FILES; i++)
874 fprintf(my_file, "[%3i %8s (%4i)]\n", i, AllBitmaps[i].name, tb[i]);
875 // -- mk, 08/14/95 -- if (count++ >= 4) {
876 // -- mk, 08/14/95 -- fprintf(my_file, "\n");
877 // -- mk, 08/14/95 -- count = 0;
878 // -- mk, 08/14/95 -- }
882 // --05/17/95--// -----------------------------------------------------------------------------
883 // --05/17/95--void say_used_once_tmaps(FILE *my_file, int *tb, sbyte *tb_lnum)
885 // --05/17/95-- int i;
886 // --05/17/95-- char *level_name;
888 // --05/17/95-- for (i=0; i<Num_tmaps; i++)
889 // --05/17/95-- if (tb[i] == 1) {
890 // --05/17/95-- int level_num = tb_lnum[i];
891 // --05/17/95-- if (level_num >= NUM_SHAREWARE_LEVELS) {
892 // --05/17/95-- Assert((level_num - NUM_SHAREWARE_LEVELS >= 0) && (level_num - NUM_SHAREWARE_LEVELS < NUM_REGISTERED_LEVELS));
893 // --05/17/95-- level_name = Registered_level_names[level_num - NUM_SHAREWARE_LEVELS];
894 // --05/17/95-- } else {
895 // --05/17/95-- Assert((level_num >= 0) && (level_num < NUM_SHAREWARE_LEVELS));
896 // --05/17/95-- level_name = Shareware_level_names[level_num];
899 // --05/17/95-- fprintf(my_file, "Texture %3i %8s used only once on level %s\n", i, TmapInfo[i].filename, level_name);
903 // ----------------------------------------------------------------------------
904 void say_used_once_tmaps(FILE *my_file, int *tb, sbyte *tb_lnum)
909 for (i=0; i<MAX_BITMAP_FILES; i++)
911 int level_num = tb_lnum[i];
912 level_name = Adam_level_names[level_num];
914 fprintf(my_file, "Texture %3i %8s used only once on level %s\n", i, AllBitmaps[i].name, level_name);
918 // ----------------------------------------------------------------------------
919 void say_unused_tmaps(FILE *my_file, int *tb)
924 for (i=0; i<MAX_BITMAP_FILES; i++)
926 if (GameBitmaps[Textures[i].index].bm_data == bogus_data)
927 fprintf(my_file, "U");
929 fprintf(my_file, " ");
931 fprintf(my_file, "[%3i %8s] ", i, AllBitmaps[i].name);
933 fprintf(my_file, "\n");
939 // ----------------------------------------------------------------------------
940 void say_unused_walls(FILE *my_file, int *tb)
944 for (i=0; i<Num_wall_anims; i++)
946 fprintf(my_file, "Wall %3i is unused.\n", i);
949 // ----------------------------------------------------------------------------
950 void say_totals(FILE *my_file, char *level_name)
953 int total_robots = 0;
954 int objects_processed = 0;
956 int used_objects[MAX_OBJECTS];
958 fprintf(my_file, "\nLevel %s\n", level_name);
960 for (i=0; i<MAX_OBJECTS; i++)
963 while (objects_processed < Highest_object_index+1) {
964 int j, objtype, objid, objcount, cur_obj_val, min_obj_val, min_objnum;
966 // Find new min objnum.
967 min_obj_val = 0x7fff0000;
970 for (j=0; j<=Highest_object_index; j++) {
971 if (!used_objects[j] && Objects[j].type!=OBJ_NONE) {
972 cur_obj_val = Objects[j].type * 1000 + Objects[j].id;
973 if (cur_obj_val < min_obj_val) {
975 min_obj_val = cur_obj_val;
979 if ((min_objnum == -1) || (Objects[min_objnum].type == 255))
984 objtype = Objects[min_objnum].type;
985 objid = Objects[min_objnum].id;
987 for (i=0; i<=Highest_object_index; i++) {
988 if (!used_objects[i]) {
990 if (((Objects[i].type == objtype) && (Objects[i].id == objid)) ||
991 ((Objects[i].type == objtype) && (objtype == OBJ_PLAYER)) ||
992 ((Objects[i].type == objtype) && (objtype == OBJ_COOP)) ||
993 ((Objects[i].type == objtype) && (objtype == OBJ_HOSTAGE))) {
994 if (Objects[i].type == OBJ_ROBOT)
1004 fprintf(my_file, "Object: ");
1005 fprintf(my_file, "%8s %8s %3i\n", object_types(min_objnum), object_ids(min_objnum), objcount);
1009 fprintf(my_file, "Total robots = %3i\n", total_robots);
1012 int First_dump_level = 0;
1013 int Last_dump_level = NUM_ADAM_LEVELS-1;
1015 // ----------------------------------------------------------------------------
1016 void say_totals_all(void)
1021 my_file = fopen( "levels.all", "wt" );
1022 // -- mprintf((1, "Fileno = %i\n", fileno(my_file)));
1025 char ErrorMessage[200];
1027 sprintf( ErrorMessage, "ERROR: Unable to open levels.all\nErrno=%i", errno );
1029 gr_palette_load(gr_palette);
1030 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
1036 for (i=First_dump_level; i<=Last_dump_level; i++) {
1037 mprintf((0, "Level %i\n", i+1));
1038 load_level(Adam_level_names[i]);
1039 say_totals(my_file, Adam_level_names[i]);
1042 //--05/17/95-- for (i=0; i<NUM_SHAREWARE_LEVELS; i++) {
1043 //--05/17/95-- mprintf((0, "Level %i\n", i+1));
1044 //--05/17/95-- load_level(Shareware_level_names[i]);
1045 //--05/17/95-- say_totals(my_file, Shareware_level_names[i]);
1048 //--05/17/95-- for (i=0; i<NUM_REGISTERED_LEVELS; i++) {
1049 //--05/17/95-- mprintf((0, "Level %i\n", i+1+NUM_SHAREWARE_LEVELS));
1050 //--05/17/95-- load_level(Registered_level_names[i]);
1051 //--05/17/95-- say_totals(my_file, Registered_level_names[i]);
1058 void dump_used_textures_level(FILE *my_file, int level_num)
1061 int temp_tmap_buf[MAX_BITMAP_FILES];
1062 int perm_tmap_buf[MAX_BITMAP_FILES];
1063 sbyte level_tmap_buf[MAX_BITMAP_FILES];
1064 int temp_wall_buf[MAX_BITMAP_FILES];
1065 int perm_wall_buf[MAX_BITMAP_FILES];
1067 for (i=0; i<MAX_BITMAP_FILES; i++) {
1068 perm_tmap_buf[i] = 0;
1069 level_tmap_buf[i] = -1;
1072 for (i=0; i<MAX_BITMAP_FILES; i++) {
1073 perm_wall_buf[i] = 0;
1076 determine_used_textures_level(0, 1, level_num, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1077 // -- determine_used_textures_robots(temp_tmap_buf);
1078 fprintf(my_file, "\nTextures used in [%s]\n", Gamesave_current_filename);
1079 say_used_tmaps(my_file, temp_tmap_buf);
1084 // ----------------------------------------------------------------------------
1085 void dump_used_textures_all(void)
1088 int temp_tmap_buf[MAX_BITMAP_FILES];
1089 int perm_tmap_buf[MAX_BITMAP_FILES];
1090 sbyte level_tmap_buf[MAX_BITMAP_FILES];
1091 int temp_wall_buf[MAX_BITMAP_FILES];
1092 int perm_wall_buf[MAX_BITMAP_FILES];
1096 my_file = fopen( "textures.dmp", "wt" );
1097 // -- mprintf((1, "Fileno = %i\n", fileno(my_file)));
1100 char ErrorMessage[200];
1102 sprintf( ErrorMessage, "ERROR: Can't open textures.dmp\nErrno=%i", errno);
1104 gr_palette_load(gr_palette);
1105 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
1111 for (i=0; i<MAX_BITMAP_FILES; i++) {
1112 perm_tmap_buf[i] = 0;
1113 level_tmap_buf[i] = -1;
1116 for (i=0; i<MAX_BITMAP_FILES; i++) {
1117 perm_wall_buf[i] = 0;
1120 // --05/17/95-- for (i=0; i<NUM_SHAREWARE_LEVELS; i++) {
1121 // --05/17/95-- determine_used_textures_level(1, 1, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1122 // --05/17/95-- fprintf(my_file, "\nTextures used in [%s]\n", Shareware_level_names[i]);
1123 // --05/17/95-- say_used_tmaps(my_file, temp_tmap_buf);
1124 // --05/17/95-- merge_buffers(perm_tmap_buf, temp_tmap_buf, MAX_BITMAP_FILES);
1125 // --05/17/95-- merge_buffers(perm_wall_buf, temp_wall_buf, MAX_BITMAP_FILES);
1128 // --05/17/95-- fprintf(my_file, "\n\nUsed textures in all shareware mines:\n");
1129 // --05/17/95-- say_used_tmaps(my_file, perm_tmap_buf);
1131 // --05/17/95-- fprintf(my_file, "\nUnused textures in all shareware mines:\n");
1132 // --05/17/95-- say_unused_tmaps(my_file, perm_tmap_buf);
1134 // --05/17/95-- fprintf(my_file, "\nTextures used exactly once in all shareware mines:\n");
1135 // --05/17/95-- say_used_once_tmaps(my_file, perm_tmap_buf, level_tmap_buf);
1137 // --05/17/95-- fprintf(my_file, "\nWall anims (eg, doors) unused in all shareware mines:\n");
1138 // --05/17/95-- say_unused_walls(my_file, perm_wall_buf);
1140 // --05/17/95-- for (i=0; i<NUM_REGISTERED_LEVELS; i++) {
1141 // --05/17/95-- determine_used_textures_level(1, 0, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1142 // --05/17/95-- fprintf(my_file, "\nTextures used in [%s]\n", Registered_level_names[i]);
1143 // --05/17/95-- say_used_tmaps(my_file, temp_tmap_buf);
1144 // --05/17/95-- merge_buffers(perm_tmap_buf, temp_tmap_buf, MAX_BITMAP_FILES);
1147 // --05/17/95-- fprintf(my_file, "\n\nUsed textures in all (including registered) mines:\n");
1148 // --05/17/95-- say_used_tmaps(my_file, perm_tmap_buf);
1150 // --05/17/95-- fprintf(my_file, "\nUnused textures in all (including registered) mines:\n");
1151 // --05/17/95-- say_unused_tmaps(my_file, perm_tmap_buf);
1153 for (i=First_dump_level; i<=Last_dump_level; i++) {
1154 determine_used_textures_level(1, 0, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1155 fprintf(my_file, "\nTextures used in [%s]\n", Adam_level_names[i]);
1156 say_used_tmaps(my_file, temp_tmap_buf);
1157 merge_buffers(perm_tmap_buf, temp_tmap_buf, MAX_BITMAP_FILES);
1160 fprintf(my_file, "\n\nUsed textures in all (including registered) mines:\n");
1161 say_used_tmaps(my_file, perm_tmap_buf);
1163 fprintf(my_file, "\nUnused textures in all (including registered) mines:\n");
1164 say_unused_tmaps(my_file, perm_tmap_buf);