- Timestamp:
- 05/28/09 14:58:52 (10 months ago)
- Files:
-
- 1 modified
-
trunk/src/monster/monster2.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/monster/monster2.c
r1390 r1415 561 561 void display_monlist(void) 562 562 { 563 int i, max;563 int i, j, k, max; 564 564 int line = 1, x = 0; 565 565 int cur_x; 566 unsigned total_count = 0, disp_count = 0 ;566 unsigned total_count = 0, disp_count = 0, type_count = 0; 567 567 568 568 byte attr; … … 573 573 monster_type *m_ptr; 574 574 monster_race *r_ptr; 575 monster_race *r2_ptr; 575 576 576 577 u16b *race_count; 578 u16b *order; 577 579 578 580 bool in_term = (Term != angband_term[0]); … … 601 603 } 602 604 603 /* Allocate the array */605 /* Allocate the primary array */ 604 606 race_count = C_ZNEW(z_info->r_max, u16b); 605 607 … … 612 614 if (!m_ptr->ml) continue; 613 615 616 /* If this is the first one of this type, count the type */ 617 if (!race_count[m_ptr->r_idx]) type_count++; 618 614 619 /* Bump the count for this race, and the total count */ 615 620 race_count[m_ptr->r_idx]++; … … 636 641 total_count, (total_count > 1 ? "s" : "")), 0, 0); 637 642 638 639 /* Go over in reverse order (so we show harder monsters first) */ 640 for (i = z_info->r_max - 1; (i > 0) && (line < max); i--) 643 /* Allocate the secondary array */ 644 order = C_ZNEW(type_count, u16b); 645 646 647 /* Sort, because we cannot rely on monster.txt being ordered */ 648 649 /* Populate the ordered array, starting at 1 to ignore @ */ 650 for (i = 1; i < z_info->r_max; i++) 641 651 { 642 652 /* No monsters of this race are visible */ 643 653 if (!race_count[i]) continue; 644 654 655 /* Get the monster info */ 656 r_ptr = &r_info[i]; 657 658 /* Fit this monster into the sorted array */ 659 for (j = 0; j < type_count; j++) 660 { 661 r2_ptr = &r_info[order[j]]; 662 663 /* Monsters are sorted by depth */ 664 /* Monsters of same depth are sorted by power */ 665 if ((r_ptr->level > r2_ptr->level) || 666 ((r_ptr->level == r2_ptr->level) && 667 (r_ptr->power > r2_ptr->power))) 668 { 669 /* Move weaker monsters down the array */ 670 for (k = type_count - 1; k > j; k--) 671 { 672 order[k] = order[k - 1]; 673 } 674 675 /* Put current monster in the right place */ 676 order[j] = i; 677 break; 678 } 679 } 680 } 681 682 683 /* Print them out in descending order */ 684 for (i = 0; (i < type_count) && (line < max); i++) 685 { 645 686 /* Reset position */ 646 687 cur_x = x; 647 688 648 689 /* Note that these have been displayed */ 649 disp_count += race_count[ i];690 disp_count += race_count[order[i]]; 650 691 651 692 /* Get monster race and name */ 652 r_ptr = &r_info[ i];693 r_ptr = &r_info[order[i]]; 653 694 m_name = r_name + r_ptr->name; 654 695 … … 662 703 663 704 /* Build the monster name */ 664 if (race_count[ i] == 1)705 if (race_count[order[i]] == 1) 665 706 my_strcpy(buf, m_name, sizeof(buf)); 666 707 else 667 strnfmt(buf, sizeof(buf), "%s (x%d) ", m_name, race_count[i]); 708 strnfmt(buf, sizeof(buf), "%s (x%d) ", m_name, 709 race_count[order[i]]); 668 710 669 711 /* Display the pict */ … … 711 753 Term_addstr(-1, TERM_WHITE, " (Press any key to continue.)"); 712 754 713 /* Free the race counters */755 /* Free the arrays */ 714 756 FREE(race_count); 757 FREE(order); 715 758 } 716 759
