Clean up some spell-related code

Add two helper functions and use those outside of spell.c,
instead of iterating through all the spells.
This commit is contained in:
Pasi Kallinen
2022-02-20 21:12:23 +02:00
parent 041a07468a
commit 038ae7f984
5 changed files with 42 additions and 44 deletions

View File

@@ -915,7 +915,7 @@ spelleffects(int spell, boolean atme)
* (There's no duplication of messages; when the rejection takes
* place in getspell(), we don't get called.)
*/
if (rejectcasting()) {
if ((spell < 0) || rejectcasting()) {
return ECMD_OK; /* no time elapses */
}
@@ -1923,4 +1923,28 @@ initialspell(struct obj* obj)
return;
}
/* return TRUE if hero knows spell otyp, FALSE otherwise */
boolean
known_spell(short otyp)
{
int i;
for (i = 0; (i < MAXSPELL) && (spellid(i) != NO_SPELL); i++)
if (spellid(i) == otyp)
return TRUE;
return FALSE;
}
/* return index for spell otyp, or -1 if not found */
int
spell_idx(short otyp)
{
int i;
for (i = 0; (i < MAXSPELL) && (spellid(i) != NO_SPELL); i++)
if (spellid(i) == otyp)
return i;
return -1;
}
/*spell.c*/