is 'mon' (possibly youmonst) protected against damage type 'adtype' via wielded weapon or worn dragon scales? [or by virtue of being a dragon?] */
| 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?] */ |
| 90 | boolean |
| 91 | defended(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 */ |
no test coverage detected