- Timestamp:
- 05/31/09 19:30:18 (15 months ago)
- Location:
- trunk/src/monster
- Files:
-
- 2 modified
-
monster2.c (modified) (12 diffs)
-
types.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/monster/monster2.c
r1415 r1418 564 564 int line = 1, x = 0; 565 565 int cur_x; 566 unsigned total_count = 0, disp_count = 0, type_count = 0 ;566 unsigned total_count = 0, disp_count = 0, type_count = 0, los_count = 0; 567 567 568 568 byte attr; … … 575 575 monster_race *r2_ptr; 576 576 577 u16b *race_count; 577 monster_vis *list; 578 578 579 u16b *order; 579 580 … … 604 605 605 606 /* Allocate the primary array */ 606 race_count = C_ZNEW(z_info->r_max, u16b);607 608 /* Scan the monster list*/607 list = C_ZNEW(z_info->r_max, monster_vis); 608 609 /* Scan the list of monsters on the level */ 609 610 for (i = 1; i < mon_max; i++) 610 611 { 611 612 m_ptr = &mon_list[i]; 612 613 613 /* Only visible monsters */614 /* Only consider visible monsters */ 614 615 if (!m_ptr->ml) continue; 615 616 616 617 /* If this is the first one of this type, count the type */ 617 if (! race_count[m_ptr->r_idx]) type_count++;618 if (!list[m_ptr->r_idx].count) type_count++; 618 619 620 /* Check for LOS */ 621 if (player_has_los_bold(m_ptr->fy, m_ptr->fx)) 622 { 623 /* Increment the total number of in-LOS monsters */ 624 los_count++; 625 626 /* Increment the LOS count for this monster type */ 627 list[m_ptr->r_idx].los++; 628 629 /* Check if awake and increment accordingly */ 630 if (!m_ptr->csleep) list[m_ptr->r_idx].los_awake++; 631 } 632 /* Not in LOS so increment if awake */ 633 else if (!m_ptr->csleep) list[m_ptr->r_idx].awake++; 634 619 635 /* Bump the count for this race, and the total count */ 620 race_count[m_ptr->r_idx]++;636 list[m_ptr->r_idx].count++; 621 637 total_count++; 622 638 } 623 639 624 /* Note no visible monsters */640 /* Note no visible monsters at all */ 625 641 if (!total_count) 626 642 { … … 631 647 632 648 /* Free up memory */ 633 FREE( race_count);649 FREE(list); 634 650 635 651 /* Done */ … … 637 653 } 638 654 639 /* Message */640 prt(format("You can see %d monster%s:",641 total_count, (total_count > 1 ? "s" : "")), 0, 0);642 643 655 /* Allocate the secondary array */ 644 656 order = C_ZNEW(type_count, u16b); 645 657 646 647 658 /* Sort, because we cannot rely on monster.txt being ordered */ 648 659 … … 651 662 { 652 663 /* No monsters of this race are visible */ 653 if (! race_count[i]) continue;664 if (!list[i].count) continue; 654 665 655 666 /* Get the monster info */ … … 659 670 for (j = 0; j < type_count; j++) 660 671 { 672 /* If we get to the end of the list, put this one in */ 673 if (!order[j]) 674 { 675 order[j] = i; 676 break; 677 } 678 679 /* Get the monster info for comparison */ 661 680 r2_ptr = &r_info[order[j]]; 662 681 … … 679 698 } 680 699 } 681 682 683 /* Print them out in descending order */ 700 701 /* Message for monsters in LOS */ 702 prt(format("You can see %d monster%s", los_count, 703 (los_count > 0 ? (los_count == 1 ? ":" : "s:") : "s.")), 0, 0); 704 705 /* Print out in-LOS monsters in descending order */ 684 706 for (i = 0; (i < type_count) && (line < max); i++) 685 707 { 708 /* Skip if there are none of these in LOS */ 709 if (!list[order[i]].los) continue; 710 686 711 /* Reset position */ 687 712 cur_x = x; 688 713 689 714 /* Note that these have been displayed */ 690 disp_count += race_count[order[i]];715 disp_count += list[order[i]].los; 691 716 692 717 /* Get monster race and name */ … … 703 728 704 729 /* Build the monster name */ 705 if ( race_count[order[i]]== 1)706 my_strcpy(buf, m_name, sizeof(buf));707 else708 strnfmt(buf, sizeof(buf), "%s (x%d) ", m_name,709 race_count[order[i]]);730 if (list[order[i]].los == 1) 731 strnfmt(buf, sizeof(buf), (list[order[i]].los_awake == 732 1 ? "%s (awake) " : "%s (asleep) "), m_name); 733 else strnfmt(buf, sizeof(buf), "%s (x%d, %d awake) ", m_name, 734 list[order[i]].los, list[order[i]].los_awake); 710 735 711 736 /* Display the pict */ … … 729 754 730 755 /* Reprint Message */ 731 prt(format("You can see %d monster%s:", 732 total_count, (total_count > 1 ? "s" : "")), 0, 0); 756 prt(format("You can see %d monster%s", 757 los_count, (los_count > 0 ? (los_count == 1 ? 758 ":" : "s:") : "s.")), 0, 0); 733 759 734 760 /* Reset */ … … 737 763 } 738 764 765 /* Message for monsters outside LOS */ 766 prt(format("You are aware of %d %smonster%s", 767 (total_count - los_count), (los_count > 0 ? "other " : ""), 768 ((total_count - los_count) > 0 ? ((total_count - los_count) == 769 1 ? ":" : "s:") : "s.")), line++, 0); 770 771 /* Print out non-LOS monsters in descending order */ 772 for (i = 0; (i < type_count) && (line < max); i++) 773 { 774 /* Skip if there are none of these out of LOS */ 775 if (list[order[i]].count == list[order[i]].los) continue; 776 777 /* Reset position */ 778 cur_x = x; 779 780 /* Note that these have been displayed */ 781 disp_count += (list[order[i]].count - list[order[i]].los); 782 783 /* Get monster race and name */ 784 r_ptr = &r_info[order[i]]; 785 m_name = r_name + r_ptr->name; 786 787 /* Display uniques in a special colour */ 788 if (r_ptr->flags[0] & RF0_UNIQUE) 789 attr = TERM_VIOLET; 790 else if (r_ptr->level > p_ptr->depth) 791 attr = TERM_RED; 792 else 793 attr = TERM_WHITE; 794 795 /* Build the monster name */ 796 if ((list[order[i]].count - list[order[i]].los) == 1) 797 strnfmt(buf, sizeof(buf), (list[order[i]].awake == 798 1 ? "%s (awake) " : "%s (asleep) "), m_name); 799 else strnfmt(buf, sizeof(buf), "%s (x%d, %d awake) ", m_name, 800 (list[order[i]].count - list[order[i]].los), 801 list[order[i]].awake); 802 803 /* Display the pict */ 804 Term_putch(cur_x++, line, r_ptr->x_attr, r_ptr->x_char); 805 if (use_bigtile) Term_putch(cur_x++, line, 255, -1); 806 Term_putch(cur_x++, line, TERM_WHITE, ' '); 807 808 /* Print and bump line counter */ 809 c_prt(attr, buf, line, cur_x); 810 line++; 811 812 /* Page wrap */ 813 if (!in_term && (line == max) && disp_count != total_count) 814 { 815 prt("-- more --", line, x); 816 anykey(); 817 818 /* Clear the screen */ 819 for (line = 1; line <= max; line++) 820 prt("", line, x); 821 822 /* Reprint Message */ 823 prt(format("You can see %d %smonster%s", 824 (total_count - los_count), (los_count > 0 ? 825 "other " : ""), ((total_count - los_count) > 0 826 ? ((total_count - los_count) == 1 ? ":" : "s:") 827 : "s.")), 0, 0); 828 829 /* Reset */ 830 line = 1; 831 } 832 } 833 834 739 835 /* Print "and others" message if we've run out of space */ 740 836 if (disp_count != total_count) … … 754 850 755 851 /* Free the arrays */ 756 FREE( race_count);852 FREE(list); 757 853 FREE(order); 758 854 } -
trunk/src/monster/types.h
r1220 r1418 155 155 } monster_type; 156 156 157 /* 158 * Monster data for the visible monster list 159 */ 160 typedef struct 161 { 162 u16b count; /* total number of this type visible */ 163 u16b awake; /* number awake */ 164 u16b los; /* number in LOS */ 165 u16b los_awake; /* number awake and in LOS */ 166 } monster_vis; 167 157 168 #endif /* INCLUDED_MONSTER_TYPES_H */
