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

Function Resists_Elem

src/mondata.c:128–197  ·  view source on GitHub ↗

returns True if monster resists particular elemental damage; handles 'carry' effects of artifacts as well as worn/wielded items */

Source from the content-addressed store, hash-verified

126/* returns True if monster resists particular elemental damage;
127 handles 'carry' effects of artifacts as well as worn/wielded items */
128boolean
129Resists_Elem(struct monst *mon, int propindx)
130{
131 struct obj *o;
132 long slotmask;
133 boolean is_you = (mon == &gy.youmonst);
134 int u_resist = 0, damgtype = 0, rsstmask = 0;
135
136 /*
137 * Main damage/resistance types, mostly matching dragon breath values.
138 * propindx = property index, fire (1), cold, (2) through stone (8);
139 * damgtype = damage type, 2 through 9 (0 and 1 aren't used here);
140 * rsstmask = resistance mask, 1, 2, 4, ..., 64, 128.
141 */
142
143 switch (propindx) {
144 case FIRE_RES: /* 1 */
145 case COLD_RES: /* 2 */
146 case SLEEP_RES: /* 3 */
147 case DISINT_RES: /* 4 */
148 case SHOCK_RES: /* 5 */
149 case POISON_RES: /* 6 */
150 case ACID_RES: /* 7 */
151 case STONE_RES: /* 8 */
152 damgtype = propindx + 1; /* valid for propindx 1..8, damgtype 2..9 */
153 rsstmask = 1 << (propindx - 1); /* valid for propindx 1..8 */
154 u_resist = u.uprops[propindx].intrinsic
155 || u.uprops[propindx].extrinsic;
156 break;
157
158 /* accept these, but we expect callers to use their routines directly */
159 case ANTIMAGIC:
160 return resists_magm(mon);
161 case DRAIN_RES:
162 return resists_drli(mon);
163 case BLND_RES:
164 return resists_blnd(mon);
165
166 default:
167 impossible("Resists_Elem(%d), unexpected property type", propindx);
168 return FALSE;
169 }
170
171 if (is_you ? u_resist : ((mon_resistancebits(mon) & rsstmask) != 0))
172 return TRUE;
173 /* check for resistance granted by wielded weapon */
174 o = is_you ? uwep : MON_WEP(mon);
175 if (o && o->oartifact && defends(damgtype, o))
176 return TRUE;
177 /* check for resistance granted by worn or carried items */
178 o = is_you ? gi.invent : mon->minvent;
179 slotmask = W_ARMOR | W_ACCESSORY;
180 if (!is_you /* assumes monsters don't wield non-weapons */
181 || (uwep && (uwep->oclass == WEAPON_CLASS || is_weptool(uwep))))
182 slotmask |= W_WEP;
183 if (is_you && u.twoweap)
184 slotmask |= W_SWAPWEP;
185 for (; o; o = o->nobj)

Callers

nothing calls this directly

Calls 6

resists_magmFunction · 0.85
resists_drliFunction · 0.85
resists_blndFunction · 0.85
defendsFunction · 0.85
defends_when_carriedFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected