* Used by: crystal balls, potions, fountains * * Returns 1 if nothing was detected. * Returns 0 if something was detected. */
| 795 | * Returns 0 if something was detected. |
| 796 | */ |
| 797 | int |
| 798 | monster_detect(struct obj *otmp, /* detecting object (if any) */ |
| 799 | int mclass) /* monster class, 0 for all */ |
| 800 | { |
| 801 | struct monst *mtmp; |
| 802 | int mcnt = 0; |
| 803 | |
| 804 | /* Note: This used to just check fmon for a non-zero value |
| 805 | * but in versions since 3.3.0 fmon can test TRUE due to the |
| 806 | * presence of dmons, so we have to find at least one |
| 807 | * with positive hit-points to know for sure. |
| 808 | */ |
| 809 | for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { |
| 810 | if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) |
| 811 | continue; |
| 812 | ++mcnt; |
| 813 | break; /* no need for full count, just 1 or more vs 0 */ |
| 814 | } |
| 815 | |
| 816 | if (!mcnt) { |
| 817 | if (otmp) |
| 818 | strange_feeling(otmp, Hallucination |
| 819 | ? "You get the heebie jeebies." |
| 820 | : "You feel threatened."); |
| 821 | return 1; |
| 822 | } else { |
| 823 | boolean unconstrained, woken = FALSE; |
| 824 | unsigned swallowed = u.uswallow; /* before unconstrain_map() */ |
| 825 | |
| 826 | cls(); |
| 827 | unconstrained = unconstrain_map(); |
| 828 | for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { |
| 829 | if (DEADMONSTER(mtmp) || (mtmp->isgd && !mtmp->mx)) |
| 830 | continue; |
| 831 | if (!mclass || mtmp->data->mlet == mclass |
| 832 | || (mtmp->data == &mons[PM_LONG_WORM] |
| 833 | && mclass == S_WORM_TAIL)) |
| 834 | map_monst(mtmp, TRUE); |
| 835 | |
| 836 | if (otmp && otmp->cursed && helpless(mtmp)) { |
| 837 | mtmp->msleeping = mtmp->mfrozen = 0; |
| 838 | mtmp->mcanmove = 1; |
| 839 | woken = TRUE; |
| 840 | } |
| 841 | } |
| 842 | if (!swallowed) |
| 843 | display_self(); |
| 844 | You("sense the presence of monsters."); |
| 845 | if (woken) |
| 846 | pline("Monsters sense the presence of you."); |
| 847 | |
| 848 | if ((otmp && otmp->blessed) && !unconstrained) { |
| 849 | /* persistent detection--just show updated map */ |
| 850 | display_nhwindow(WIN_MAP, TRUE); |
| 851 | } else { |
| 852 | /* one-shot detection--allow player to move cursor around and |
| 853 | get autodescribe feedback */ |
| 854 | EDetect_monsters |= I_SPECIAL; |
no test coverage detected