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

Function defended

src/mondata.c:90–124  ·  view source on GitHub ↗

is 'mon' (possibly youmonst) protected against damage type 'adtype' via wielded weapon or worn dragon scales? [or by virtue of being a dragon?] */

Source from the content-addressed store, hash-verified

88/* is 'mon' (possibly youmonst) protected against damage type 'adtype' via
89 wielded weapon or worn dragon scales? [or by virtue of being a dragon?] */
90boolean
91defended(struct monst *mon, int adtyp)
92{
93 struct obj *o, otemp;
94 int mndx;
95 boolean is_you = (mon == &gy.youmonst);
96
97 /* is 'mon' wielding an artifact that protects against 'adtyp'? */
98 o = is_you ? uwep : MON_WEP(mon);
99 if (o && o->oartifact && defends(adtyp, o))
100 return TRUE;
101
102 /* if 'mon' is an adult dragon, treat it as if it was wearing scales
103 so that it has the same benefit as a hero wearing dragon scales */
104 mndx = monsndx(mon->data);
105 if (mndx >= PM_GRAY_DRAGON && mndx <= PM_YELLOW_DRAGON) {
106 /* a dragon is its own suit... if mon is poly'd hero, we don't
107 care about embedded scales (uskin) because being a dragon with
108 embedded scales is no better than just being a dragon */
109 otemp = cg.zeroobj;
110 otemp.oclass = ARMOR_CLASS;
111 otemp.otyp = GRAY_DRAGON_SCALES + (mndx - PM_GRAY_DRAGON);
112 /* defends() and Is_dragon_armor() only care about otyp so ignore
113 the rest of otemp's fields */
114 o = &otemp;
115 } else {
116 /* ordinary case: not an adult dragon */
117 o = is_you ? uarm : which_armor(mon, W_ARM);
118 }
119 /* is 'mon' wearing dragon scales that protect against 'adtyp'? */
120 if (o && Is_dragon_armor(o) && defends(adtyp, o))
121 return TRUE;
122
123 return FALSE;
124}
125
126/* returns True if monster resists particular elemental damage;
127 handles 'carry' effects of artifacts as well as worn/wielded items */

Callers 15

resists_drliFunction · 0.85
mhitm_ad_drliFunction · 0.85
mhitm_ad_fireFunction · 0.85
mhitm_ad_coldFunction · 0.85
mhitm_ad_elecFunction · 0.85
mhitm_ad_acidFunction · 0.85
mhitm_ad_slowFunction · 0.85
mhitm_ad_diseFunction · 0.85
spec_appliesFunction · 0.85
sleep_monstFunction · 0.85
m_harmless_trapFunction · 0.85
zhitmFunction · 0.85

Calls 2

defendsFunction · 0.85
which_armorFunction · 0.85

Tested by

no test coverage detected