Difference between revisions of "Source:NetHack 3.4.3/src/mondata.c"

From NetHackWiki
Jump to navigation Jump to search
(Automated source code upload)
 
(num_horns: Annotate.)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
__MIXEDSYNTAXHIGHLIGHT__
 +
Below is the full text to src/mondata.c from NetHack 3.4.3. To link to a particular line, write [[mondata.c#line123|<nowiki>[[mondata.c#line123]]</nowiki>]], for example.
 +
 +
== Top of file ==
  
Below is the full text to src/mondata.c from NetHack 3.4.3. To link to a particular line, write [[mondata.c#line123|<nowiki>[[mondata.c#line123]]</nowiki>]], for example.
 
 
  <span id="line1">1.    /* SCCS Id: @(#)mondata.c 3.4 2003/06/02 */</span>
 
  <span id="line1">1.    /* SCCS Id: @(#)mondata.c 3.4 2003/06/02 */</span>
 
  <span id="line2">2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */</span>
 
  <span id="line2">2.    /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */</span>
Line 16: Line 19:
 
  <span id="line11">11.  #ifdef OVLB</span>
 
  <span id="line11">11.  #ifdef OVLB</span>
 
  <span id="line12">12.  </span>
 
  <span id="line12">12.  </span>
 +
 +
== set_mon_data ==
 +
 
  <span id="line13">13.  void</span>
 
  <span id="line13">13.  void</span>
 
  <span id="line14">14.  set_mon_data(mon, ptr, flag)</span>
 
  <span id="line14">14.  set_mon_data(mon, ptr, flag)</span>
Line 35: Line 41:
 
  <span id="line30">30.  #ifdef OVL0</span>
 
  <span id="line30">30.  #ifdef OVL0</span>
 
  <span id="line31">31.  </span>
 
  <span id="line31">31.  </span>
 +
 +
== attacktype_fordmg ==
 +
 
  <span id="line32">32.  struct attack *</span>
 
  <span id="line32">32.  struct attack *</span>
 
  <span id="line33">33.  attacktype_fordmg(ptr, atyp, dtyp)</span>
 
  <span id="line33">33.  attacktype_fordmg(ptr, atyp, dtyp)</span>
Line 49: Line 58:
 
  <span id="line44">44.  }</span>
 
  <span id="line44">44.  }</span>
 
  <span id="line45">45.  </span>
 
  <span id="line45">45.  </span>
 +
 +
== attacktype ==
 +
 
  <span id="line46">46.  boolean</span>
 
  <span id="line46">46.  boolean</span>
 
  <span id="line47">47.  attacktype(ptr, atyp)</span>
 
  <span id="line47">47.  attacktype(ptr, atyp)</span>
Line 60: Line 72:
 
  <span id="line55">55.  #ifdef OVLB</span>
 
  <span id="line55">55.  #ifdef OVLB</span>
 
  <span id="line56">56.  </span>
 
  <span id="line56">56.  </span>
 +
 +
== poly_when_stoned ==
 +
 
  <span id="line57">57.  boolean</span>
 
  <span id="line57">57.  boolean</span>
 
  <span id="line58">58.  poly_when_stoned(ptr)</span>
 
  <span id="line58">58.  poly_when_stoned(ptr)</span>
Line 69: Line 84:
 
  <span id="line64">64.  }</span>
 
  <span id="line64">64.  }</span>
 
  <span id="line65">65.  </span>
 
  <span id="line65">65.  </span>
 +
 +
== resists_drli ==
 +
 
  <span id="line66">66.  boolean</span>
 
  <span id="line66">66.  boolean</span>
 
  <span id="line67">67.  resists_drli(mon) /* returns TRUE if monster is drain-life resistant */</span>
 
  <span id="line67">67.  resists_drli(mon) /* returns TRUE if monster is drain-life resistant */</span>
Line 81: Line 99:
 
  <span id="line76">76.  }</span>
 
  <span id="line76">76.  }</span>
 
  <span id="line77">77.  </span>
 
  <span id="line77">77.  </span>
 +
 +
== resists_magm ==
 +
 
  <span id="line78">78.  boolean</span>
 
  <span id="line78">78.  boolean</span>
 
  <span id="line79">79.  resists_magm(mon) /* TRUE if monster is magic-missile resistant */</span>
 
  <span id="line79">79.  resists_magm(mon) /* TRUE if monster is magic-missile resistant */</span>
Line 105: Line 126:
 
  <span id="line100">100.  }</span>
 
  <span id="line100">100.  }</span>
 
  <span id="line101">101.  </span>
 
  <span id="line101">101.  </span>
 +
 +
== resists_blnd ==
 +
 
  <span id="line102">102.  /* TRUE iff monster is resistant to light-induced blindness */</span>
 
  <span id="line102">102.  /* TRUE iff monster is resistant to light-induced blindness */</span>
 
  <span id="line103">103.  boolean</span>
 
  <span id="line103">103.  boolean</span>
Line 135: Line 159:
 
  <span id="line130">130.  }</span>
 
  <span id="line130">130.  }</span>
 
  <span id="line131">131.  </span>
 
  <span id="line131">131.  </span>
 +
 +
== can_blnd ==
 +
 
  <span id="line132">132.  /* TRUE iff monster can be blinded by the given attack */</span>
 
  <span id="line132">132.  /* TRUE iff monster can be blinded by the given attack */</span>
 
  <span id="line133">133.  /* Note: may return TRUE when mdef is blind (e.g. new cream-pie attack) */</span>
 
  <span id="line133">133.  /* Note: may return TRUE when mdef is blind (e.g. new cream-pie attack) */</span>
Line 221: Line 248:
 
  <span id="line216">216.  #ifdef OVL0</span>
 
  <span id="line216">216.  #ifdef OVL0</span>
 
  <span id="line217">217.  </span>
 
  <span id="line217">217.  </span>
 +
 +
== ranged_attk ==
 +
 
  <span id="line218">218.  boolean</span>
 
  <span id="line218">218.  boolean</span>
 
  <span id="line219">219.  ranged_attk(ptr) /* returns TRUE if monster can attack at range */</span>
 
  <span id="line219">219.  ranged_attk(ptr) /* returns TRUE if monster can attack at range */</span>
Line 243: Line 273:
 
  <span id="line238">238.  }</span>
 
  <span id="line238">238.  }</span>
 
  <span id="line239">239.  </span>
 
  <span id="line239">239.  </span>
 +
 +
== hates_silver ==
 +
 
  <span id="line240">240.  boolean</span>
 
  <span id="line240">240.  boolean</span>
 
  <span id="line241">241.  hates_silver(ptr)</span>
 
  <span id="line241">241.  hates_silver(ptr)</span>
Line 253: Line 286:
 
  <span id="line248">248.  }</span>
 
  <span id="line248">248.  }</span>
 
  <span id="line249">249.  </span>
 
  <span id="line249">249.  </span>
 +
 +
== passes_bars ==
 +
 
  <span id="line250">250.  /* true iff the type of monster pass through iron bars */</span>
 
  <span id="line250">250.  /* true iff the type of monster pass through iron bars */</span>
 
  <span id="line251">251.  boolean</span>
 
  <span id="line251">251.  boolean</span>
Line 266: Line 302:
 
  <span id="line261">261.  #ifdef OVL1</span>
 
  <span id="line261">261.  #ifdef OVL1</span>
 
  <span id="line262">262.  </span>
 
  <span id="line262">262.  </span>
 +
 +
== can_track ==
 +
 
  <span id="line263">263.  boolean</span>
 
  <span id="line263">263.  boolean</span>
 
  <span id="line264">264.  can_track(ptr) /* returns TRUE if monster can track well */</span>
 
  <span id="line264">264.  can_track(ptr) /* returns TRUE if monster can track well */</span>
Line 279: Line 318:
 
  <span id="line274">274.  #ifdef OVLB</span>
 
  <span id="line274">274.  #ifdef OVLB</span>
 
  <span id="line275">275.  </span>
 
  <span id="line275">275.  </span>
 +
 +
== sliparm ==
 +
 
  <span id="line276">276.  boolean</span>
 
  <span id="line276">276.  boolean</span>
 
  <span id="line277">277.  sliparm(ptr) /* creature will slide out of armor */</span>
 
  <span id="line277">277.  sliparm(ptr) /* creature will slide out of armor */</span>
Line 287: Line 329:
 
  <span id="line282">282.  }</span>
 
  <span id="line282">282.  }</span>
 
  <span id="line283">283.  </span>
 
  <span id="line283">283.  </span>
 +
 +
== breakarm ==
 +
 
  <span id="line284">284.  boolean</span>
 
  <span id="line284">284.  boolean</span>
 
  <span id="line285">285.  breakarm(ptr) /* creature will break out of armor */</span>
 
  <span id="line285">285.  breakarm(ptr) /* creature will break out of armor */</span>
Line 299: Line 344:
 
  <span id="line294">294.  #ifdef OVL1</span>
 
  <span id="line294">294.  #ifdef OVL1</span>
 
  <span id="line295">295.  </span>
 
  <span id="line295">295.  </span>
 +
 +
== sticks ==
 +
 
  <span id="line296">296.  boolean</span>
 
  <span id="line296">296.  boolean</span>
 
  <span id="line297">297.  sticks(ptr) /* creature sticks other creatures it hits */</span>
 
  <span id="line297">297.  sticks(ptr) /* creature sticks other creatures it hits */</span>
Line 307: Line 355:
 
  <span id="line302">302.  }</span>
 
  <span id="line302">302.  }</span>
 
  <span id="line303">303.  </span>
 
  <span id="line303">303.  </span>
 +
 +
== num_horns ==
 +
Used for correct pluralization of helm related messages in do_wear.c, worn.c, and polyself.c. There is also a macro, has_horns, defined in mondata.h line 48 ("#define has_horns(ptr) (num_horns(ptr) > 0)").
 
  <span id="line304">304.  /* number of horns this type of monster has on its head */</span>
 
  <span id="line304">304.  /* number of horns this type of monster has on its head */</span>
 
  <span id="line305">305.  int</span>
 
  <span id="line305">305.  int</span>
Line 329: Line 380:
 
  <span id="line324">324.  }</span>
 
  <span id="line324">324.  }</span>
 
  <span id="line325">325.  </span>
 
  <span id="line325">325.  </span>
 +
 +
== dmgtype_fromattack ==
 +
 
  <span id="line326">326.  struct attack *</span>
 
  <span id="line326">326.  struct attack *</span>
 
  <span id="line327">327.  dmgtype_fromattack(ptr, dtyp, atyp)</span>
 
  <span id="line327">327.  dmgtype_fromattack(ptr, dtyp, atyp)</span>
Line 343: Line 397:
 
  <span id="line338">338.  }</span>
 
  <span id="line338">338.  }</span>
 
  <span id="line339">339.  </span>
 
  <span id="line339">339.  </span>
 +
 +
== dmgtype ==
 +
 
  <span id="line340">340.  boolean</span>
 
  <span id="line340">340.  boolean</span>
 
  <span id="line341">341.  dmgtype(ptr, dtyp)</span>
 
  <span id="line341">341.  dmgtype(ptr, dtyp)</span>
Line 351: Line 408:
 
  <span id="line346">346.  }</span>
 
  <span id="line346">346.  }</span>
 
  <span id="line347">347.  </span>
 
  <span id="line347">347.  </span>
 +
 +
== max_passive_dmg ==
 +
 
  <span id="line348">348.  /* returns the maximum damage a defender can do to the attacker via</span>
 
  <span id="line348">348.  /* returns the maximum damage a defender can do to the attacker via</span>
 
  <span id="line349">349.  * a passive defense */</span>
 
  <span id="line349">349.  * a passive defense */</span>
Line 382: Line 442:
 
  <span id="line377">377.  #ifdef OVL0</span>
 
  <span id="line377">377.  #ifdef OVL0</span>
 
  <span id="line378">378.  </span>
 
  <span id="line378">378.  </span>
 +
 +
== monsndx ==
 +
 
  <span id="line379">379.  int</span>
 
  <span id="line379">379.  int</span>
 
  <span id="line380">380.  monsndx(ptr) /* return an index into the mons array */</span>
 
  <span id="line380">380.  monsndx(ptr) /* return an index into the mons array */</span>
Line 403: Line 466:
 
  <span id="line398">398.  </span>
 
  <span id="line398">398.  </span>
 
  <span id="line399">399.  </span>
 
  <span id="line399">399.  </span>
 +
 +
== name_to_mon ==
 +
 
  <span id="line400">400.  int</span>
 
  <span id="line400">400.  int</span>
 
  <span id="line401">401.  name_to_mon(in_str)</span>
 
  <span id="line401">401.  name_to_mon(in_str)</span>
Line 518: Line 584:
 
  <span id="line513">513.  #ifdef OVL2</span>
 
  <span id="line513">513.  #ifdef OVL2</span>
 
  <span id="line514">514.  </span>
 
  <span id="line514">514.  </span>
 +
 +
== gender ==
 +
 
  <span id="line515">515.  /* returns 3 values (0=male, 1=female, 2=none) */</span>
 
  <span id="line515">515.  /* returns 3 values (0=male, 1=female, 2=none) */</span>
 
  <span id="line516">516.  int</span>
 
  <span id="line516">516.  int</span>
Line 527: Line 596:
 
  <span id="line522">522.  }</span>
 
  <span id="line522">522.  }</span>
 
  <span id="line523">523.  </span>
 
  <span id="line523">523.  </span>
 +
 +
== pronoun_gender ==
 +
 
  <span id="line524">524.  /* Like gender(), but lower animals and such are still "it". */</span>
 
  <span id="line524">524.  /* Like gender(), but lower animals and such are still "it". */</span>
 
  <span id="line525">525.  /* This is the one we want to use when printing messages. */</span>
 
  <span id="line525">525.  /* This is the one we want to use when printing messages. */</span>
Line 541: Line 613:
 
  <span id="line536">536.  #ifdef OVLB</span>
 
  <span id="line536">536.  #ifdef OVLB</span>
 
  <span id="line537">537.  </span>
 
  <span id="line537">537.  </span>
 +
 +
== levl_follower ==
 +
 
  <span id="line538">538.  /* used for nearby monsters when you go to another level */</span>
 
  <span id="line538">538.  /* used for nearby monsters when you go to another level */</span>
 
  <span id="line539">539.  boolean</span>
 
  <span id="line539">539.  boolean</span>
Line 558: Line 633:
 
  <span id="line553">553.  }</span>
 
  <span id="line553">553.  }</span>
 
  <span id="line554">554.  </span>
 
  <span id="line554">554.  </span>
 +
 +
== grownups-array ==
 +
 
  <span id="line555">555.  static const short grownups[][2] = {</span>
 
  <span id="line555">555.  static const short grownups[][2] = {</span>
 
  <span id="line556">556.  {PM_CHICKATRICE, PM_COCKATRICE},</span>
 
  <span id="line556">556.  {PM_CHICKATRICE, PM_COCKATRICE},</span>
Line 619: Line 697:
 
  <span id="line614">614.  };</span>
 
  <span id="line614">614.  };</span>
 
  <span id="line615">615.  </span>
 
  <span id="line615">615.  </span>
 +
 +
== little_to_big ==
 +
 
  <span id="line616">616.  int</span>
 
  <span id="line616">616.  int</span>
 
  <span id="line617">617.  little_to_big(montype)</span>
 
  <span id="line617">617.  little_to_big(montype)</span>
Line 646: Line 727:
 
  <span id="line641">641.  }</span>
 
  <span id="line641">641.  }</span>
 
  <span id="line642">642.  </span>
 
  <span id="line642">642.  </span>
 +
 +
== big_to_little ==
 +
 
  <span id="line643">643.  int</span>
 
  <span id="line643">643.  int</span>
 
  <span id="line644">644.  big_to_little(montype)</span>
 
  <span id="line644">644.  big_to_little(montype)</span>
Line 657: Line 741:
 
  <span id="line652">652.  }</span>
 
  <span id="line652">652.  }</span>
 
  <span id="line653">653.  </span>
 
  <span id="line653">653.  </span>
 +
 +
== raceptr ==
 +
 
  <span id="line654">654.  /*</span>
 
  <span id="line654">654.  /*</span>
 
  <span id="line655">655.  * Return the permonst ptr for the race of the monster.</span>
 
  <span id="line655">655.  * Return the permonst ptr for the race of the monster.</span>
Line 670: Line 757:
 
  <span id="line665">665.  }</span>
 
  <span id="line665">665.  }</span>
 
  <span id="line666">666.  </span>
 
  <span id="line666">666.  </span>
 +
 +
== locomotion ==
 +
 
  <span id="line667">667.  static const char *levitate[4] = { "float", "Float", "wobble", "Wobble" };</span>
 
  <span id="line667">667.  static const char *levitate[4] = { "float", "Float", "wobble", "Wobble" };</span>
 
  <span id="line668">668.  static const char *flys[4] = { "fly", "Fly", "flutter", "Flutter" };</span>
 
  <span id="line668">668.  static const char *flys[4] = { "fly", "Fly", "flutter", "Flutter" };</span>
Line 698: Line 788:
 
  <span id="line693">693.  }</span>
 
  <span id="line693">693.  }</span>
 
  <span id="line694">694.  </span>
 
  <span id="line694">694.  </span>
 +
 +
== stagger ==
 +
 
  <span id="line695">695.  const char *</span>
 
  <span id="line695">695.  const char *</span>
 
  <span id="line696">696.  stagger(ptr, def)</span>
 
  <span id="line696">696.  stagger(ptr, def)</span>
Line 718: Line 811:
 
  <span id="line713">713.  }</span>
 
  <span id="line713">713.  }</span>
 
  <span id="line714">714.  </span>
 
  <span id="line714">714.  </span>
 +
 +
== on_fire ==
 +
 
  <span id="line715">715.  /* return a phrase describing the effect of fire attack on a type of monster */</span>
 
  <span id="line715">715.  /* return a phrase describing the effect of fire attack on a type of monster */</span>
 
  <span id="line716">716.  const char *</span>
 
  <span id="line716">716.  const char *</span>

Latest revision as of 17:59, 23 December 2011

Below is the full text to src/mondata.c from NetHack 3.4.3. To link to a particular line, write [[mondata.c#line123]], for example.

Top of file

/*	SCCS Id: @(#)mondata.c	3.4	2003/06/02	*/
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed.  See license for details. */

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

#include "hack.h"
#include "eshk.h"
#include "epri.h"

/*	These routines provide basic data for any type of monster. */

#ifdef OVLB

set_mon_data

void
set_mon_data(mon, ptr, flag)
struct monst *mon;
struct permonst *ptr;
int flag;
{
mon->data = ptr;
if (flag == -1) return;		/* "don't care" */

if (flag == 1)
	mon->mintrinsics |= (ptr->mresists & 0x00FF);
else
	mon->mintrinsics = (ptr->mresists & 0x00FF);
return;
}

#endif /* OVLB */
#ifdef OVL0

attacktype_fordmg

struct attack *
attacktype_fordmg(ptr, atyp, dtyp)
struct permonst *ptr;
int atyp, dtyp;
{
struct attack *a;

for (a = &ptr->mattk[0]; a < &ptr->mattk[NATTK]; a++)
	if (a->aatyp == atyp && (dtyp == AD_ANY || a->adtyp == dtyp))
	    return a;

return (struct attack *)0;
}

attacktype

boolean
attacktype(ptr, atyp)
struct permonst *ptr;
int atyp;
{
return attacktype_fordmg(ptr, atyp, AD_ANY) ? TRUE : FALSE;
}

#endif /* OVL0 */
#ifdef OVLB

poly_when_stoned

boolean
poly_when_stoned(ptr)
struct permonst *ptr;
{
return((boolean)(is_golem(ptr) && ptr != &mons[PM_STONE_GOLEM] &&
	    !(mvitals[PM_STONE_GOLEM].mvflags & G_GENOD)));
	    /* allow G_EXTINCT */
}

resists_drli

boolean
resists_drli(mon)	/* returns TRUE if monster is drain-life resistant */
struct monst *mon;
{
	struct permonst *ptr = mon->data;
	struct obj *wep = ((mon == &youmonst) ? uwep : MON_WEP(mon));

	return (boolean)(is_undead(ptr) || is_demon(ptr) || is_were(ptr) ||
			 ptr == &mons[PM_DEATH] ||
			 (wep && wep->oartifact && defends(AD_DRLI, wep)));
}

resists_magm

boolean
resists_magm(mon)	/* TRUE if monster is magic-missile resistant */
struct monst *mon;
{
	struct permonst *ptr = mon->data;
	struct obj *o;

	/* as of 3.2.0:  gray dragons, Angels, Oracle, Yeenoghu */
	if (dmgtype(ptr, AD_MAGM) || ptr == &mons[PM_BABY_GRAY_DRAGON] ||
		dmgtype(ptr, AD_RBRE))	/* Chromatic Dragon */
	    return TRUE;
	/* check for magic resistance granted by wielded weapon */
	o = (mon == &youmonst) ? uwep : MON_WEP(mon);
	if (o && o->oartifact && defends(AD_MAGM, o))
	    return TRUE;
	/* check for magic resistance granted by worn or carried items */
	o = (mon == &youmonst) ? invent : mon->minvent;
	for ( ; o; o = o->nobj)
	    if ((o->owornmask && objects[o->otyp].oc_oprop == ANTIMAGIC) ||
		    (o->oartifact && protects(AD_MAGM, o)))
		return TRUE;
	return FALSE;
}

resists_blnd

/* TRUE iff monster is resistant to light-induced blindness */
boolean
resists_blnd(mon)
struct monst *mon;
{
	struct permonst *ptr = mon->data;
	boolean is_you = (mon == &youmonst);
	struct obj *o;

	if (is_you ? (Blind || u.usleep) :
		(mon->mblinded || !mon->mcansee || !haseyes(ptr) ||
		    /* BUG: temporary sleep sets mfrozen, but since
			    paralysis does too, we can't check it */
		    mon->msleeping))
	    return TRUE;
	/* yellow light, Archon; !dust vortex, !cobra, !raven */
	if (dmgtype_fromattack(ptr, AD_BLND, AT_EXPL) ||
		dmgtype_fromattack(ptr, AD_BLND, AT_GAZE))
	    return TRUE;
	o = is_you ? uwep : MON_WEP(mon);
	if (o && o->oartifact && defends(AD_BLND, o))
	    return TRUE;
	o = is_you ? invent : mon->minvent;
	for ( ; o; o = o->nobj)
	    if ((o->owornmask && objects[o->otyp].oc_oprop == BLINDED) ||
		    (o->oartifact && protects(AD_BLND, o)))
		return TRUE;
	return FALSE;
}

can_blnd

/* TRUE iff monster can be blinded by the given attack */
/* Note: may return TRUE when mdef is blind (e.g. new cream-pie attack) */
boolean
can_blnd(magr, mdef, aatyp, obj)
struct monst *magr;		/* NULL == no specific aggressor */
struct monst *mdef;
uchar aatyp;
struct obj *obj;		/* aatyp == AT_WEAP, AT_SPIT */
{
	boolean is_you = (mdef == &youmonst);
	boolean check_visor = FALSE;
	struct obj *o;
	const char *s;

	/* no eyes protect against all attacks for now */
	if (!haseyes(mdef->data))
	    return FALSE;

	switch(aatyp) {
	case AT_EXPL: case AT_BOOM: case AT_GAZE: case AT_MAGC:
	case AT_BREA: /* assumed to be lightning */
	    /* light-based attacks may be cancelled or resisted */
	    if (magr && magr->mcan)
		return FALSE;
	    return !resists_blnd(mdef);

	case AT_WEAP: case AT_SPIT: case AT_NONE:
	    /* an object is used (thrown/spit/other) */
	    if (obj && (obj->otyp == CREAM_PIE)) {
		if (is_you && Blindfolded)
		    return FALSE;
	    } else if (obj && (obj->otyp == BLINDING_VENOM)) {
		/* all ublindf, including LENSES, protect, cream-pies too */
		if (is_you && (ublindf || u.ucreamed))
		    return FALSE;
		check_visor = TRUE;
	    } else if (obj && (obj->otyp == POT_BLINDNESS)) {
		return TRUE;	/* no defense */
	    } else
		return FALSE;	/* other objects cannot cause blindness yet */
	    if ((magr == &youmonst) && u.uswallow)
		return FALSE;	/* can't affect eyes while inside monster */
	    break;

	case AT_ENGL:
	    if (is_you && (Blindfolded || u.usleep || u.ucreamed))
		return FALSE;
	    if (!is_you && mdef->msleeping)
		return FALSE;
	    break;

	case AT_CLAW:
	    /* e.g. raven: all ublindf, including LENSES, protect */
	    if (is_you && ublindf)
		return FALSE;
	    if ((magr == &youmonst) && u.uswallow)
		return FALSE;	/* can't affect eyes while inside monster */
	    check_visor = TRUE;
	    break;

	case AT_TUCH: case AT_STNG:
	    /* some physical, blind-inducing attacks can be cancelled */
	    if (magr && magr->mcan)
		return FALSE;
	    break;

	default:
	    break;
	}

	/* check if wearing a visor (only checked if visor might help) */
	if (check_visor) {
	    o = (mdef == &youmonst) ? invent : mdef->minvent;
	    for ( ; o; o = o->nobj)
		if ((o->owornmask & W_ARMH) &&
		    (s = OBJ_DESCR(objects[o->otyp])) != (char *)0 &&
		    !strcmp(s, "visored helmet"))
		    return FALSE;
	}

	return TRUE;
}

#endif /* OVLB */
#ifdef OVL0

ranged_attk

boolean
ranged_attk(ptr)	/* returns TRUE if monster can attack at range */
struct permonst *ptr;
{
	register int i, atyp;
	long atk_mask = (1L << AT_BREA) | (1L << AT_SPIT) | (1L << AT_GAZE);

	/* was: (attacktype(ptr, AT_BREA) || attacktype(ptr, AT_WEAP) ||
		attacktype(ptr, AT_SPIT) || attacktype(ptr, AT_GAZE) ||
		attacktype(ptr, AT_MAGC));
	   but that's too slow -dlc
	 */
	for (i = 0; i < NATTK; i++) {
	    atyp = ptr->mattk[i].aatyp;
	    if (atyp >= AT_WEAP) return TRUE;
	 /* assert(atyp < 32); */
	    if ((atk_mask & (1L << atyp)) != 0L) return TRUE;
	}

	return FALSE;
}

hates_silver

boolean
hates_silver(ptr)
register struct permonst *ptr;
/* returns TRUE if monster is especially affected by silver weapons */
{
	return((boolean)(is_were(ptr) || ptr->mlet==S_VAMPIRE || is_demon(ptr) ||
		ptr == &mons[PM_SHADE] ||
		(ptr->mlet==S_IMP && ptr != &mons[PM_TENGU])));
}

passes_bars

/* true iff the type of monster pass through iron bars */
boolean
passes_bars(mptr)
struct permonst *mptr;
{
return (boolean) (passes_walls(mptr) || amorphous(mptr) ||
		      is_whirly(mptr) || verysmall(mptr) ||
		      (slithy(mptr) && !bigmonst(mptr)));
}

#endif /* OVL0 */
#ifdef OVL1

can_track

boolean
can_track(ptr)		/* returns TRUE if monster can track well */
	register struct permonst *ptr;
{
	if (uwep && uwep->oartifact == ART_EXCALIBUR)
		return TRUE;
	else
		return((boolean)haseyes(ptr));
}

#endif /* OVL1 */
#ifdef OVLB

sliparm

boolean
sliparm(ptr)	/* creature will slide out of armor */
	register struct permonst *ptr;
{
	return((boolean)(is_whirly(ptr) || ptr->msize <= MZ_SMALL ||
			 noncorporeal(ptr)));
}

breakarm

boolean
breakarm(ptr)	/* creature will break out of armor */
	register struct permonst *ptr;
{
	return ((bigmonst(ptr) || (ptr->msize > MZ_SMALL && !humanoid(ptr)) ||
		/* special cases of humanoids that cannot wear body armor */
		ptr == &mons[PM_MARILITH] || ptr == &mons[PM_WINGED_GARGOYLE])
	      && !sliparm(ptr));
}
#endif /* OVLB */
#ifdef OVL1

sticks

boolean
sticks(ptr)	/* creature sticks other creatures it hits */
	register struct permonst *ptr;
{
	return((boolean)(dmgtype(ptr,AD_STCK) || dmgtype(ptr,AD_WRAP) ||
		attacktype(ptr,AT_HUGS)));
}

num_horns

Used for correct pluralization of helm related messages in do_wear.c, worn.c, and polyself.c. There is also a macro, has_horns, defined in mondata.h line 48 ("#define has_horns(ptr) (num_horns(ptr) > 0)").

/* number of horns this type of monster has on its head */
int
num_horns(ptr)
struct permonst *ptr;
{
switch (monsndx(ptr)) {
case PM_HORNED_DEVIL:	/* ? "more than one" */
case PM_MINOTAUR:
case PM_ASMODEUS:
case PM_BALROG:
	return 2;
case PM_WHITE_UNICORN:
case PM_GRAY_UNICORN:
case PM_BLACK_UNICORN:
case PM_KI_RIN:
	return 1;
default:
	break;
}
return 0;
}

dmgtype_fromattack

struct attack *
dmgtype_fromattack(ptr, dtyp, atyp)
struct permonst *ptr;
int dtyp, atyp;
{
struct attack *a;

for (a = &ptr->mattk[0]; a < &ptr->mattk[NATTK]; a++)
	if (a->adtyp == dtyp && (atyp == AT_ANY || a->aatyp == atyp))
	    return a;

return (struct attack *)0;
}

dmgtype

boolean
dmgtype(ptr, dtyp)
struct permonst *ptr;
int dtyp;
{
return dmgtype_fromattack(ptr, dtyp, AT_ANY) ? TRUE : FALSE;
}

max_passive_dmg

/* returns the maximum damage a defender can do to the attacker via
* a passive defense */
int
max_passive_dmg(mdef, magr)
register struct monst *mdef, *magr;
{
int	i, dmg = 0;
uchar adtyp;

for(i = 0; i < NATTK; i++)
	if(mdef->data->mattk[i].aatyp == AT_NONE ||
		mdef->data->mattk[i].aatyp == AT_BOOM) {
	    adtyp = mdef->data->mattk[i].adtyp;
	    if ((adtyp == AD_ACID && !resists_acid(magr)) ||
		    (adtyp == AD_COLD && !resists_cold(magr)) ||
		    (adtyp == AD_FIRE && !resists_fire(magr)) ||
		    (adtyp == AD_ELEC && !resists_elec(magr)) ||
		    adtyp == AD_PHYS) {
		dmg = mdef->data->mattk[i].damn;
		if(!dmg) dmg = mdef->data->mlevel+1;
		dmg *= mdef->data->mattk[i].damd;
	    } else dmg = 0;

	    return dmg;
	}
return 0;
}

#endif /* OVL1 */
#ifdef OVL0

monsndx

int
monsndx(ptr)		/* return an index into the mons array */
	struct	permonst	*ptr;
{
	register int	i;

	i = (int)(ptr - &mons[0]);
	if (i < LOW_PM || i >= NUMMONS) {
		/* ought to switch this to use `fmt_ptr' */
	    panic("monsndx - could not index monster (%lx)",
		  (unsigned long)ptr);
	    return NON_PM;		/* will not get here */
	}

	return(i);
}

#endif /* OVL0 */
#ifdef OVL1

name_to_mon

int
name_to_mon(in_str)
const char *in_str;
{
	/* Be careful.  We must check the entire string in case it was
	 * something such as "ettin zombie corpse".  The calling routine
	 * doesn't know about the "corpse" until the monster name has
	 * already been taken off the front, so we have to be able to
	 * read the name with extraneous stuff such as "corpse" stuck on
	 * the end.
	 * This causes a problem for names which prefix other names such
	 * as "ettin" on "ettin zombie".  In this case we want the _longest_
	 * name which exists.
	 * This also permits plurals created by adding suffixes such as 's'
	 * or 'es'.  Other plurals must still be handled explicitly.
	 */
	register int i;
	register int mntmp = NON_PM;
	register char *s, *str, *term;
	char buf[BUFSZ];
	int len, slen;

	str = strcpy(buf, in_str);

	if (!strncmp(str, "a ", 2)) str += 2;
	else if (!strncmp(str, "an ", 3)) str += 3;

	slen = strlen(str);
	term = str + slen;

	if ((s = strstri(str, "vortices")) != 0)
	    Strcpy(s+4, "ex");
	/* be careful with "ies"; "priest", "zombies" */
	else if (slen > 3 && !strcmpi(term-3, "ies") &&
		    (slen < 7 || strcmpi(term-7, "zombies")))
	    Strcpy(term-3, "y");
	/* luckily no monster names end in fe or ve with ves plurals */
	else if (slen > 3 && !strcmpi(term-3, "ves"))
	    Strcpy(term-3, "f");

	slen = strlen(str); /* length possibly needs recomputing */

{
	static const struct alt_spl { const char* name; short pm_val; }
	    names[] = {
	    /* Alternate spellings */
		{ "grey dragon",	PM_GRAY_DRAGON },
		{ "baby grey dragon",	PM_BABY_GRAY_DRAGON },
		{ "grey unicorn",	PM_GRAY_UNICORN },
		{ "grey ooze",		PM_GRAY_OOZE },
		{ "gray-elf",		PM_GREY_ELF },
	    /* Hyphenated names */
		{ "ki rin",		PM_KI_RIN },
		{ "uruk hai",		PM_URUK_HAI },
		{ "orc captain",	PM_ORC_CAPTAIN },
		{ "woodland elf",	PM_WOODLAND_ELF },
		{ "green elf",		PM_GREEN_ELF },
		{ "grey elf",		PM_GREY_ELF },
		{ "gray elf",		PM_GREY_ELF },
		{ "elf lord",		PM_ELF_LORD },
#if 0	/* OBSOLETE */
		{ "high elf",		PM_HIGH_ELF },
#endif
		{ "olog hai",		PM_OLOG_HAI },
		{ "arch lich",		PM_ARCH_LICH },
	    /* Some irregular plurals */
		{ "incubi",		PM_INCUBUS },
		{ "succubi",		PM_SUCCUBUS },
		{ "violet fungi",	PM_VIOLET_FUNGUS },
		{ "homunculi",		PM_HOMUNCULUS },
		{ "baluchitheria",	PM_BALUCHITHERIUM },
		{ "lurkers above",	PM_LURKER_ABOVE },
		{ "cavemen",		PM_CAVEMAN },
		{ "cavewomen",		PM_CAVEWOMAN },
		{ "djinn",		PM_DJINNI },
		{ "mumakil",		PM_MUMAK },
		{ "erinyes",		PM_ERINYS },
	    /* falsely caught by -ves check above */
		{ "master of thief",	PM_MASTER_OF_THIEVES },
	    /* end of list */
		{ 0, 0 }
	};
	register const struct alt_spl *namep;

	for (namep = names; namep->name; namep++)
	    if (!strncmpi(str, namep->name, (int)strlen(namep->name)))
		return namep->pm_val;
}

	for (len = 0, i = LOW_PM; i < NUMMONS; i++) {
	    register int m_i_len = strlen(mons[i].mname);
	    if (m_i_len > len && !strncmpi(mons[i].mname, str, m_i_len)) {
		if (m_i_len == slen) return i;	/* exact match */
		else if (slen > m_i_len &&
			(str[m_i_len] == ' ' ||
			 !strcmpi(&str[m_i_len], "s") ||
			 !strncmpi(&str[m_i_len], "s ", 2) ||
			 !strcmpi(&str[m_i_len], "'") ||
			 !strncmpi(&str[m_i_len], "' ", 2) ||
			 !strcmpi(&str[m_i_len], "'s") ||
			 !strncmpi(&str[m_i_len], "'s ", 3) ||
			 !strcmpi(&str[m_i_len], "es") ||
			 !strncmpi(&str[m_i_len], "es ", 3))) {
		    mntmp = i;
		    len = m_i_len;
		}
	    }
	}
	if (mntmp == NON_PM) mntmp = title_to_mon(str, (int *)0, (int *)0);
	return mntmp;
}

#endif /* OVL1 */
#ifdef OVL2

gender

/* returns 3 values (0=male, 1=female, 2=none) */
int
gender(mtmp)
register struct monst *mtmp;
{
	if (is_neuter(mtmp->data)) return 2;
	return mtmp->female;
}

pronoun_gender

/* Like gender(), but lower animals and such are still "it". */
/* This is the one we want to use when printing messages. */
int
pronoun_gender(mtmp)
register struct monst *mtmp;
{
	if (is_neuter(mtmp->data) || !canspotmon(mtmp)) return 2;
	return (humanoid(mtmp->data) || (mtmp->data->geno & G_UNIQ) ||
		type_is_pname(mtmp->data)) ? (int)mtmp->female : 2;
}

#endif /* OVL2 */
#ifdef OVLB

levl_follower

/* used for nearby monsters when you go to another level */
boolean
levl_follower(mtmp)
struct monst *mtmp;
{
	/* monsters with the Amulet--even pets--won't follow across levels */
	if (mon_has_amulet(mtmp)) return FALSE;

	/* some monsters will follow even while intending to flee from you */
	if (mtmp->mtame || mtmp->iswiz || is_fshk(mtmp)) return TRUE;

	/* stalking types follow, but won't when fleeing unless you hold
	   the Amulet */
	return (boolean)((mtmp->data->mflags2 & M2_STALK) &&
				(!mtmp->mflee || u.uhave.amulet));
}

grownups-array

static const short grownups[][2] = {
	{PM_CHICKATRICE, PM_COCKATRICE},
	{PM_LITTLE_DOG, PM_DOG}, {PM_DOG, PM_LARGE_DOG},
	{PM_HELL_HOUND_PUP, PM_HELL_HOUND},
	{PM_WINTER_WOLF_CUB, PM_WINTER_WOLF},
	{PM_KITTEN, PM_HOUSECAT}, {PM_HOUSECAT, PM_LARGE_CAT},
	{PM_PONY, PM_HORSE}, {PM_HORSE, PM_WARHORSE},
	{PM_KOBOLD, PM_LARGE_KOBOLD}, {PM_LARGE_KOBOLD, PM_KOBOLD_LORD},
	{PM_GNOME, PM_GNOME_LORD}, {PM_GNOME_LORD, PM_GNOME_KING},
	{PM_DWARF, PM_DWARF_LORD}, {PM_DWARF_LORD, PM_DWARF_KING},
	{PM_MIND_FLAYER, PM_MASTER_MIND_FLAYER},
	{PM_ORC, PM_ORC_CAPTAIN}, {PM_HILL_ORC, PM_ORC_CAPTAIN},
	{PM_MORDOR_ORC, PM_ORC_CAPTAIN}, {PM_URUK_HAI, PM_ORC_CAPTAIN},
	{PM_SEWER_RAT, PM_GIANT_RAT},
	{PM_CAVE_SPIDER, PM_GIANT_SPIDER},
	{PM_OGRE, PM_OGRE_LORD}, {PM_OGRE_LORD, PM_OGRE_KING},
	{PM_ELF, PM_ELF_LORD}, {PM_WOODLAND_ELF, PM_ELF_LORD},
	{PM_GREEN_ELF, PM_ELF_LORD}, {PM_GREY_ELF, PM_ELF_LORD},
	{PM_ELF_LORD, PM_ELVENKING},
	{PM_LICH, PM_DEMILICH}, {PM_DEMILICH, PM_MASTER_LICH},
	{PM_MASTER_LICH, PM_ARCH_LICH},
	{PM_VAMPIRE, PM_VAMPIRE_LORD}, {PM_BAT, PM_GIANT_BAT},
	{PM_BABY_GRAY_DRAGON, PM_GRAY_DRAGON},
	{PM_BABY_SILVER_DRAGON, PM_SILVER_DRAGON},
#if 0	/* DEFERRED */
	{PM_BABY_SHIMMERING_DRAGON, PM_SHIMMERING_DRAGON},
#endif
	{PM_BABY_RED_DRAGON, PM_RED_DRAGON},
	{PM_BABY_WHITE_DRAGON, PM_WHITE_DRAGON},
	{PM_BABY_ORANGE_DRAGON, PM_ORANGE_DRAGON},
	{PM_BABY_BLACK_DRAGON, PM_BLACK_DRAGON},
	{PM_BABY_BLUE_DRAGON, PM_BLUE_DRAGON},
	{PM_BABY_GREEN_DRAGON, PM_GREEN_DRAGON},
	{PM_BABY_YELLOW_DRAGON, PM_YELLOW_DRAGON},
	{PM_RED_NAGA_HATCHLING, PM_RED_NAGA},
	{PM_BLACK_NAGA_HATCHLING, PM_BLACK_NAGA},
	{PM_GOLDEN_NAGA_HATCHLING, PM_GOLDEN_NAGA},
	{PM_GUARDIAN_NAGA_HATCHLING, PM_GUARDIAN_NAGA},
	{PM_SMALL_MIMIC, PM_LARGE_MIMIC}, {PM_LARGE_MIMIC, PM_GIANT_MIMIC},
	{PM_BABY_LONG_WORM, PM_LONG_WORM},
	{PM_BABY_PURPLE_WORM, PM_PURPLE_WORM},
	{PM_BABY_CROCODILE, PM_CROCODILE},
	{PM_SOLDIER, PM_SERGEANT},
	{PM_SERGEANT, PM_LIEUTENANT},
	{PM_LIEUTENANT, PM_CAPTAIN},
	{PM_WATCHMAN, PM_WATCH_CAPTAIN},
	{PM_ALIGNED_PRIEST, PM_HIGH_PRIEST},
	{PM_STUDENT, PM_ARCHEOLOGIST},
	{PM_ATTENDANT, PM_HEALER},
	{PM_PAGE, PM_KNIGHT},
	{PM_ACOLYTE, PM_PRIEST},
	{PM_APPRENTICE, PM_WIZARD},
	{PM_MANES,PM_LEMURE},
#ifdef KOPS
	{PM_KEYSTONE_KOP, PM_KOP_SERGEANT},
	{PM_KOP_SERGEANT, PM_KOP_LIEUTENANT},
	{PM_KOP_LIEUTENANT, PM_KOP_KAPTAIN},
#endif
	{NON_PM,NON_PM}
};

little_to_big

int
little_to_big(montype)
int montype;
{
#ifndef AIXPS2_BUG
	register int i;

	for (i = 0; grownups[i][0] >= LOW_PM; i++)
		if(montype == grownups[i][0]) return grownups[i][1];
	return montype;
#else
/* AIX PS/2 C-compiler 1.1.1 optimizer does not like the above for loop,
* and causes segmentation faults at runtime.  (The problem does not
* occur if -O is not used.)
* lehtonen@cs.Helsinki.FI (Tapio Lehtonen) 28031990
*/
	int i;
	int monvalue;

	monvalue = montype;
	for (i = 0; grownups[i][0] >= LOW_PM; i++)
		if(montype == grownups[i][0]) monvalue = grownups[i][1];

	return monvalue;
#endif
}

big_to_little

int
big_to_little(montype)
int montype;
{
	register int i;

	for (i = 0; grownups[i][0] >= LOW_PM; i++)
		if(montype == grownups[i][1]) return grownups[i][0];
	return montype;
}

raceptr

/*
* Return the permonst ptr for the race of the monster.
* Returns correct pointer for non-polymorphed and polymorphed
* player.  It does not return a pointer to player role character.
*/
const struct permonst *
raceptr(mtmp)
struct monst *mtmp;
{
if (mtmp == &youmonst && !Upolyd) return(&mons[urace.malenum]);
else return(mtmp->data);
}

locomotion

static const char *levitate[4]	= { "float", "Float", "wobble", "Wobble" };
static const char *flys[4]	= { "fly", "Fly", "flutter", "Flutter" };
static const char *flyl[4]	= { "fly", "Fly", "stagger", "Stagger" };
static const char *slither[4]	= { "slither", "Slither", "falter", "Falter" };
static const char *ooze[4]	= { "ooze", "Ooze", "tremble", "Tremble" };
static const char *immobile[4]	= { "wiggle", "Wiggle", "pulsate", "Pulsate" };
static const char *crawl[4]	= { "crawl", "Crawl", "falter", "Falter" };

const char *
locomotion(ptr, def)
const struct permonst *ptr;
const char *def;
{
	int capitalize = (*def == highc(*def));

	return (
		is_floater(ptr) ? levitate[capitalize] :
		(is_flyer(ptr) && ptr->msize <= MZ_SMALL) ? flys[capitalize] :
		(is_flyer(ptr) && ptr->msize > MZ_SMALL)  ? flyl[capitalize] :
		slithy(ptr)     ? slither[capitalize] :
		amorphous(ptr)  ? ooze[capitalize] :
		!ptr->mmove	? immobile[capitalize] :
		nolimbs(ptr)    ? crawl[capitalize] :
		def
	       );

}

stagger

const char *
stagger(ptr, def)
const struct permonst *ptr;
const char *def;
{
	int capitalize = 2 + (*def == highc(*def));

	return (
		is_floater(ptr) ? levitate[capitalize] :
		(is_flyer(ptr) && ptr->msize <= MZ_SMALL) ? flys[capitalize] :
		(is_flyer(ptr) && ptr->msize > MZ_SMALL)  ? flyl[capitalize] :
		slithy(ptr)     ? slither[capitalize] :
		amorphous(ptr)  ? ooze[capitalize] :
		!ptr->mmove	? immobile[capitalize] :
		nolimbs(ptr)    ? crawl[capitalize] :
		def
	       );

}

on_fire

/* return a phrase describing the effect of fire attack on a type of monster */
const char *
on_fire(mptr, mattk)
struct permonst *mptr;
struct attack *mattk;
{
const char *what;

switch (monsndx(mptr)) {
case PM_FLAMING_SPHERE:
case PM_FIRE_VORTEX:
case PM_FIRE_ELEMENTAL:
case PM_SALAMANDER:
	what = "already on fire";
	break;
case PM_WATER_ELEMENTAL:
case PM_FOG_CLOUD:
case PM_STEAM_VORTEX:
	what = "boiling";
	break;
case PM_ICE_VORTEX:
case PM_GLASS_GOLEM:
	what = "melting";
	break;
case PM_STONE_GOLEM:
case PM_CLAY_GOLEM:
case PM_GOLD_GOLEM:
case PM_AIR_ELEMENTAL:
case PM_EARTH_ELEMENTAL:
case PM_DUST_VORTEX:
case PM_ENERGY_VORTEX:
	what = "heating up";
	break;
default:
	what = (mattk->aatyp == AT_HUGS) ? "being roasted" : "on fire";
	break;
}
return what;
}

#endif /* OVLB */

/*mondata.c*/