Skip to content

Commit

Permalink
fix: A check for monsters having ranged spells
Browse files Browse the repository at this point in the history
The function mons_has_ranged_spell() didn't considered spells marked as
ranged by _ms_ranged_spell() to actually be ranged unless their range
was greater than 1. The problem with this is that many LOS-affecting
spells have an undefined range, which gets resolved to a range of -1.
Hence a monster like a curse toe with e.g. Symbol of Torment and only
summons as its other spells was incorrectly not flagged as ranged. This
commit only excludes attack spells if their range is exactly 1.  I've
looked over all calls to mons_has_ranged_spell() and there's nothing
that should break if we expand the list of monster ranged spells in this
way.

It might be good to actually designate a LOS range for all the various
smite targeted attack spells for clarity in the monster info UI. Smiting
itself already has such a range, for example. I'm not changing any spell
definitions for now, since I've not checked if those changes could
somehow have other side effects. Monster AI is notorious for having
subtle bugs.

(cherry picked from commit 585c54f536188b0a9123da2be5ea99197ebdd732)
  • Loading branch information
gammafunk committed Aug 17, 2024
1 parent f3f7718 commit 8b4f558
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions crawl-ref/source/mon-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3857,7 +3857,6 @@ static bool _ms_ranged_spell(spell_type monspell, bool attack_only = false,
case SPELL_NO_SPELL:
case SPELL_CANTRIP:
case SPELL_BLINK_CLOSE:
case SPELL_VAMPIRIC_DRAINING:
return false;

default:
Expand Down Expand Up @@ -3886,7 +3885,8 @@ bool mons_has_ranged_spell(const monster& mon, bool attack_only,
if (slot.spell == SPELL_CREATE_TENTACLES)
return true;
if (_ms_ranged_spell(slot.spell, attack_only, ench_too)
&& mons_spell_range(mon, slot.spell) > 1)
// Assume ranged spells with no defined range are always effective.
&& mons_spell_range(mon, slot.spell) != 1)
{
return true;
}
Expand Down

0 comments on commit 8b4f558

Please sign in to comment.