1 /* $Id: dumpmine.c,v 1.9 2004-12-21 11:24:23 btb 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.9 2004-12-21 11:24:23 btb Exp $";
44 #include "editor/editor.h"
67 extern ubyte bogus_data[64*64];
68 extern grs_bitmap bogus_bitmap;
70 void dump_used_textures_level(FILE *my_file, int level_num);
71 void say_totals(FILE *my_file, char *level_name);
73 // ----------------------------------------------------------------------------
74 char *object_types(int objnum)
76 int type = Objects[objnum].type;
78 Assert((type >= 0) && (type < MAX_OBJECT_TYPES));
79 return Object_type_names[type];
82 // ----------------------------------------------------------------------------
83 char *object_ids(int objnum)
85 int type = Objects[objnum].type;
86 int id = Objects[objnum].id;
90 return Robot_names[id];
93 return Powerup_names[id];
100 void err_printf(FILE *my_file, char * format, ... )
105 va_start(args, format );
106 vsprintf(message,format,args);
109 mprintf((1, "%s", message));
110 fprintf(my_file, "%s", message);
114 void warning_printf(FILE *my_file, char * format, ... )
119 va_start(args, format );
120 vsprintf(message,format,args);
123 mprintf((0, "%s", message));
124 fprintf(my_file, "%s", message);
127 // ----------------------------------------------------------------------------
128 void write_exit_text(FILE *my_file)
132 fprintf(my_file, "-----------------------------------------------------------------------------\n");
133 fprintf(my_file, "Exit stuff\n");
135 // ---------- Find exit triggers ----------
137 for (i=0; i<Num_triggers; i++)
138 if (Triggers[i].type == TT_EXIT) {
141 fprintf(my_file, "Trigger %2i, is an exit trigger with %i links.\n", i, Triggers[i].num_links);
143 if (Triggers[i].num_links != 0)
144 err_printf(my_file, "Error: Exit triggers must have 0 links, this one has %i links.\n", Triggers[i].num_links);
146 // Find wall pointing to this trigger.
148 for (j=0; j<Num_walls; j++)
149 if (Walls[j].trigger == i) {
151 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);
154 err_printf(my_file, "Error: Trigger %i is not bound to any wall.\n", i);
156 err_printf(my_file, "Error: Trigger %i is bound to %i walls.\n", i, count2);
161 err_printf(my_file, "Error: No exit trigger in this mine.\n");
163 err_printf(my_file, "Error: More than one exit trigger in this mine.\n");
165 fprintf(my_file, "\n");
167 // ---------- Find exit doors ----------
169 for (i=0; i<=Highest_segment_index; i++)
170 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++)
171 if (Segments[i].children[j] == -2) {
172 fprintf(my_file, "Segment %3i, side %i is an exit door.\n", i, j);
177 err_printf(my_file, "Error: No external wall in this mine.\n");
178 else if (count != 1) {
179 // -- warning_printf(my_file, "Warning: %i external walls in this mine.\n", count);
180 // -- warning_printf(my_file, "(If %i are secret exits, then no problem.)\n", count-1);
182 fprintf(my_file, "\n");
185 // ----------------------------------------------------------------------------
186 void write_key_text(FILE *my_file)
189 int red_count, blue_count, gold_count;
190 int red_count2, blue_count2, gold_count2;
191 int blue_segnum=-1, blue_sidenum=-1, red_segnum=-1, red_sidenum=-1, gold_segnum=-1, gold_sidenum=-1;
194 fprintf(my_file, "-----------------------------------------------------------------------------\n");
195 fprintf(my_file, "Key stuff:\n");
201 for (i=0; i<Num_walls; i++) {
202 if (Walls[i].keys & KEY_BLUE) {
203 fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the blue key.\n", i, Walls[i].segnum, Walls[i].sidenum);
204 if (blue_segnum == -1) {
205 blue_segnum = Walls[i].segnum;
206 blue_sidenum = Walls[i].sidenum;
209 connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[blue_segnum]);
210 if (connect_side != blue_sidenum) {
211 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);
216 if (Walls[i].keys & KEY_RED) {
217 fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the red key.\n", i, Walls[i].segnum, Walls[i].sidenum);
218 if (red_segnum == -1) {
219 red_segnum = Walls[i].segnum;
220 red_sidenum = Walls[i].sidenum;
223 connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[red_segnum]);
224 if (connect_side != red_sidenum) {
225 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);
230 if (Walls[i].keys & KEY_GOLD) {
231 fprintf(my_file, "Wall %i (seg=%i, side=%i) is keyed to the gold key.\n", i, Walls[i].segnum, Walls[i].sidenum);
232 if (gold_segnum == -1) {
233 gold_segnum = Walls[i].segnum;
234 gold_sidenum = Walls[i].sidenum;
237 connect_side = find_connect_side(&Segments[Walls[i].segnum], &Segments[gold_segnum]);
238 if (connect_side != gold_sidenum) {
239 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);
247 warning_printf(my_file, "Warning: %i doors are keyed to the blue key.\n", blue_count);
250 warning_printf(my_file, "Warning: %i doors are keyed to the red key.\n", red_count);
253 warning_printf(my_file, "Warning: %i doors are keyed to the gold key.\n", gold_count);
259 for (i=0; i<=Highest_object_index; i++) {
260 if (Objects[i].type == OBJ_POWERUP)
261 if (Objects[i].id == POW_KEY_BLUE) {
262 fprintf(my_file, "The BLUE key is object %i in segment %i\n", i, Objects[i].segnum);
265 if (Objects[i].type == OBJ_POWERUP)
266 if (Objects[i].id == POW_KEY_RED) {
267 fprintf(my_file, "The RED key is object %i in segment %i\n", i, Objects[i].segnum);
270 if (Objects[i].type == OBJ_POWERUP)
271 if (Objects[i].id == POW_KEY_GOLD) {
272 fprintf(my_file, "The GOLD key is object %i in segment %i\n", i, Objects[i].segnum);
276 if (Objects[i].contains_count) {
277 if (Objects[i].contains_type == OBJ_POWERUP) {
278 switch (Objects[i].contains_id) {
280 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);
281 blue_count2 += Objects[i].contains_count;
284 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);
285 gold_count2 += Objects[i].contains_count;
288 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);
289 red_count2 += Objects[i].contains_count;
299 if (blue_count2 == 0)
300 err_printf(my_file, "Error: There is a door keyed to the blue key, but no blue key!\n");
304 err_printf(my_file, "Error: There is a door keyed to the red key, but no red key!\n");
307 if (gold_count2 == 0)
308 err_printf(my_file, "Error: There is a door keyed to the gold key, but no gold key!\n");
311 err_printf(my_file, "Error: There are %i blue keys!\n", blue_count2);
314 err_printf(my_file, "Error: There are %i red keys!\n", red_count2);
317 err_printf(my_file, "Error: There are %i gold keys!\n", gold_count2);
320 // ----------------------------------------------------------------------------
321 void write_control_center_text(FILE *my_file)
323 int i, count, objnum, count2;
325 fprintf(my_file, "-----------------------------------------------------------------------------\n");
326 fprintf(my_file, "Control Center stuff:\n");
329 for (i=0; i<=Highest_segment_index; i++)
330 if (Segment2s[i].special == SEGMENT_IS_CONTROLCEN) {
332 fprintf(my_file, "Segment %3i is a control center.\n", i);
333 objnum = Segments[i].objects;
335 while (objnum != -1) {
336 if (Objects[objnum].type == OBJ_CNTRLCEN)
338 objnum = Objects[objnum].next;
341 fprintf(my_file, "No control center object in control center segment.\n");
342 else if (count2 != 1)
343 fprintf(my_file, "%i control center objects in control center segment.\n", count2);
347 err_printf(my_file, "Error: No control center in this mine.\n");
349 err_printf(my_file, "Error: More than one control center in this mine.\n");
352 // ----------------------------------------------------------------------------
353 void write_fuelcen_text(FILE *my_file)
357 fprintf(my_file, "-----------------------------------------------------------------------------\n");
358 fprintf(my_file, "Fuel Center stuff: (Note: This means fuel, repair, materialize, control centers!)\n");
360 for (i=0; i<Num_fuelcenters; i++) {
361 fprintf(my_file, "Fuelcenter %i: Type=%i (%s), segment = %3i\n", i, Station[i].Type, Special_names[Station[i].Type], Station[i].segnum);
362 if (Segment2s[Station[i].segnum].special != Station[i].Type)
363 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);
367 // ----------------------------------------------------------------------------
368 void write_segment_text(FILE *my_file)
372 fprintf(my_file, "-----------------------------------------------------------------------------\n");
373 fprintf(my_file, "Segment stuff:\n");
375 for (i=0; i<=Highest_segment_index; i++) {
377 fprintf(my_file, "Segment %4i: ", i);
378 if (Segment2s[i].special != 0)
379 fprintf(my_file, "special = %3i (%s), value = %3i ", Segment2s[i].special, Special_names[Segment2s[i].special], Segment2s[i].value);
381 if (Segment2s[i].matcen_num != -1)
382 fprintf(my_file, "matcen = %3i, ", Segment2s[i].matcen_num);
384 fprintf(my_file, "\n");
387 for (i=0; i<=Highest_segment_index; i++) {
390 objnum = Segments[i].objects;
391 fprintf(my_file, "Segment %4i: ", i);
394 fprintf(my_file, "Objects: ");
395 while (objnum != -1) {
396 fprintf(my_file, "[%8s %8s %3i] ", object_types(objnum), object_ids(objnum), objnum);
397 objnum = Objects[objnum].next;
399 fprintf(my_file, "\nAborted after %i links\n", depth);
404 fprintf(my_file, "\n");
408 // ----------------------------------------------------------------------------
409 // This routine is bogus. It assumes that all centers are matcens,
410 // which is not true. The setting of segnum is bogus.
411 void write_matcen_text(FILE *my_file)
415 fprintf(my_file, "-----------------------------------------------------------------------------\n");
416 fprintf(my_file, "Materialization centers:\n");
417 for (i=0; i<Num_robot_centers; i++) {
418 int trigger_count=0, segnum, fuelcen_num;
420 fprintf(my_file, "FuelCenter[%02i].Segment = %04i ", i, Station[i].segnum);
421 fprintf(my_file, "Segment2[%04i].matcen_num = %02i ", Station[i].segnum, Segment2s[Station[i].segnum].matcen_num);
423 fuelcen_num = RobotCenters[i].fuelcen_num;
424 if (Station[fuelcen_num].Type != SEGMENT_IS_ROBOTMAKER)
425 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]);
427 segnum = Station[fuelcen_num].segnum;
429 // Find trigger for this materialization center.
430 for (j=0; j<Num_triggers; j++) {
431 if (Triggers[j].type == TT_MATCEN) {
432 for (k=0; k<Triggers[j].num_links; k++)
433 if (Triggers[j].seg[k] == segnum) {
434 fprintf(my_file, "Trigger = %2i ", j );
439 fprintf(my_file, "\n");
441 if (trigger_count == 0)
442 err_printf(my_file, "Error: Matcen %i in segment %i has no trigger!\n", i, segnum);
447 // ----------------------------------------------------------------------------
448 void write_wall_text(FILE *my_file)
451 sbyte wall_flags[MAX_WALLS];
453 fprintf(my_file, "-----------------------------------------------------------------------------\n");
454 fprintf(my_file, "Walls:\n");
455 for (i=0; i<Num_walls; i++) {
458 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,
459 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);
461 if (Walls[i].trigger >= Num_triggers)
462 fprintf(my_file, "Wall %03d points to invalid trigger %d\n",i,Walls[i].trigger);
464 segnum = Walls[i].segnum;
465 sidenum = Walls[i].sidenum;
467 if (Segments[segnum].sides[sidenum].wall_num != i)
468 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);
471 for (i=0; i<MAX_WALLS; i++)
474 for (i=0; i<=Highest_segment_index; i++) {
475 segment *segp = &Segments[i];
476 for (j=0; j<MAX_SIDES_PER_SEGMENT; j++) {
477 side *sidep = &segp->sides[j];
478 if (sidep->wall_num != -1)
479 if (wall_flags[sidep->wall_num])
480 err_printf(my_file, "Error: Wall %i appears in two or more segments, including segment %i, side %i.\n", sidep->wall_num, i, j);
482 wall_flags[sidep->wall_num] = 1;
488 //typedef struct trigger {
495 // short seg[MAX_WALLS_PER_LINK];
496 // short side[MAX_WALLS_PER_LINK];
499 // ----------------------------------------------------------------------------
500 void write_player_text(FILE *my_file)
502 int i, num_players=0;
504 fprintf(my_file, "-----------------------------------------------------------------------------\n");
505 fprintf(my_file, "Players:\n");
506 for (i=0; i<=Highest_object_index; i++) {
507 if (Objects[i].type == OBJ_PLAYER) {
509 fprintf(my_file, "Player %2i is object #%3i in segment #%3i.\n", Objects[i].id, i, Objects[i].segnum);
513 if (num_players != MAX_PLAYERS)
514 err_printf(my_file, "Error: %i player objects. %i are required.\n", num_players, MAX_PLAYERS);
515 if (num_players > MAX_MULTI_PLAYERS)
516 err_printf(my_file, "Error: %i player objects. %i are required.\n", num_players, MAX_PLAYERS);
519 // ----------------------------------------------------------------------------
520 void write_trigger_text(FILE *my_file)
524 fprintf(my_file, "-----------------------------------------------------------------------------\n");
525 fprintf(my_file, "Triggers:\n");
526 for (i=0; i<Num_triggers; i++) {
527 fprintf(my_file, "Trigger %03i: type=%02x flags=%04x, value=%08x, time=%8x, num_links=%i ", i,
528 Triggers[i].type, Triggers[i].flags, Triggers[i].value, Triggers[i].time, Triggers[i].num_links);
530 for (j=0; j<Triggers[i].num_links; j++)
531 fprintf(my_file, "[%03i:%i] ", Triggers[i].seg[j], Triggers[i].side[j]);
533 // Find which wall this trigger is connected to.
534 for (w=0; w<Num_walls; w++)
535 if (Walls[w].trigger == i)
539 err_printf(my_file, "\nError: Trigger %i is not connected to any wall, so it can never be triggered.\n", i);
541 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);
547 // ----------------------------------------------------------------------------
548 void write_game_text_file(char *filename)
550 char my_filename[128];
556 // mprintf((0, "Writing text file for mine [%s]\n", filename));
558 namelen = strlen(filename);
560 Assert (namelen > 4);
562 Assert (filename[namelen-4] == '.');
564 strcpy(my_filename, filename);
565 strcpy( &my_filename[namelen-4], ".txm");
567 // mprintf((0, "Writing text file [%s]\n", my_filename));
569 my_file = fopen( my_filename, "wt" );
570 // -- mprintf((1, "Fileno = %i\n", fileno(my_file)));
573 char ErrorMessage[200];
575 sprintf(ErrorMessage, "ERROR: Unable to open %s\nErrno = %i", my_filename, errno);
577 gr_palette_load(gr_palette);
578 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
584 dump_used_textures_level(my_file, 0);
585 say_totals(my_file, Gamesave_current_filename);
587 fprintf(my_file, "\nNumber of segments: %4i\n", Highest_segment_index+1);
588 fprintf(my_file, "Number of objects: %4i\n", Highest_object_index+1);
589 fprintf(my_file, "Number of walls: %4i\n", Num_walls);
590 fprintf(my_file, "Number of open doors: %4i\n", Num_open_doors);
591 fprintf(my_file, "Number of triggers: %4i\n", Num_triggers);
592 fprintf(my_file, "Number of matcens: %4i\n", Num_robot_centers);
593 fprintf(my_file, "\n");
595 write_segment_text(my_file);
597 write_fuelcen_text(my_file);
599 write_matcen_text(my_file);
601 write_player_text(my_file);
603 write_wall_text(my_file);
605 write_trigger_text(my_file);
607 write_exit_text(my_file);
609 // ---------- Find control center segment ----------
610 write_control_center_text(my_file);
612 // ---------- Show keyed walls ----------
613 write_key_text(my_file);
617 mprintf((1, "Close value = %i\n", r));
623 // -- // ---------------
624 // -- // Note: This only works for a loaded level because the objects array must be valid.
625 // -- void determine_used_textures_robots(int *tmap_buf)
630 // -- Assert(N_polygon_models);
632 // -- for (objnum=0; objnum <= Highest_object_index; objnum++) {
635 // -- if (Objects[objnum].render_type == RT_POLYOBJ) {
636 // -- model_num = Objects[objnum].rtype.pobj_info.model_num;
638 // -- po=&Polygon_models[model_num];
640 // -- for (i=0;i<po->n_textures;i++) {
643 // -- tli = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]];
644 // -- Assert((tli>=0) && (tli<= Num_tmaps));
645 // -- tmap_buf[tli]++;
652 // --05/17/95--// -----------------------------------------------------------------------------
653 // --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)
655 // --05/17/95-- int segnum, sidenum;
656 // --05/17/95-- int i, j;
658 // --05/17/95-- for (i=0; i<max_tmap; i++)
659 // --05/17/95-- tmap_buf[i] = 0;
661 // --05/17/95-- if (load_level_flag) {
662 // --05/17/95-- if (shareware_flag)
663 // --05/17/95-- load_level(Shareware_level_names[level_num]);
665 // --05/17/95-- load_level(Registered_level_names[level_num]);
668 // --05/17/95-- for (segnum=0; segnum<=Highest_segment_index; segnum++) {
669 // --05/17/95-- segment *segp = &Segments[segnum];
671 // --05/17/95-- for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
672 // --05/17/95-- side *sidep = &segp->sides[sidenum];
674 // --05/17/95-- if (sidep->wall_num != -1) {
675 // --05/17/95-- int clip_num = Walls[sidep->wall_num].clip_num;
676 // --05/17/95-- if (clip_num != -1) {
678 // --05/17/95-- int num_frames = WallAnims[clip_num].num_frames;
680 // --05/17/95-- wall_buf[clip_num] = 1;
682 // --05/17/95-- for (j=0; j<num_frames; j++) {
683 // --05/17/95-- int tmap_num;
685 // --05/17/95-- tmap_num = WallAnims[clip_num].frames[j];
686 // --05/17/95-- tmap_buf[tmap_num]++;
687 // --05/17/95-- if (level_tmap_buf[tmap_num] == -1)
688 // --05/17/95-- level_tmap_buf[tmap_num] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS;
693 // --05/17/95-- if (sidep->tmap_num >= 0)
694 // --05/17/95-- if (sidep->tmap_num < max_tmap) {
695 // --05/17/95-- tmap_buf[sidep->tmap_num]++;
696 // --05/17/95-- if (level_tmap_buf[sidep->tmap_num] == -1)
697 // --05/17/95-- level_tmap_buf[sidep->tmap_num] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS;
698 // --05/17/95-- } else
699 // --05/17/95-- Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
701 // --05/17/95-- if ((sidep->tmap_num2 & 0x3fff) != 0)
702 // --05/17/95-- if ((sidep->tmap_num2 & 0x3fff) < max_tmap) {
703 // --05/17/95-- tmap_buf[sidep->tmap_num2 & 0x3fff]++;
704 // --05/17/95-- if (level_tmap_buf[sidep->tmap_num2 & 0x3fff] == -1)
705 // --05/17/95-- level_tmap_buf[sidep->tmap_num2 & 0x3fff] = level_num + (!shareware_flag) * NUM_SHAREWARE_LEVELS;
706 // --05/17/95-- } else
707 // --05/17/95-- Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
712 // Adam: Change NUM_ADAM_LEVELS to the number of levels.
713 #define NUM_ADAM_LEVELS 30
715 // Adam: Stick the names here.
716 char *Adam_level_names[NUM_ADAM_LEVELS] = {
754 typedef struct BitmapFile {
758 extern BitmapFile AllBitmaps[ MAX_BITMAP_FILES ];
760 int Ignore_tmap_num2_error;
762 // ----------------------------------------------------------------------------
763 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)
765 int segnum, sidenum, objnum=max_tmap;
768 Assert(shareware_flag != -17);
770 for (i=0; i<MAX_BITMAP_FILES; i++)
773 if (load_level_flag) {
774 load_level(Adam_level_names[level_num]);
779 for (objnum=0; objnum<=Highest_object_index; objnum++) {
780 object *objp = &Objects[objnum];
782 if (objp->render_type == RT_POLYOBJ) {
783 polymodel *po = &Polygon_models[objp->rtype.pobj_info.model_num];
785 for (i=0; i<po->n_textures; i++) {
787 int tli = ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index;
788 // -- mprintf((0, "%s ", AllBitmaps[ObjBitmaps[ObjBitmapPtrs[po->first_texture+i]].index].name));
790 if ((tli < MAX_BITMAP_FILES) && (tli >= 0)) {
792 if (level_tmap_buf[tli] == -1)
793 level_tmap_buf[tli] = level_num;
795 Int3(); // Hmm, It seems this texture is bogus!
802 Ignore_tmap_num2_error = 0;
804 // Process walls and segment sides.
805 for (segnum=0; segnum<=Highest_segment_index; segnum++) {
806 segment *segp = &Segments[segnum];
808 for (sidenum=0; sidenum<MAX_SIDES_PER_SEGMENT; sidenum++) {
809 side *sidep = &segp->sides[sidenum];
811 if (sidep->wall_num != -1) {
812 int clip_num = Walls[sidep->wall_num].clip_num;
813 if (clip_num != -1) {
815 // -- int num_frames = WallAnims[clip_num].num_frames;
817 wall_buf[clip_num] = 1;
819 for (j=0; j<1; j++) { // Used to do through num_frames, but don't really want all the door01#3 stuff.
822 tmap_num = Textures[WallAnims[clip_num].frames[j]].index;
823 Assert((tmap_num >= 0) && (tmap_num < MAX_BITMAP_FILES));
824 tmap_buf[tmap_num]++;
825 if (level_tmap_buf[tmap_num] == -1)
826 level_tmap_buf[tmap_num] = level_num;
829 } else if (segp->children[sidenum] == -1) {
831 if (sidep->tmap_num >= 0)
832 if (sidep->tmap_num < MAX_BITMAP_FILES) {
833 Assert(Textures[sidep->tmap_num].index < MAX_BITMAP_FILES);
834 tmap_buf[Textures[sidep->tmap_num].index]++;
835 if (level_tmap_buf[Textures[sidep->tmap_num].index] == -1)
836 level_tmap_buf[Textures[sidep->tmap_num].index] = level_num;
838 Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
840 if ((sidep->tmap_num2 & 0x3fff) != 0)
841 if ((sidep->tmap_num2 & 0x3fff) < MAX_BITMAP_FILES) {
842 Assert(Textures[sidep->tmap_num2 & 0x3fff].index < MAX_BITMAP_FILES);
843 tmap_buf[Textures[sidep->tmap_num2 & 0x3fff].index]++;
844 if (level_tmap_buf[Textures[sidep->tmap_num2 & 0x3fff].index] == -1)
845 level_tmap_buf[Textures[sidep->tmap_num2 & 0x3fff].index] = level_num;
847 if (!Ignore_tmap_num2_error)
848 Int3(); // Error, bogus texture map. Should not be greater than max_tmap.
849 Ignore_tmap_num2_error = 1;
850 sidep->tmap_num2 = 0;
857 // ----------------------------------------------------------------------------
858 void merge_buffers(int *dest, int *src, int num)
862 for (i=0; i<num; i++)
867 // ----------------------------------------------------------------------------
868 void say_used_tmaps(FILE *my_file, int *tb)
871 // -- mk, 08/14/95 -- int count = 0;
873 for (i=0; i<MAX_BITMAP_FILES; i++)
875 fprintf(my_file, "[%3i %8s (%4i)]\n", i, AllBitmaps[i].name, tb[i]);
876 // -- mk, 08/14/95 -- if (count++ >= 4) {
877 // -- mk, 08/14/95 -- fprintf(my_file, "\n");
878 // -- mk, 08/14/95 -- count = 0;
879 // -- mk, 08/14/95 -- }
883 // --05/17/95--// -----------------------------------------------------------------------------
884 // --05/17/95--void say_used_once_tmaps(FILE *my_file, int *tb, sbyte *tb_lnum)
886 // --05/17/95-- int i;
887 // --05/17/95-- char *level_name;
889 // --05/17/95-- for (i=0; i<Num_tmaps; i++)
890 // --05/17/95-- if (tb[i] == 1) {
891 // --05/17/95-- int level_num = tb_lnum[i];
892 // --05/17/95-- if (level_num >= NUM_SHAREWARE_LEVELS) {
893 // --05/17/95-- Assert((level_num - NUM_SHAREWARE_LEVELS >= 0) && (level_num - NUM_SHAREWARE_LEVELS < NUM_REGISTERED_LEVELS));
894 // --05/17/95-- level_name = Registered_level_names[level_num - NUM_SHAREWARE_LEVELS];
895 // --05/17/95-- } else {
896 // --05/17/95-- Assert((level_num >= 0) && (level_num < NUM_SHAREWARE_LEVELS));
897 // --05/17/95-- level_name = Shareware_level_names[level_num];
900 // --05/17/95-- fprintf(my_file, "Texture %3i %8s used only once on level %s\n", i, TmapInfo[i].filename, level_name);
904 // ----------------------------------------------------------------------------
905 void say_used_once_tmaps(FILE *my_file, int *tb, sbyte *tb_lnum)
910 for (i=0; i<MAX_BITMAP_FILES; i++)
912 int level_num = tb_lnum[i];
913 level_name = Adam_level_names[level_num];
915 fprintf(my_file, "Texture %3i %8s used only once on level %s\n", i, AllBitmaps[i].name, level_name);
919 // ----------------------------------------------------------------------------
920 void say_unused_tmaps(FILE *my_file, int *tb)
925 for (i=0; i<MAX_BITMAP_FILES; i++)
927 if (GameBitmaps[Textures[i].index].bm_data == bogus_data)
928 fprintf(my_file, "U");
930 fprintf(my_file, " ");
932 fprintf(my_file, "[%3i %8s] ", i, AllBitmaps[i].name);
934 fprintf(my_file, "\n");
940 // ----------------------------------------------------------------------------
941 void say_unused_walls(FILE *my_file, int *tb)
945 for (i=0; i<Num_wall_anims; i++)
947 fprintf(my_file, "Wall %3i is unused.\n", i);
950 // ----------------------------------------------------------------------------
951 void say_totals(FILE *my_file, char *level_name)
954 int total_robots = 0;
955 int objects_processed = 0;
957 int used_objects[MAX_OBJECTS];
959 fprintf(my_file, "\nLevel %s\n", level_name);
961 for (i=0; i<MAX_OBJECTS; i++)
964 while (objects_processed < Highest_object_index+1) {
965 int j, objtype, objid, objcount, cur_obj_val, min_obj_val, min_objnum;
967 // Find new min objnum.
968 min_obj_val = 0x7fff0000;
971 for (j=0; j<=Highest_object_index; j++) {
972 if (!used_objects[j] && Objects[j].type!=OBJ_NONE) {
973 cur_obj_val = Objects[j].type * 1000 + Objects[j].id;
974 if (cur_obj_val < min_obj_val) {
976 min_obj_val = cur_obj_val;
980 if ((min_objnum == -1) || (Objects[min_objnum].type == 255))
985 objtype = Objects[min_objnum].type;
986 objid = Objects[min_objnum].id;
988 for (i=0; i<=Highest_object_index; i++) {
989 if (!used_objects[i]) {
991 if (((Objects[i].type == objtype) && (Objects[i].id == objid)) ||
992 ((Objects[i].type == objtype) && (objtype == OBJ_PLAYER)) ||
993 ((Objects[i].type == objtype) && (objtype == OBJ_COOP)) ||
994 ((Objects[i].type == objtype) && (objtype == OBJ_HOSTAGE))) {
995 if (Objects[i].type == OBJ_ROBOT)
1005 fprintf(my_file, "Object: ");
1006 fprintf(my_file, "%8s %8s %3i\n", object_types(min_objnum), object_ids(min_objnum), objcount);
1010 fprintf(my_file, "Total robots = %3i\n", total_robots);
1013 int First_dump_level = 0;
1014 int Last_dump_level = NUM_ADAM_LEVELS-1;
1016 // ----------------------------------------------------------------------------
1017 void say_totals_all(void)
1022 my_file = fopen( "levels.all", "wt" );
1023 // -- mprintf((1, "Fileno = %i\n", fileno(my_file)));
1026 char ErrorMessage[200];
1028 sprintf( ErrorMessage, "ERROR: Unable to open levels.all\nErrno=%i", errno );
1030 gr_palette_load(gr_palette);
1031 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
1037 for (i=First_dump_level; i<=Last_dump_level; i++) {
1038 mprintf((0, "Level %i\n", i+1));
1039 load_level(Adam_level_names[i]);
1040 say_totals(my_file, Adam_level_names[i]);
1043 //--05/17/95-- for (i=0; i<NUM_SHAREWARE_LEVELS; i++) {
1044 //--05/17/95-- mprintf((0, "Level %i\n", i+1));
1045 //--05/17/95-- load_level(Shareware_level_names[i]);
1046 //--05/17/95-- say_totals(my_file, Shareware_level_names[i]);
1049 //--05/17/95-- for (i=0; i<NUM_REGISTERED_LEVELS; i++) {
1050 //--05/17/95-- mprintf((0, "Level %i\n", i+1+NUM_SHAREWARE_LEVELS));
1051 //--05/17/95-- load_level(Registered_level_names[i]);
1052 //--05/17/95-- say_totals(my_file, Registered_level_names[i]);
1059 void dump_used_textures_level(FILE *my_file, int level_num)
1062 int temp_tmap_buf[MAX_BITMAP_FILES];
1063 int perm_tmap_buf[MAX_BITMAP_FILES];
1064 sbyte level_tmap_buf[MAX_BITMAP_FILES];
1065 int temp_wall_buf[MAX_BITMAP_FILES];
1066 int perm_wall_buf[MAX_BITMAP_FILES];
1068 for (i=0; i<MAX_BITMAP_FILES; i++) {
1069 perm_tmap_buf[i] = 0;
1070 level_tmap_buf[i] = -1;
1073 for (i=0; i<MAX_BITMAP_FILES; i++) {
1074 perm_wall_buf[i] = 0;
1077 determine_used_textures_level(0, 1, level_num, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1078 // -- determine_used_textures_robots(temp_tmap_buf);
1079 fprintf(my_file, "\nTextures used in [%s]\n", Gamesave_current_filename);
1080 say_used_tmaps(my_file, temp_tmap_buf);
1085 // ----------------------------------------------------------------------------
1086 void dump_used_textures_all(void)
1089 int temp_tmap_buf[MAX_BITMAP_FILES];
1090 int perm_tmap_buf[MAX_BITMAP_FILES];
1091 sbyte level_tmap_buf[MAX_BITMAP_FILES];
1092 int temp_wall_buf[MAX_BITMAP_FILES];
1093 int perm_wall_buf[MAX_BITMAP_FILES];
1097 my_file = fopen( "textures.dmp", "wt" );
1098 // -- mprintf((1, "Fileno = %i\n", fileno(my_file)));
1101 char ErrorMessage[200];
1103 sprintf( ErrorMessage, "ERROR: Can't open textures.dmp\nErrno=%i", errno);
1105 gr_palette_load(gr_palette);
1106 nm_messagebox( NULL, 1, "Ok", ErrorMessage );
1112 for (i=0; i<MAX_BITMAP_FILES; i++) {
1113 perm_tmap_buf[i] = 0;
1114 level_tmap_buf[i] = -1;
1117 for (i=0; i<MAX_BITMAP_FILES; i++) {
1118 perm_wall_buf[i] = 0;
1121 // --05/17/95-- for (i=0; i<NUM_SHAREWARE_LEVELS; i++) {
1122 // --05/17/95-- determine_used_textures_level(1, 1, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1123 // --05/17/95-- fprintf(my_file, "\nTextures used in [%s]\n", Shareware_level_names[i]);
1124 // --05/17/95-- say_used_tmaps(my_file, temp_tmap_buf);
1125 // --05/17/95-- merge_buffers(perm_tmap_buf, temp_tmap_buf, MAX_BITMAP_FILES);
1126 // --05/17/95-- merge_buffers(perm_wall_buf, temp_wall_buf, MAX_BITMAP_FILES);
1129 // --05/17/95-- fprintf(my_file, "\n\nUsed textures in all shareware mines:\n");
1130 // --05/17/95-- say_used_tmaps(my_file, perm_tmap_buf);
1132 // --05/17/95-- fprintf(my_file, "\nUnused textures in all shareware mines:\n");
1133 // --05/17/95-- say_unused_tmaps(my_file, perm_tmap_buf);
1135 // --05/17/95-- fprintf(my_file, "\nTextures used exactly once in all shareware mines:\n");
1136 // --05/17/95-- say_used_once_tmaps(my_file, perm_tmap_buf, level_tmap_buf);
1138 // --05/17/95-- fprintf(my_file, "\nWall anims (eg, doors) unused in all shareware mines:\n");
1139 // --05/17/95-- say_unused_walls(my_file, perm_wall_buf);
1141 // --05/17/95-- for (i=0; i<NUM_REGISTERED_LEVELS; i++) {
1142 // --05/17/95-- determine_used_textures_level(1, 0, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1143 // --05/17/95-- fprintf(my_file, "\nTextures used in [%s]\n", Registered_level_names[i]);
1144 // --05/17/95-- say_used_tmaps(my_file, temp_tmap_buf);
1145 // --05/17/95-- merge_buffers(perm_tmap_buf, temp_tmap_buf, MAX_BITMAP_FILES);
1148 // --05/17/95-- fprintf(my_file, "\n\nUsed textures in all (including registered) mines:\n");
1149 // --05/17/95-- say_used_tmaps(my_file, perm_tmap_buf);
1151 // --05/17/95-- fprintf(my_file, "\nUnused textures in all (including registered) mines:\n");
1152 // --05/17/95-- say_unused_tmaps(my_file, perm_tmap_buf);
1154 for (i=First_dump_level; i<=Last_dump_level; i++) {
1155 determine_used_textures_level(1, 0, i, temp_tmap_buf, temp_wall_buf, level_tmap_buf, MAX_BITMAP_FILES);
1156 fprintf(my_file, "\nTextures used in [%s]\n", Adam_level_names[i]);
1157 say_used_tmaps(my_file, temp_tmap_buf);
1158 merge_buffers(perm_tmap_buf, temp_tmap_buf, MAX_BITMAP_FILES);
1161 fprintf(my_file, "\n\nUsed textures in all (including registered) mines:\n");
1162 say_used_tmaps(my_file, perm_tmap_buf);
1164 fprintf(my_file, "\nUnused textures in all (including registered) mines:\n");
1165 say_unused_tmaps(my_file, perm_tmap_buf);