summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/mon-cast.cc
diff options
context:
space:
mode:
authorCharles Otto <ottochar@gmail.com>2009-11-06 00:15:09 -0500
committerCharles Otto <ottochar@gmail.com>2009-11-06 00:15:50 -0500
commit8c0f2ef1e0ca14dfbe4dc5263ce9d1dddd674758 (patch)
tree0ce03d9fbc4370b46372c0cb25ff0e33d21712c7 /crawl-ref/source/mon-cast.cc
parent2cd18cf91603ca59471842721b584b8a7521f103 (diff)
downloadcrawl-ref-8c0f2ef1e0ca14dfbe4dc5263ce9d1dddd674758.tar.gz
crawl-ref-8c0f2ef1e0ca14dfbe4dc5263ce9d1dddd674758.zip
Add haste other as a monster spell
Diffstat (limited to 'crawl-ref/source/mon-cast.cc')
-rw-r--r--crawl-ref/source/mon-cast.cc52
1 files changed, 52 insertions, 0 deletions
diff --git a/crawl-ref/source/mon-cast.cc b/crawl-ref/source/mon-cast.cc
index cd1ae62f50..1a7e53ee76 100644
--- a/crawl-ref/source/mon-cast.cc
+++ b/crawl-ref/source/mon-cast.cc
@@ -87,6 +87,45 @@ static spell_type _draco_type_to_breath(int drac_type)
return (SPELL_DRACONIAN_BREATH);
}
+// Find an allied monster to cast a beneficial beam spell at.
+// Only used for haste other at the moment.
+static bool _set_allied_target(monsters * caster, bolt & pbolt)
+{
+ monsters * selected_target = NULL;
+ int min_distance = INT_MAX;
+
+ monster_type caster_genus = mons_genus(caster->type);
+
+ for (int i = 0; i < MAX_MONSTERS; i++)
+ {
+ monsters * targ = &menv[i];
+ if (i != caster->mindex()
+ && targ->alive()
+ && caster->can_see(targ)
+ && mons_genus(targ->type) == caster_genus
+ && targ->attitude == caster->attitude
+ && !targ->has_ench(ENCH_CHARM)
+ && !targ->has_ench(ENCH_HASTE))
+ {
+ int targ_distance = grid_distance(targ->pos(), caster->pos());
+ if (targ_distance < min_distance && targ_distance < pbolt.range)
+ {
+ min_distance = targ_distance;
+ selected_target = targ;
+ }
+ }
+ }
+
+ if (selected_target)
+ {
+ pbolt.target = selected_target->pos();
+ return (true);
+ }
+
+ // Didn't find a target
+ return (false);
+}
+
bolt mons_spells( monsters *mons, spell_type spell_cast, int power )
{
ASSERT(power > 0);
@@ -172,6 +211,11 @@ bolt mons_spells( monsters *mons, spell_type spell_cast, int power )
beam.is_beam = true;
break;
+ case SPELL_HASTE_OTHER:
+ beam.flavour = BEAM_HASTE;
+ beam.is_beam = true;
+ break;
+
case SPELL_HASTE: // (self)
beam.flavour = BEAM_HASTE;
break;
@@ -1055,6 +1099,14 @@ bool handle_mon_spell(monsters *monster, bolt &beem)
// Setup the spell.
setup_mons_cast(monster, beem, spell_cast);
+ // Try to find a nearby ally to haste
+ if (spell_cast == SPELL_HASTE_OTHER
+ && !_set_allied_target(monster, beem))
+ {
+ spell_cast = SPELL_NO_SPELL;
+ continue;
+ }
+
// beam-type spells requiring tracers
if (spell_needs_tracer(spell_cast))
{