Changeset 1418

Show
Ignore:
Timestamp:
05/31/09 19:30:18 (10 months ago)
Author:
magnate
Message:

Monster display now shows in/out of LOS and asleep/awake - closes #848

Location:
trunk/src/monster
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/monster/monster2.c

    r1415 r1418  
    564564        int line = 1, x = 0; 
    565565        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; 
    567567 
    568568        byte attr; 
     
    575575        monster_race *r2_ptr; 
    576576 
    577         u16b *race_count; 
     577        monster_vis *list; 
     578         
    578579        u16b *order; 
    579580 
     
    604605 
    605606        /* 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 */ 
    609610        for (i = 1; i < mon_max; i++) 
    610611        { 
    611612                m_ptr = &mon_list[i]; 
    612613 
    613                 /* Only visible monsters */ 
     614                /* Only consider visible monsters */ 
    614615                if (!m_ptr->ml) continue; 
    615616 
    616617                /* 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++; 
    618619                 
     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 
    619635                /* Bump the count for this race, and the total count */ 
    620                 race_count[m_ptr->r_idx]++; 
     636                list[m_ptr->r_idx].count++; 
    621637                total_count++; 
    622638        } 
    623639 
    624         /* Note no visible monsters */ 
     640        /* Note no visible monsters at all */ 
    625641        if (!total_count) 
    626642        { 
     
    631647 
    632648                /* Free up memory */ 
    633                 FREE(race_count); 
     649                FREE(list); 
    634650 
    635651                /* Done */ 
     
    637653        } 
    638654 
    639         /* Message */ 
    640         prt(format("You can see %d monster%s:", 
    641                 total_count, (total_count > 1 ? "s" : "")), 0, 0); 
    642  
    643655        /* Allocate the secondary array */ 
    644656        order = C_ZNEW(type_count, u16b); 
    645657 
    646  
    647658        /* Sort, because we cannot rely on monster.txt being ordered */ 
    648659 
     
    651662        { 
    652663                /* No monsters of this race are visible */ 
    653                 if (!race_count[i]) continue; 
     664                if (!list[i].count) continue; 
    654665 
    655666                /* Get the monster info */ 
     
    659670                for (j = 0; j < type_count; j++) 
    660671                { 
     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 */ 
    661680                        r2_ptr = &r_info[order[j]]; 
    662681 
     
    679698                } 
    680699        } 
    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 */ 
    684706        for (i = 0; (i < type_count) && (line < max); i++) 
    685707        { 
     708                /* Skip if there are none of these in LOS */ 
     709                if (!list[order[i]].los) continue; 
     710 
    686711                /* Reset position */ 
    687712                cur_x = x; 
    688713 
    689714                /* Note that these have been displayed */ 
    690                 disp_count += race_count[order[i]]; 
     715                disp_count += list[order[i]].los; 
    691716 
    692717                /* Get monster race and name */ 
     
    703728 
    704729                /* Build the monster name */ 
    705                 if (race_count[order[i]] == 1) 
    706                         my_strcpy(buf, m_name, sizeof(buf)); 
    707                 else 
    708                         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); 
    710735 
    711736                /* Display the pict */ 
     
    729754 
    730755                        /* 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); 
    733759 
    734760                        /* Reset */ 
     
    737763        } 
    738764 
     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 
    739835        /* Print "and others" message if we've run out of space */ 
    740836        if (disp_count != total_count) 
     
    754850 
    755851        /* Free the arrays */ 
    756         FREE(race_count); 
     852        FREE(list); 
    757853        FREE(order); 
    758854} 
  • trunk/src/monster/types.h

    r1220 r1418  
    155155} monster_type; 
    156156 
     157/*  
     158 * Monster data for the visible monster list  
     159 */ 
     160typedef 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 
    157168#endif /* INCLUDED_MONSTER_TYPES_H */