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

Function spellretention

src/spell.c:2294–2336  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2292}
2293
2294staticfn char *
2295spellretention(int idx, char * outbuf)
2296{
2297 long turnsleft, percent, accuracy;
2298 int skill;
2299
2300 skill = P_SKILL(spell_skilltype(spellid(idx)));
2301 skill = max(skill, P_UNSKILLED); /* restricted same as unskilled */
2302 turnsleft = spellknow(idx);
2303 *outbuf = '\0'; /* lint suppression */
2304
2305 if (turnsleft < 1L) {
2306 /* spell has expired; hero can't successfully cast it anymore */
2307 Strcpy(outbuf, "(gone)");
2308 } else if (turnsleft >= (long) KEEN) {
2309 /* full retention, first turn or immediately after reading book */
2310 Strcpy(outbuf, "100%");
2311 } else {
2312 /*
2313 * Retention is displayed as a range of percentages of
2314 * amount of time left until memory of the spell expires;
2315 * the precision of the range depends upon hero's skill
2316 * in this spell.
2317 * expert: 2% intervals; 1-2, 3-4, ..., 99-100;
2318 * skilled: 5% intervals; 1-5, 6-10, ..., 95-100;
2319 * basic: 10% intervals; 1-10, 11-20, ..., 91-100;
2320 * unskilled: 25% intervals; 1-25, 26-50, 51-75, 76-100.
2321 *
2322 * At the low end of each range, a value of N% really means
2323 * (N-1)%+1 through N%; so 1% is "greater than 0, at most 200".
2324 * KEEN is a multiple of 100; KEEN/100 loses no precision.
2325 */
2326 percent = (turnsleft - 1L) / ((long) KEEN / 100L) + 1L;
2327 accuracy = (skill == P_EXPERT) ? 2L
2328 : (skill == P_SKILLED) ? 5L
2329 : (skill == P_BASIC) ? 10L
2330 : 25L;
2331 /* round up to the high end of this range */
2332 percent = accuracy * ((percent - 1L) / accuracy + 1L);
2333 Sprintf(outbuf, "%ld%%-%ld%%", percent - accuracy + 1L, percent);
2334 }
2335 return outbuf;
2336}
2337
2338/* Learn a spell during creation of the initial inventory */
2339void

Callers 1

dospellmenuFunction · 0.85

Calls 1

spell_skilltypeFunction · 0.85

Tested by

no test coverage detected