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

Function resist

src/zap.c:6099–6158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6097}
6098
6099int
6100resist(struct monst *mtmp, char oclass, int damage, int tell)
6101{
6102 int resisted;
6103 int alev, dlev;
6104
6105 /* fake players always pass resistance test against Conflict
6106 (this doesn't guarantee that they're never affected by it) */
6107 if (oclass == RING_CLASS && !damage && !tell && is_mplayer(mtmp->data))
6108 return 1;
6109
6110 /* attack level */
6111 switch (oclass) {
6112 case WAND_CLASS:
6113 alev = 12;
6114 break;
6115 case TOOL_CLASS:
6116 alev = 10;
6117 break; /* instrument */
6118 case WEAPON_CLASS:
6119 alev = 10;
6120 break; /* artifact */
6121 case SCROLL_CLASS:
6122 alev = 9;
6123 break;
6124 case POTION_CLASS:
6125 alev = 6;
6126 break;
6127 case RING_CLASS:
6128 alev = 5;
6129 break;
6130 default:
6131 alev = u.ulevel;
6132 break; /* spell */
6133 }
6134 /* defense level */
6135 dlev = (int) mtmp->m_lev;
6136 if (dlev > 50)
6137 dlev = 50;
6138 else if (dlev < 1)
6139 dlev = is_mplayer(mtmp->data) ? u.ulevel : 1;
6140
6141 resisted = rn2(100 + alev - dlev) < mtmp->data->mr;
6142 if (resisted) {
6143 if (tell)
6144 shieldeff_mon(mtmp);
6145 damage = (damage + 1) / 2;
6146 }
6147
6148 if (damage) {
6149 mtmp->mhp -= damage;
6150 if (DEADMONSTER(mtmp)) {
6151 if (gm.m_using)
6152 monkilled(mtmp, "", AD_RBRE);
6153 else
6154 killed(mtmp);
6155 }
6156 }

Callers 15

potionhitFunction · 0.85
hmon_hitmonFunction · 0.85
Mb_hitFunction · 0.85
mon_polyFunction · 0.85
sleep_monstFunction · 0.85
maybe_turn_mon_iterFunction · 0.85
awaken_scareFunction · 0.85
charm_monstersFunction · 0.85
trapeffect_poly_trapFunction · 0.85
steedintrapFunction · 0.85
bhitmFunction · 0.85
cancel_monstFunction · 0.85

Calls 4

rn2Function · 0.85
shieldeff_monFunction · 0.85
monkilledFunction · 0.85
killedFunction · 0.85

Tested by

no test coverage detected