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

Function percent_success

src/spell.c:2172–2292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2170RESTORE_WARNING_FORMAT_NONLITERAL
2171
2172staticfn int
2173percent_success(int spell)
2174{
2175 /* Intrinsic and learned ability are combined to calculate
2176 * the probability of player's success at casting a given spell.
2177 */
2178 int chance, splcaster, special, statused;
2179 int difficulty;
2180 int skill, skilltype = spell_skilltype(spellid(spell));
2181 /* Knights don't get metal armor penalty for clerical spells */
2182 boolean paladin_bonus = (Role_if(PM_KNIGHT)
2183 && skilltype == P_CLERIC_SPELL);
2184
2185 /* Calculate intrinsic ability (splcaster) */
2186
2187 splcaster = gu.urole.spelbase;
2188 special = gu.urole.spelheal;
2189 statused = ACURR(gu.urole.spelstat);
2190
2191 if (uarm && is_metallic(uarm) && !paladin_bonus)
2192 splcaster += (uarmc && uarmc->otyp == ROBE) ? gu.urole.spelarmr / 2
2193 : gu.urole.spelarmr;
2194 else if (uarmc && uarmc->otyp == ROBE)
2195 splcaster -= gu.urole.spelarmr;
2196 if (uarms)
2197 splcaster += gu.urole.spelshld;
2198
2199 if (uwep && uwep->otyp == QUARTERSTAFF)
2200 splcaster -= 3; /* Small bonus */
2201
2202 if (!paladin_bonus) {
2203 if (uarmh && is_metallic(uarmh)) /* && otyp != HELM_OF_BRILLIANCE */
2204 splcaster += uarmhbon;
2205 if (uarmg && is_metallic(uarmg))
2206 splcaster += uarmgbon;
2207 if (uarmf && is_metallic(uarmf))
2208 splcaster += uarmfbon;
2209 }
2210
2211 if (spellid(spell) == gu.urole.spelspec)
2212 splcaster += gu.urole.spelsbon;
2213
2214 /* `healing spell' bonus */
2215 if (spellid(spell) == SPE_HEALING || spellid(spell) == SPE_EXTRA_HEALING
2216 || spellid(spell) == SPE_CURE_BLINDNESS
2217 || spellid(spell) == SPE_CURE_SICKNESS
2218 || spellid(spell) == SPE_RESTORE_ABILITY
2219 || spellid(spell) == SPE_REMOVE_CURSE)
2220 splcaster += special;
2221
2222 if (splcaster > 20)
2223 splcaster = 20;
2224
2225 /* Calculate learned ability */
2226
2227 /* The player's basic likelihood of being able to cast any spell
2228 * is based of their `magic' statistic. (Int or Wis)
2229 */

Callers 2

spelleffects_checkFunction · 0.85
dospellmenuFunction · 0.85

Calls 3

spell_skilltypeFunction · 0.85
isqrtFunction · 0.85
weightFunction · 0.85

Tested by

no test coverage detected