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

Function spelleffects_check

src/spell.c:1219–1380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1217}
1218
1219staticfn boolean
1220spelleffects_check(int spell, int *res, int *energy)
1221{
1222 int chance;
1223 boolean confused = (Confusion != 0);
1224
1225 *energy = 0;
1226
1227 /*
1228 * Reject attempting to cast while stunned or with no free hands.
1229 * Already done in getspell() to stop casting before choosing
1230 * which spell, but duplicated here for cases where spelleffects()
1231 * gets called directly for ^T without intrinsic teleport capability
1232 * or #turn for non-priest/non-knight.
1233 * (There's no duplication of messages; when the rejection takes
1234 * place in getspell(), we don't get called.)
1235 */
1236 if ((spell == UNKNOWN_SPELL) || rejectcasting()) {
1237 *res = ECMD_OK; /* no time elapses */
1238 return TRUE;
1239 }
1240
1241 /*
1242 * Note: dotele() also calculates energy use and checks nutrition
1243 * and strength requirements; if any of these change, update it too.
1244 */
1245 *energy = SPELL_LEV_PW(spellev(spell)); /* 5 <= energy <= 35 */
1246
1247 /*
1248 * Spell casting no longer affects knowledge of the spell. A
1249 * decrement of spell knowledge is done every turn.
1250 */
1251 if (spellknow(spell) <= 0) {
1252 Your("knowledge of this spell is twisted.");
1253 pline("It invokes nightmarish images in your mind...");
1254 spell_backfire(spell);
1255 u.uen -= rnd(*energy);
1256 if (u.uen < 0)
1257 u.uen = 0;
1258 disp.botl = TRUE;
1259 *res = ECMD_TIME;
1260 return TRUE;
1261 } else if (spellknow(spell) <= KEEN / 200) { /* 100 turns left */
1262 You("strain to recall the spell.");
1263 } else if (spellknow(spell) <= KEEN / 40) { /* 500 turns left */
1264 You("have difficulty remembering the spell.");
1265 } else if (spellknow(spell) <= KEEN / 20) { /* 1000 turns left */
1266 Your("knowledge of this spell is growing faint.");
1267 } else if (spellknow(spell) <= KEEN / 10) { /* 2000 turns left */
1268 Your("recall of this spell is gradually fading.");
1269 }
1270
1271 if (u.uhunger <= 10 && spellid(spell) != SPE_DETECT_FOOD) {
1272 You("are too hungry to cast that spell.");
1273 *res = ECMD_OK;
1274 return TRUE;
1275 } else if (ACURR(A_STR) < 4 && spellid(spell) != SPE_RESTORE_ABILITY) {
1276 You("lack the strength to cast spells.");

Callers 1

spelleffectsFunction · 0.85

Calls 11

rejectcastingFunction · 0.85
YourFunction · 0.85
spell_backfireFunction · 0.85
rndFunction · 0.85
YouFunction · 0.85
check_capacityFunction · 0.85
You_feelFunction · 0.85
acurrFunction · 0.85
morehungryFunction · 0.85
percent_successFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected