1 /* $Id: dumpmine.c,v 1.5 2004-08-28 23:17:45 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.5 2004-08-28 23:17:45 schaffner Exp $";
44 #include "editor/editor.h"
67 extern ubyte bogus_data[64*64];
68 extern grs_bitmap bogus_bitmap;
70 // ----------------------------------------------------------------------------
71 char *object_types(int objnum)
73 int type = Objects[objnum].type;
75 Assert((type >= 0) && (type < MAX_OBJECT_TYPES));
76 return &Object_type_names[type];
79 // ----------------------------------------------------------------------------
80 char *object_ids(int objnum)
82 int type = Objects[objnum].type;
83 int id = Objects[objnum].id;
87 return &Robot_names[id];
90 return &Powerup_names[id];
97 void err_printf(FILE *my_file, char * format, ... )
102 va_start(args, format );
103 vsprintf(message,format,args);
106 mprintf((1, "%s", message));
107 fprintf(my_file, "%s", message);
111 void warning_printf(FILE *my_file, char * format, ... )
116 va_start(args, format );
117 vsprintf(message,format,args);
120 mprintf((0, "%s", message));
121 fprintf(my_file, "%s", message);
124 // ----------------------------------------------------------------------------
125 void write_exit_text(FILE *my_file)
129 fprintf(my_file, "-----------------------------------------------------------------------------\n");
130 fprintf(my_file, "Exit stuff\n");
132 // ---------- Find exit triggers ----------
134 for (i=0; i<Num_triggers; i++)
135 if (Triggers[i].type == TT_EXIT) {
138 fprintf(my_file, "Trigger %2i, is an exit trigger with %i links.\n", i, Triggers[i].num_links);
140 if (Triggers[i].num_links != 0)
141 err_printf(my_file, "Error: Exit triggers must have 0 links, this one has %i links.\n", Triggers[i].num_links);
143 // Find wall pointing to this trigger.
145 for (j=0; j<Num_walls; j++)
146 if (Walls[j].trigger == i) {
148 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);
151 err_printf(my_file, "Error: Trigger %i is not bound to any wall.\n", i);
153 err_printf(my_file, "Error: Trigger %i is bound to %i walls.\n", i, count2);
158 err_printf(my_file, "Error: No exit trigger in this mine.\n");
160 err_printf(my_file, "Error: More than one exit trigger in this mine.\n");
162 fprintf(my_file, "\n");
164 // ---------- Find exit doors ----------
166 for (i=0; i<=Highest_segment_index; i++)
167 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
168 if (Segments[i].children[j] == -2) {
169 fprintf(my_file, "Segment %3i, side %i is an exit door.\n", i, j);
174 err_printf(my_file, "Error: No external wall in this mine.\n");
175 else if (count != 1) {
176 // -- warning_printf(my_file, "Warning: %i external walls in this mine.\n", count);
177 // -- warning_printf(my_file, "(If %i are secret exits, then no problem.)\n", count-1);
179 fprintf(my_file, "\n");
182 // ----------------------------------------------------------------------------
183 void write_key_text(FILE *my_file)
186 int red_count, blue_count, gold_count;
187 int red_count2, blue_count2, gold_count2;
188 int blue_segnum=-1, blue_sidenum=-1, red_segnum=-1, red_sidenum=-1, gold_segnum=-1, gold_sidenum=-1;
191 fprintf(my_file, "-----------------------------------------------------------------------------\n");
192 fprintf(my_file, "Key stuff:\n");
198 for (i=0; i<Num_walls; i++) {
199 if (Walls[i].keys & KEY_BLUE) {
200 fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the blue key.\n", i, Walls[i].segnum, Walls[i].sidenum);
201 if (blue_segnum == -1) {
202 blue_segnum = Walls[i].segnum;
203 blue_sidenum = Walls[i].sidenum;
206 connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[blue_segnum]);
207 if (connect_side != blue_sidenum) {
208 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);
213 if (Walls[i].keys & KEY_RED) {
214 fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the red key.\n", i, Walls[i].segnum, Walls[i].sidenum);
215 if (red_segnum == -1) {
216 red_segnum = Walls[i].segnum;
217 red_sidenum = Walls[i].sidenum;
220 connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[red_segnum]);
221 if (connect_side != red_sidenum) {
222 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);
227 if (Walls[i].keys & KEY_GOLD) {
228 fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the gold key.\n", i, Walls[i].segnum, Walls[i].sidenum);
229 if (gold_segnum == -1) {
230 gold_segnum = Walls[i].segnum;
231 gold_sidenum = Walls[i].sidenum;
234 connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[gold_segnum]);
235 if (connect_side != gold_sidenum) {
236 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);
244 warning_printf(my_file, "Warning: %i doors are keyed to the blue key.\n", blue_count);
247 warning_printf(my_file, "Warning: %i doors are keyed to the red key.\n", red_count);
250 warning_printf(my_file, "Warning: %i doors are keyed to the gold key.\n", gold_count);
256 for (i=0; i<=Highest_object_index; i++) {
257 if (Objects[i].type == OBJ_POWERUP)
258 if (Objects[i].id == POW_KEY_BLUE) {
259 fprintf(my_file, "The BLUE key is object %i in segment %i\n", i, Objects[i].segnum);
262 if (Objects[i].type == OBJ_POWERUP)
263 if (Objects[i].id == POW_KEY_RED) {
264 fprintf(my_file, "The RED key is object %i in segment %i\n", i, Objects[i].segnum);
267 if (Objects[i].type == OBJ_POWERUP)
268 if (Objects[i].id == POW_KEY_GOLD) {
269 fprintf(my_file, "The GOLD key is object %i in segment %i\n", i, Objects[i].segnum);
273 if (Objects[i].contains_count) {
274 if (Objects[i].contains_type == OBJ_POWERUP) {
275 switch (Objects[i].contains_id) {
277 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);
278 blue_count2 += Objects[i].contains_count;
281 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);
282 gold_count2 += Objects[i].contains_count;
285 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);
286 red_count2 += Objects[i].contains_count;
296 if (blue_count2 == 0)
297 err_printf(my_file, "Error: There is a door keyed to the blue key, but no blue key!\n");
301 err_printf(my_file, "Error: There is a door keyed to the red key, but no red key!\n");
304 if (gold_count2 == 0)
305 err_printf(my_file, "Error: There is a door keyed to the gold key, but no gold key!\n");
308 err_printf(my_file, "Error: There are %i blue keys!\n", blue_count2);
311 err_printf(my_file, "Error: There are %i red keys!\n", red_count2);
314 err_printf(my_file, "Error: There are %i gold keys!\n", gold_count2);
317 // ----------------------------------------------------------------------------
318 void write_control_center_text(FILE *my_file)
320 int i, count, objnum, count2;
322 fprintf(my_file, "-----------------------------------------------------------------------------\n");
323 fprintf(my_file, "Control Center stuff:\n");
326 for (i=0; i<=Highest_segment_index; i++)
327 if (Segment2s[i].special == SEGMENT_IS_CONTROLCEN) {
329 fprintf(my_file, "Segment %3i is a control center.\n", i);
330 objnum = Segments[i].objects;
332 while (objnum != -1) {
333 if (Objects[objnum].type == OBJ_CNTRLCEN)
335 objnum = Objects[objnum].next;
338 fprintf(my_file, "No control center object in control center segment.\n");
339 else if (count2 != 1)
340 fprintf(my_file, "%i control center objects in control center segment.\n", count2);
344 err_printf(my_file, "Error: No control center in this mine.\n");
346 err_printf(my_file, "Error: More than one control center in this mine.\n");
349 // ----------------------------------------------------------------------------
350 void write_fuelcen_text(FILE *my_file)
354 fprintf(my_file, "-----------------------------------------------------------------------------\n");
355 fprintf(my_file, "Fuel Center stuff: (Note: This means fuel, repair, materialize, control centers!)\n");
357 for (i=0; i<Num_fuelcenters; i++) {
358 fprintf(my_file, "Fuelcenter %i: Type=%i (%s), segment = %3i\n", i, Station[i].Type, Special_names[Station[i].Type], Station[i].segnum);
359 if (Segment2s[Station[i].segnum].special != Station[i].Type)
360 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);
364 // ----------------------------------------------------------------------------
365 void write_segment_text(FILE *my_file)
369 fprintf(my_file, "-----------------------------------------------------------------------------\n");
370 fprintf(my_file, "Segment stuff:\n");
372 for (i=0; i<=Highest_segment_index; i++) {
374 fprintf(my_file, "Segment %4i: ", i);
375 if (Segment2s[i].special != 0)
376 fprintf(my_file, "special = %3i (%s), value = %3i ", Segment2s[i].special, Special_names[Segment2s[i].special], Segment2s[i].value);
378 if (Segment2s[i].matcen_num != -1)
379 fprintf(my_file, "matcen = %3i, ", Segment2s[i].matcen_num);
381 fprintf(my_file, "\n");
384 for (i=0; i<=Highest_segment_index; i++) {
387 objnum = Segments[i].objects;
388 fprintf(my_file, "Segment %4i: ", i);
391 fprintf(my_file, "Objects: ");
392 while (objnum != -1) {
393 fprintf(my_file, "[%8s %8s %3i] ", object_types(objnum), object_ids(objnum), objnum);
394 objnum = Objects[objnum].next;
396 fprintf(my_file, "\nAborted after %i links\n", depth);
401 fprintf(my_file, "\n");
405 // ----------------------------------------------------------------------------
406 // This routine is bogus. It assumes that all centers are matcens,
407 // which is not true. The setting of segnum is bogus.
408 void write_matcen_text(FILE *my_file)
412 fprintf(my_file, "-----------------------------------------------------------------------------\n");
413 fprintf(my_file, "Materialization centers:\n");
414 for (i=0; i<Num_robot_centers; i++) {
415 int trigger_count=0, segnum, fuelcen_num;
417 fprintf(my_file, "FuelCenter[%02i].Segment = %04i ", i, Station[i].segnum);
418 fprintf(my_file, "Segment2[%04i].matcen_num = %02i ", Station[i].segnum, Segment2s[Station[i].segnum].matcen_num);
420 fuelcen_num = RobotCenters[i].fuelcen_num;
421 if (Station[fuelcen_num].Type != SEGMENT_IS_ROBOTMAKER)
422 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]);
424 segnum = Station[fuelcen_num].segnum;
426 // Find trigger for this materialization center.
427 for (j=0; j<Num_triggers; j++) {
428 if (Triggers[j].type == TT_MATCEN) {
429 for (k=0; k<Triggers[j].num_links; k++)
430 if (Triggers[j].seg[k] == segnum) {
431 fprintf(my_file, "Trigger = %2i ", j );
436 fprintf(my_file, "\n");
438 if (trigger_count == 0)
439 err_printf(my_file, "Error: Matcen %i in segment %i has no trigger!\n", i, segnum);
444 // ----------------------------------------------------------------------------
445 void write_wall_text(FILE *my_file)
448 byte wall_flags[MAX_WALLS];
450 fprintf(my_file, "-----------------------------------------------------------------------------\n");
451 fprintf(my_file, "Walls:\n");
452 for (i=0; i<Num_walls; i++) {
455 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,
456 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);
458 if (Walls[i].trigger >= Num_triggers)
459 fprintf(my_file, "Wall %03d points to invalid trigger %d\n",i,Walls[i].trigger);
461 segnum = Walls[i].segnum;
462 sidenum = Walls[i].sidenum;
464 if (Segments[segnum].sides[sidenum].wall_num != i)
465 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);
468 for (i=0; i<MAX_WALLS; i++)
471 for (i=0; i<=Highest_segment_index; i++) {
472 segment *segp = &Segments[i];
473 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++) {
474 side *sidep = &segp->sides[j];
475 if (sidep->wall_num != -1)
476 if (wall_flags[sidep->wall_num])
477 err_printf(my_file, "Error: Wall %i appears in two or more segments, including segment %i, side %i.\n", sidep->wall_num, i, j);
479 wall_flags[sidep->wall_num] = 1;
485 //typedef struct trigger {
492 // short seg[MAX_WALLS_PER_LINK];
493 // short side[MAX_WALLS_PER_LINK];
496 // ----------------------------------------------------------------------------
497 void write_player_text(FILE *my_file)
499 int i, num_players=0;
501 fprintf(my_file, "-----------------------------------------------------------------------------\n");
502 fprintf(my_file, "Players:\n");
503 for (i=0; i<=Highest_object_index; i++) {
504 if (Objects[i].type == OBJ_PLAYER) {
506 fprintf(my_file, "Player %2i is object #%3i in segment #%3i.\n", Objects[i].id, i, Objects[i].segnum);
510 if (num_players != MAX_PLAYERS)
511 err_printf(my_file, "Error: %i player objects. %i are required.\n", num_players, MAX_PLAYERS);
512 if (num_players > MAX_MULTI_PLAYERS)
513 err_printf(my_file, "Error: %i player objects. %i are required.\n", num_players, MAX_PLAYERS);
516 // ----------------------------------------------------------------------------
517 void write_trigger_text(FILE *my_file)
521 fprintf(my_file, "-----------------------------------------------------------------------------\n");
522 fprintf(my_file, "Triggers:\n");
523 for (i=0; i<Num_triggers; i++) {
524 fprintf(my_file, "Trigger %03i: type=%02x flags=%04x, value=%08x, time=%8x, num_links=%i ", i,
525 Triggers[i].type, Triggers[i].flags, Triggers[i].value, Triggers[i].time, Triggers[i].num_links);
527 for (j=0; j<Triggers[i].num_links; j++)
528 fprintf(my_file, "[%03i:%i] ", Triggers[i].seg[j], Triggers[i].side[j]);
530 // Find which wall this trigger is connected to.
531 for (w=0; w<Num_walls; w++)
532 if (Walls[w].trigger == i)
536 err_printf(my_file, "\nError: Trigger %i is not connected to any wall, so it can never be triggered.\n", i);
538 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);
544 // ----------------------------------------------------------------------------
545 void write_game_text_file(char *filename)
547 char my_filename[128];
553 // mprintf((0, "Writing text file for mine [%s]\n", filename));
555 namelen = strlen(filename);
557 Assert (namelen > 4);
559 Assert (filename[namelen-4] == '.');
561 strcpy(my_filename, filename);
562 strcpy( &my_filename[namelen-4], ".txm");
564 // mprintf((0, "Writing text file [%s]\n", my_filename));
566 my_file = fopen( my_filename, "wt" );
567 // -- mprintf((1, "Fileno = %i\n", fileno(my_file)));
570 char ErrorMessage[200];
572 sprintf( ErrorMessage, "ERROR: Unable to open %s\nErrno = %i", my_file, errno );
574 gr_palette_load(gr_palette);
575 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
581 dump_used_textures_level(my_file, 0);
582 say_totals(my_file, Gamesave_current_filename);
584 fprintf(my_file, "\nNumber of segments: %4i\n", Highest_segment_index+1);
585 fprintf(my_file, "Number of objects: %4i\n", Highest_object_index+1);
586 fprintf(my_file, "Number of walls: %4i\n", Num_walls);
587 fprintf(my_file, "Number of open doors: %4i\n", Num_open_doors);
588 fprintf(my_file, "Number of triggers: %4i\n", Num_triggers);
589 fprintf(my_file, "Number of matcens: %4i\n", Num_robot_centers);
590 fprintf(my_file, "\n");
592 write_segment_text(my_file);
594 write_fuelcen_text(my_file);
596 write_matcen_text(my_file);
598 write_player_text(my_file);
600 write_wall_text(my_file);
602 write_trigger_text(my_file);
604 write_exit_text(my_file);
606 // ---------- Find control center segment ----------
607 write_control_center_text(my_file);
609 // ---------- Show keyed walls ----------
610 write_key_text(my_file);
614 mprintf((1, "Close value = %i\n", r));
620 // -- // ---------------
621 // -- // Note: This only works for a loaded level because the objects array must be valid.
622 // -- void determine_used_textures_robots(int *tmap_buf)
627 // -- Assert(N_polygon_models);
629 // -- for (objnum=0; objnum <= Highest_object_index; objnum++) {
632 // -- if (Objects[objnum].render_type == RT_POLYOBJ) {
633 // -- model_num = Objects[objnum].rtype.pobj_info.model_num;
635 // -- po=&Polygon_models[model_num];
637 // -- for (i=0;i<po->n_textures;i++) {
640 // -- tli = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]];
641 // -- Assert((tli>=0) && (tli<= Num_tmaps));
642 // -- tmap_buf[tli]++;
649 // --05/17/95--// -----------------------------------------------------------------------------
650 // --05/17/95--void determine_used_textures_level(int load_level_flag, int shareware_flag, int level_num, int *tmap_buf, int *wall_buf, byte *level_tmap_buf, int max_tmap)
652 // --05/17/95-- int segnum, sidenum;
653 // --05/17/95-- int i, j;
655 // --05/17/95-- for (i=0; i<max_tmap; i++)
656 // --05/17/95-- tmap_buf[i] = 0;
658 // --05/17/95-- if (load_level_flag) {
659 // --05/17/95-- if (shareware_flag)
660 // --05/17/95-- load_level(Shareware_level_names[level_num]);
662 // --05/17/95-- load_level(Registered_level_names[level_num]);
665 // --05/17/95-- for (segnum=0; segnum<=Highest_segment_index; segnum++) {
666 // --05/17/95-- segment *segp = &Segments[segnum];
668 // --05/17/95-- for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
669 // --05/17/95-- side *sidep = &segp->sides[sidenum];
671 // --05/17/95-- if (sidep->wall_num != -1) {
672 // --05/17/95-- int clip_num = Walls[sidep->wall_num].clip_num;
673 // --05/17/95-- if (clip_num != -1) {
675 // --05/17/95-- int num_frames = WallAnims[clip_num].num_frames;
677 // --05/17/95-- wall_buf[clip_num] = 1;
679 // --05/17/95-- for (j=0; j<num_frames; j++) {
680 // --05/17/95-- int tmap_num;
682 // --05/17/95-- tmap_num = WallAnims[clip_num].frames[j];
683 // --05/17/95-- tmap_buf[tmap_num]++;
684 // --05/17/95-- if (level_tmap_buf[tmap_num] == -1)
685 // --05/17/95-- level_tmap_buf[tmap_num] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS;
690 // --05/17/95-- if (sidep->tmap_num >= 0)
691 // --05/17/95-- if (sidep->tmap_num < max_tmap) {
692 // --05/17/95-- tmap_buf[sidep->tmap_num]++;
693 // --05/17/95-- if (level_tmap_buf[sidep->tmap_num] == -1)
694 // --05/17/95-- level_tmap_buf[sidep->tmap_num] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS;
695 // --05/17/95-- } else
696 // --05/17/95-- Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
698 // --05/17/95-- if ((sidep->tmap_num2 & 0x3fff) != 0)
699 // --05/17/95-- if ((sidep->tmap_num2 & 0x3fff) < max_tmap) {
700 // --05/17/95-- tmap_buf[sidep->tmap_num2 & 0x3fff]++;
701 // --05/17/95-- if (level_tmap_buf[sidep->tmap_num2 & 0x3fff] == -1)
702 // --05/17/95-- level_tmap_buf[sidep->tmap_num2 & 0x3fff] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS;
703 // --05/17/95-- } else
704 // --05/17/95-- Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
709 // Adam: Change NUM_ADAM_LEVELS to the number of levels.
710 #define NUM_ADAM_LEVELS 30
712 // Adam: Stick the names here.
713 char *Adam_level_names[NUM_ADAM_LEVELS] = {
751 typedef struct BitmapFile {
755 extern BitmapFile AllBitmaps[ MAX_BITMAP_FILES ];
757 int Ignore_tmap_num2_error;
759 // ----------------------------------------------------------------------------
760 void determine_used_textures_level(int load_level_flag, int shareware_flag, int level_num, int *tmap_buf, int *wall_buf, byte *level_tmap_buf, int max_tmap)
762 int segnum, sidenum, objnum=max_tmap;
765 Assert(shareware_flag != -17);
767 for (i=0; i<MAX_BITMAP_FILES; i++)
770 if (load_level_flag) {
771 load_level(Adam_level_names[level_num]);
776 for (objnum=0; objnum<=Highest_object_index; objnum++) {
777 object *objp = &Objects[objnum];
779 if (objp->render_type == RT_POLYOBJ) {
780 polymodel *po = &Polygon_models[objp->rtype.pobj_info.model_num];
782 for (i=0; i<po->n_textures; i++) {
784 int tli = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index;
785 // -- mprintf((0, "%s ", AllBitmaps[ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index].name));
787 if ((tli < MAX_BITMAP_FILES) && (tli >= 0)) {
789 if (level_tmap_buf[tli] == -1)
790 level_tmap_buf[tli] = level_num;
792 Int3(); // Hmm, It seems this texture is bogus!
799 Ignore_tmap_num2_error = 0;
801 // Process walls and segment sides.
802 for (segnum=0; segnum<=Highest_segment_index; segnum++) {
803 segment *segp = &Segments[segnum];
805 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
806 side *sidep = &segp->sides[sidenum];
808 if (sidep->wall_num != -1) {
809 int clip_num = Walls[sidep->wall_num].clip_num;
810 if (clip_num != -1) {
812 // -- int num_frames = WallAnims[clip_num].num_frames;
814 wall_buf[clip_num] = 1;
816 for (j=0; j<1; j++) { // Used to do through num_frames, but don't really want all the door01#3 stuff.
819 tmap_num = Textures[WallAnims[clip_num].frames[j]].index;
820 Assert((tmap_num >= 0) && (tmap_num < MAX_BITMAP_FILES));
821 tmap_buf[tmap_num]++;
822 if (level_tmap_buf[tmap_num] == -1)
823 level_tmap_buf[tmap_num] = level_num;
826 } else if (segp->children[sidenum] == -1) {
828 if (sidep->tmap_num >= 0)
829 if (sidep->tmap_num < MAX_BITMAP_FILES) {
830 Assert(Textures[sidep->tmap_num].index < MAX_BITMAP_FILES);
831 tmap_buf[Textures[sidep->tmap_num].index]++;
832 if (level_tmap_buf[Textures[sidep->tmap_num].index] == -1)
833 level_tmap_buf[Textures[sidep->tmap_num].index] = level_num;
835 Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
837 if ((sidep->tmap_num2 & 0x3fff) != 0)
838 if ((sidep->tmap_num2 & 0x3fff) < MAX_BITMAP_FILES) {
839 Assert(Textures[sidep->tmap_num2 & 0x3fff].index < MAX_BITMAP_FILES);
840 tmap_buf[Textures[sidep->tmap_num2 & 0x3fff].index]++;
841 if (level_tmap_buf[Textures[sidep->tmap_num2 & 0x3fff].index] == -1)
842 level_tmap_buf[Textures[sidep->tmap_num2 & 0x3fff].index] = level_num;
844 if (!Ignore_tmap_num2_error)
845 Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
846 Ignore_tmap_num2_error = 1;
847 sidep->tmap_num2 = 0;
854 // ----------------------------------------------------------------------------
855 void merge_buffers(int *dest, int *src, int num)
859 for (i=0; i<num; i++)
864 // ----------------------------------------------------------------------------
865 void say_used_tmaps(FILE *my_file, int *tb)
868 // -- mk, 08/14/95 -- int count = 0;
870 for (i=0; i<MAX_BITMAP_FILES; i++)
872 fprintf(my_file, "[%3i %8s (%4i)]\n", i, AllBitmaps[i].name, tb[i]);
873 // -- mk, 08/14/95 -- if (count++ >= 4) {
874 // -- mk, 08/14/95 -- fprintf(my_file, "\n");
875 // -- mk, 08/14/95 -- count = 0;
876 // -- mk, 08/14/95 -- }
880 // --05/17/95--// -----------------------------------------------------------------------------
881 // --05/17/95--void say_used_once_tmaps(FILE *my_file, int *tb, byte *tb_lnum)
883 // --05/17/95-- int i;
884 // --05/17/95-- char *level_name;
886 // --05/17/95-- for (i=0; i<Num_tmaps; i++)
887 // --05/17/95-- if (tb[i] == 1) {
888 // --05/17/95-- int level_num = tb_lnum[i];
889 // --05/17/95-- if (level_num >= NUM_SHAREWARE_LEVELS) {
890 // --05/17/95-- Assert((level_num - NUM_SHAREWARE_LEVELS >= 0) && (level_num - NUM_SHAREWARE_LEVELS < NUM_REGISTERED_LEVELS));
891 // --05/17/95-- level_name = Registered_level_names[level_num - NUM_SHAREWARE_LEVELS];
892 // --05/17/95-- } else {
893 // --05/17/95-- Assert((level_num >= 0) && (level_num < NUM_SHAREWARE_LEVELS));
894 // --05/17/95-- level_name = Shareware_level_names[level_num];
897 // --05/17/95-- fprintf(my_file, "Texture %3i %8s used only once on level %s\n", i, TmapInfo[i].filename, level_name);
901 // ----------------------------------------------------------------------------
902 void say_used_once_tmaps(FILE *my_file, int *tb, byte *tb_lnum)
907 for (i=0; i<MAX_BITMAP_FILES; i++)
909 int level_num = tb_lnum[i];
910 level_name = Adam_level_names[level_num];
912 fprintf(my_file, "Texture %3i %8s used only once on level %s\n", i, AllBitmaps[i].name, level_name);
916 // ----------------------------------------------------------------------------
917 void say_unused_tmaps(FILE *my_file, int *tb)
922 for (i=0; i<MAX_BITMAP_FILES; i++)
924 if (GameBitmaps[Textures[i].index].bm_data == &bogus_data)
925 fprintf(my_file, "U");
927 fprintf(my_file, " ");
929 fprintf(my_file, "[%3i %8s] ", i, AllBitmaps[i].name);
931 fprintf(my_file, "\n");
937 // ----------------------------------------------------------------------------
938 void say_unused_walls(FILE *my_file, int *tb)
942 for (i=0; i<Num_wall_anims; i++)
944 fprintf(my_file, "Wall %3i is unused.\n", i);
947 // ----------------------------------------------------------------------------
948 say_totals(FILE *my_file, char *level_name)
951 int total_robots = 0;
952 int objects_processed = 0;
954 int used_objects[MAX_OBJECTS];
956 fprintf(my_file, "\nLevel %s\n", level_name);
958 for (i=0; i<MAX_OBJECTS; i++)
961 while (objects_processed < Highest_object_index+1) {
962 int j, objtype, objid, objcount, cur_obj_val, min_obj_val, min_objnum;
964 // Find new min objnum.
965 min_obj_val = 0x7fff0000;
968 for (j=0; j<=Highest_object_index; j++) {
969 if (!used_objects[j] && Objects[j].type!=OBJ_NONE) {
970 cur_obj_val = Objects[j].type * 1000 + Objects[j].id;
971 if (cur_obj_val < min_obj_val) {
973 min_obj_val = cur_obj_val;
977 if ((min_objnum == -1) || (Objects[min_objnum].type == 255))
982 objtype = Objects[min_objnum].type;
983 objid = Objects[min_objnum].id;
985 for (i=0; i<=Highest_object_index; i++) {
986 if (!used_objects[i]) {
988 if (((Objects[i].type == objtype) && (Objects[i].id == objid)) ||
989 ((Objects[i].type == objtype) && (objtype == OBJ_PLAYER)) ||
990 ((Objects[i].type == objtype) && (objtype == OBJ_COOP)) ||
991 ((Objects[i].type == objtype) && (objtype == OBJ_HOSTAGE))) {
992 if (Objects[i].type == OBJ_ROBOT)
1002 fprintf(my_file, "Object: ");
1003 fprintf(my_file, "%8s %8s %3i\n", object_types(min_objnum), object_ids(min_objnum), objcount);
1007 fprintf(my_file, "Total robots = %3i\n", total_robots);
1010 int First_dump_level = 0;
1011 int Last_dump_level = NUM_ADAM_LEVELS-1;
1013 // ----------------------------------------------------------------------------
1014 void say_totals_all(void)
1019 my_file = fopen( "levels.all", "wt" );
1020 // -- mprintf((1, "Fileno = %i\n", fileno(my_file)));
1023 char ErrorMessage[200];
1025 sprintf( ErrorMessage, "ERROR: Unable to open levels.all\nErrno=%i", errno );
1027 gr_palette_load(gr_palette);
1028 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
1034 for (i=First_dump_level; i<=Last_dump_level; i++) {
1035 mprintf((0, "Level %i\n", i+1));
1036 load_level(Adam_level_names[i]);
1037 say_totals(my_file, Adam_level_names[i]);
1040 //--05/17/95-- for (i=0; i<NUM_SHAREWARE_LEVELS; i++) {
1041 //--05/17/95-- mprintf((0, "Level %i\n", i+1));
1042 //--05/17/95-- load_level(Shareware_level_names[i]);
1043 //--05/17/95-- say_totals(my_file, Shareware_level_names[i]);
1046 //--05/17/95-- for (i=0; i<NUM_REGISTERED_LEVELS; i++) {
1047 //--05/17/95-- mprintf((0, "Level %i\n", i+1+NUM_SHAREWARE_LEVELS));
1048 //--05/17/95-- load_level(Registered_level_names[i]);
1049 //--05/17/95-- say_totals(my_file, Registered_level_names[i]);
1056 void dump_used_textures_level(FILE *my_file, int level_num)
1059 int temp_tmap_buf[MAX_BITMAP_FILES];
1060 int perm_tmap_buf[MAX_BITMAP_FILES];
1061 byte level_tmap_buf[MAX_BITMAP_FILES];
1062 int temp_wall_buf[MAX_BITMAP_FILES];
1063 int perm_wall_buf[MAX_BITMAP_FILES];
1065 for (i=0; i<MAX_BITMAP_FILES; i++) {
1066 perm_tmap_buf[i] = 0;
1067 level_tmap_buf[i] = -1;
1070 for (i=0; i<MAX_BITMAP_FILES; i++) {
1071 perm_wall_buf[i] = 0;
1074 determine_used_textures_level(0, 1, level_num, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1075 // -- determine_used_textures_robots(temp_tmap_buf);
1076 fprintf(my_file, "\nTextures used in [%s]\n", Gamesave_current_filename);
1077 say_used_tmaps(my_file, temp_tmap_buf);
1082 // ----------------------------------------------------------------------------
1083 void dump_used_textures_all(void)
1086 int temp_tmap_buf[MAX_BITMAP_FILES];
1087 int perm_tmap_buf[MAX_BITMAP_FILES];
1088 byte level_tmap_buf[MAX_BITMAP_FILES];
1089 int temp_wall_buf[MAX_BITMAP_FILES];
1090 int perm_wall_buf[MAX_BITMAP_FILES];
1094 my_file = fopen( "textures.dmp", "wt" );
1095 // -- mprintf((1, "Fileno = %i\n", fileno(my_file)));
1098 char ErrorMessage[200];
1100 sprintf( ErrorMessage, "ERROR: Can't open textures.dmp\nErrno=%i", errno);
1102 gr_palette_load(gr_palette);
1103 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
1109 for (i=0; i<MAX_BITMAP_FILES; i++) {
1110 perm_tmap_buf[i] = 0;
1111 level_tmap_buf[i] = -1;
1114 for (i=0; i<MAX_BITMAP_FILES; i++) {
1115 perm_wall_buf[i] = 0;
1118 // --05/17/95-- for (i=0; i<NUM_SHAREWARE_LEVELS; i++) {
1119 // --05/17/95-- determine_used_textures_level(1, 1, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1120 // --05/17/95-- fprintf(my_file, "\nTextures used in [%s]\n", Shareware_level_names[i]);
1121 // --05/17/95-- say_used_tmaps(my_file, temp_tmap_buf);
1122 // --05/17/95-- merge_buffers(perm_tmap_buf, temp_tmap_buf, MAX_BITMAP_FILES);
1123 // --05/17/95-- merge_buffers(perm_wall_buf, temp_wall_buf, MAX_BITMAP_FILES);
1126 // --05/17/95-- fprintf(my_file, "\n\nUsed textures in all shareware mines:\n");
1127 // --05/17/95-- say_used_tmaps(my_file, perm_tmap_buf);
1129 // --05/17/95-- fprintf(my_file, "\nUnused textures in all shareware mines:\n");
1130 // --05/17/95-- say_unused_tmaps(my_file, perm_tmap_buf);
1132 // --05/17/95-- fprintf(my_file, "\nTextures used exactly once in all shareware mines:\n");
1133 // --05/17/95-- say_used_once_tmaps(my_file, perm_tmap_buf, level_tmap_buf);
1135 // --05/17/95-- fprintf(my_file, "\nWall anims (eg, doors) unused in all shareware mines:\n");
1136 // --05/17/95-- say_unused_walls(my_file, perm_wall_buf);
1138 // --05/17/95-- for (i=0; i<NUM_REGISTERED_LEVELS; i++) {
1139 // --05/17/95-- determine_used_textures_level(1, 0, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1140 // --05/17/95-- fprintf(my_file, "\nTextures used in [%s]\n", Registered_level_names[i]);
1141 // --05/17/95-- say_used_tmaps(my_file, temp_tmap_buf);
1142 // --05/17/95-- merge_buffers(perm_tmap_buf, temp_tmap_buf, MAX_BITMAP_FILES);
1145 // --05/17/95-- fprintf(my_file, "\n\nUsed textures in all (including registered) mines:\n");
1146 // --05/17/95-- say_used_tmaps(my_file, perm_tmap_buf);
1148 // --05/17/95-- fprintf(my_file, "\nUnused textures in all (including registered) mines:\n");
1149 // --05/17/95-- say_unused_tmaps(my_file, perm_tmap_buf);
1151 for (i=First_dump_level; i<=Last_dump_level; i++) {
1152 determine_used_textures_level(1, 0, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1153 fprintf(my_file, "\nTextures used in [%s]\n", Adam_level_names[i]);
1154 say_used_tmaps(my_file, temp_tmap_buf);
1155 merge_buffers(perm_tmap_buf, temp_tmap_buf, MAX_BITMAP_FILES);
1158 fprintf(my_file, "\n\nUsed textures in all (including registered) mines:\n");
1159 say_used_tmaps(my_file, perm_tmap_buf);
1161 fprintf(my_file, "\nUnused textures in all (including registered) mines:\n");
1162 say_unused_tmaps(my_file, perm_tmap_buf);