MCPcopy Create free account
hub / github.com/NetHack/NetHack / CapitalMon

Function CapitalMon

src/rumors.c:790–822  ·  view source on GitHub ↗

is 'word' a capitalized monster name that should be preceded by "the"? (non-unique monster like Mordor Orc, or capitalized title like Norn rather than a name); used by the() on a string without any context; this sets up a list of names rather than scan all of mons[] every time the decision is needed (resulting list currently contains 27 monster entries and 20 hallucination entries)

Source from the content-addressed store, hash-verified

788 the decision is needed (resulting list currently contains 27 monster
789 entries and 20 hallucination entries) */
790boolean
791CapitalMon(
792 const char *word) /* potential monster name; a name might be followed by
793 * something like " corpse" */
794{
795 const char *nam;
796 unsigned i, wln, nln;
797
798 if (!word || !*word || *word == lowc(*word))
799 return FALSE; /* 'word' is not a capitalized monster name */
800
801 if (!CapMons)
802 init_CapMons();
803 assert(CapMons != 0);
804
805 wln = (unsigned) strlen(word);
806 for (i = 0; i < CapMonSiz - 1; ++i) {
807 nam = CapMons[i];
808 nln = (unsigned) strlen(nam);
809 if (wln < nln)
810 continue;
811 /*
812 * Unlike name_to_mon(), we don't need to find the longest match
813 * or return the gender or a pointer to trailing stuff. We do
814 * check full words though: "Foo" matches "Foo" and "Foo bar" and
815 * "Foo's bar" but not "Foobar". We use case-sensitive matching.
816 */
817 if (!strncmp(nam, word, nln)
818 && (!word[nln] || word[nln] == ' ' || word[nln] == '\''))
819 return TRUE; /* 'word' is a capitalized monster name */
820 }
821 return FALSE;
822}
823
824/* one-time initialization of CapMons[], a list of non-unique monsters
825 having a capitalized type name like Green-elf or Archon, plus unique

Callers 2

theFunction · 0.85
dump_weightsFunction · 0.85

Calls 2

init_CapMonsFunction · 0.85
lowcFunction · 0.70

Tested by

no test coverage detected