decide whether an artifact's special attacks apply against mtmp */
| 1006 | |
| 1007 | /* decide whether an artifact's special attacks apply against mtmp */ |
| 1008 | staticfn int |
| 1009 | spec_applies(const struct artifact *weap, struct monst *mtmp) |
| 1010 | { |
| 1011 | struct permonst *ptr; |
| 1012 | boolean yours; |
| 1013 | |
| 1014 | if (!(weap->spfx & (SPFX_DBONUS | SPFX_ATTK))) |
| 1015 | return (weap->attk.adtyp == AD_PHYS); |
| 1016 | |
| 1017 | yours = (mtmp == &gy.youmonst); |
| 1018 | ptr = mtmp->data; |
| 1019 | |
| 1020 | if (weap->spfx & SPFX_DMONS) { |
| 1021 | return (ptr == &mons[(int) weap->mtype]); |
| 1022 | } else if (weap->spfx & SPFX_DCLAS) { |
| 1023 | return (weap->mtype == (unsigned long) ptr->mlet); |
| 1024 | } else if (weap->spfx & SPFX_DFLAG1) { |
| 1025 | return ((ptr->mflags1 & weap->mtype) != 0L); |
| 1026 | } else if (weap->spfx & SPFX_DFLAG2) { |
| 1027 | return ((ptr->mflags2 & weap->mtype) |
| 1028 | || (yours |
| 1029 | && ((!Upolyd && (gu.urace.selfmask & weap->mtype)) |
| 1030 | || ((weap->mtype & M2_WERE) && ismnum(u.ulycn))))); |
| 1031 | } else if (weap->spfx & SPFX_DALIGN) { |
| 1032 | return yours ? (u.ualign.type != weap->alignment) |
| 1033 | : (ptr->maligntyp == A_NONE |
| 1034 | || sgn(ptr->maligntyp) != weap->alignment); |
| 1035 | } else if (weap->spfx & SPFX_ATTK) { |
| 1036 | if (defended(mtmp, (int) weap->attk.adtyp)) |
| 1037 | return FALSE; |
| 1038 | |
| 1039 | switch (weap->attk.adtyp) { |
| 1040 | case AD_FIRE: |
| 1041 | return !(yours ? Fire_resistance : resists_fire(mtmp)); |
| 1042 | case AD_COLD: |
| 1043 | return !(yours ? Cold_resistance : resists_cold(mtmp)); |
| 1044 | case AD_ELEC: |
| 1045 | return !(yours ? Shock_resistance : resists_elec(mtmp)); |
| 1046 | case AD_MAGM: |
| 1047 | case AD_STUN: |
| 1048 | return !(yours ? Antimagic : (rn2(100) < ptr->mr)); |
| 1049 | case AD_DRST: |
| 1050 | return !(yours ? Poison_resistance : resists_poison(mtmp)); |
| 1051 | case AD_DRLI: |
| 1052 | return !(yours ? Drain_resistance : resists_drli(mtmp)); |
| 1053 | case AD_STON: |
| 1054 | return !(yours ? Stone_resistance : resists_ston(mtmp)); |
| 1055 | default: |
| 1056 | impossible("Weird weapon special attack."); |
| 1057 | } |
| 1058 | } |
| 1059 | return 0; |
| 1060 | } |
| 1061 | |
| 1062 | /* return the M2 flags of monster that an artifact's special attacks apply |
| 1063 | * against */ |
no test coverage detected