summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJude Brown <bookofjude@users.sourceforge.net>2009-12-28 11:01:51 +1000
committerJude Brown <bookofjude@users.sourceforge.net>2009-12-28 13:55:53 +1000
commit3c1f575a5c99c03e72a30fe3d8ac91a7248c144e (patch)
tree0215c0a30c1f8b481ba7d4c8b47abcbd56ea8402
parent719f1284e8de636334894a366507e32d6a36f7f5 (diff)
downloadcrawl-ref-3c1f575a5c99c03e72a30fe3d8ac91a7248c144e.tar.gz
crawl-ref-3c1f575a5c99c03e72a30fe3d8ac91a7248c144e.zip
Move and tweak Mislead code.
Newly placed monsters during the mislead status are also given a mislead_as monster type.
-rw-r--r--crawl-ref/source/makefile.obj1
-rw-r--r--crawl-ref/source/mislead.cc127
-rw-r--r--crawl-ref/source/mislead.h8
-rw-r--r--crawl-ref/source/mon-cast.cc103
-rw-r--r--crawl-ref/source/mon-place.cc4
5 files changed, 141 insertions, 102 deletions
diff --git a/crawl-ref/source/makefile.obj b/crawl-ref/source/makefile.obj
index 926b9d5e50..1b1d038f31 100644
--- a/crawl-ref/source/makefile.obj
+++ b/crawl-ref/source/makefile.obj
@@ -102,6 +102,7 @@ menu.o \
message.o \
mgen_data.o \
misc.o \
+mislead.o \
mon-abil.o \
mon-act.o \
mon-behv.o \
diff --git a/crawl-ref/source/mislead.cc b/crawl-ref/source/mislead.cc
new file mode 100644
index 0000000000..64c574d97a
--- /dev/null
+++ b/crawl-ref/source/mislead.cc
@@ -0,0 +1,127 @@
+/* File: mislead.cc
+ * Summary: Handling of the Mislead spell and stats
+ */
+
+#include "AppHdr.h"
+#include "mislead.h"
+
+#include "enum.h"
+#include "env.h"
+#include "message.h"
+#include "monster.h"
+#include "mon-iter.h"
+#include "mon-util.h"
+#include "view.h"
+#include "random.h"
+#include "tutorial.h"
+#include "xom.h"
+
+bool unsuitable_misled_monster(monster_type mons)
+{
+ return (mons_is_unique(mons) || mons_is_mimic(mons)
+ || mons_class_is_stationary(mons) || mons_genus(mons) == MONS_DRACONIAN
+ || mons == MONS_DANCING_WEAPON || mons == MONS_UGLY_THING
+ || mons == MONS_VERY_UGLY_THING || mons == MONS_ZOMBIE_SMALL
+ || mons == MONS_ZOMBIE_LARGE || mons == MONS_SKELETON_SMALL
+ || mons == MONS_SKELETON_LARGE || mons == MONS_SIMULACRUM_SMALL
+ || mons == MONS_SIMULACRUM_LARGE || mons == MONS_SPECTRAL_THING
+ || mons == MONS_SLIME_CREATURE || mons == MONS_BALLISTOMYCETE
+ || mons == MONS_HYDRA || mons == MONS_PLAYER_GHOST
+ || mons == MONS_SHAPESHIFTER || mons == MONS_PANDEMONIUM_DEMON
+ || mons == MONS_KILLER_KLOWN || mons == MONS_KRAKEN
+ || mons == MONS_KRAKEN_TENTACLE
+ || mons == MONS_GLOWING_SHAPESHIFTER
+ || mons == MONS_GIANT_BAT);
+}
+
+monster_type get_misled_monster (monsters *monster)
+{
+ monster_type mons = random_monster_at_grid(monster->pos());
+ if (unsuitable_misled_monster(mons))
+ mons = random_monster_at_grid(monster->pos());
+
+ if (unsuitable_misled_monster(mons))
+ return (MONS_GIANT_BAT);
+
+ return mons;
+}
+
+bool update_mislead_monster(monsters* monster)
+{
+ // Don't affect uniques, named monsters, and monsters with special tiles.
+ if (mons_is_unique(monster->type) || !monster->mname.empty()
+ || monster->props.exists("monster_tile")
+ || monster->props.exists("mislead_as"))
+ {
+ return (false);
+ }
+
+ short misled_as = get_misled_monster(monster);
+ monster->props["mislead_as"] = misled_as;
+
+ if (misled_as == MONS_GIANT_BAT)
+ return (false);
+
+ return (true);
+}
+
+int update_mislead_monsters(monsters* caster)
+{
+ int count = 0;
+
+ for (monster_iterator mi; mi; ++mi)
+ if (*mi != caster && update_mislead_monster(*mi))
+ count++;
+
+ return count;
+}
+
+void mons_cast_mislead(monsters *monster)
+{
+ // This really only affects the player; it causes confusion when cast on
+ // non-player foes, but that is dealt with inside ye-great-Switch-of-Doom.
+ if (monster->foe != MHITYOU)
+ return;
+
+ // Prevents Mislead spam by Mara and co. {due}
+ if (you.duration[DUR_MISLED] > 10 && one_chance_in(3))
+ return;
+
+ if (wearing_amulet(AMU_CLARITY))
+ {
+ mpr("Your vision blurs momentarily.");
+ return;
+ }
+
+ update_mislead_monsters(monster);
+
+ const int old_value = you.duration[DUR_MISLED];
+ you.increase_duration(DUR_MISLED, monster->hit_dice * 12 / 3, 50);
+ if (you.duration[DUR_MISLED] > old_value)
+ {
+ you.check_awaken(500);
+
+ if (old_value <= 0)
+ {
+ mpr("But for a moment, strange images dance in front of your eyes.", MSGCH_WARN);
+#ifdef USE_TILE
+ tiles.add_overlay(you.pos(), tileidx_zap(MAGENTA));
+ update_screen();
+#else
+ flash_view(MAGENTA);
+#endif
+ more();
+ }
+ else
+ mpr("You are even more misled!", MSGCH_WARN);
+
+ learned_something_new(TUT_YOU_ENCHANTED);
+
+ xom_is_stimulated((you.duration[DUR_MISLED] - old_value)
+ / BASELINE_DELAY);
+ }
+
+ return;
+}
+
+
diff --git a/crawl-ref/source/mislead.h b/crawl-ref/source/mislead.h
new file mode 100644
index 0000000000..540ffea9b1
--- /dev/null
+++ b/crawl-ref/source/mislead.h
@@ -0,0 +1,8 @@
+/* File: mislead.h
+ * Summary: Handling of the Mislead spell and stats
+ */
+
+bool unsuitable_misled_monster(monster_type mons);
+monster_type get_misled_monster (monsters *monster);
+int update_mislead_monsters(monsters* caster);
+bool update_mislead_monster(monsters* monster);
diff --git a/crawl-ref/source/mon-cast.cc b/crawl-ref/source/mon-cast.cc
index 761521f7ab..7bbbd77862 100644
--- a/crawl-ref/source/mon-cast.cc
+++ b/crawl-ref/source/mon-cast.cc
@@ -24,6 +24,7 @@
#include "mon-place.h"
#include "terrain.h"
#include "tutorial.h"
+#include "mislead.h"
#include "mgen_data.h"
#include "coord.h"
#include "mon-speak.h"
@@ -1564,108 +1565,6 @@ int _count_mara_fakes()
return count;
}
-bool _unsuitable_misled_monster(monster_type mons)
-{
- return (mons_is_unique(mons) || mons_is_mimic(mons)
- || mons_class_is_stationary(mons) || mons_genus(mons) == MONS_DRACONIAN
- || mons == MONS_DANCING_WEAPON || mons == MONS_UGLY_THING
- || mons == MONS_VERY_UGLY_THING || mons == MONS_ZOMBIE_SMALL
- || mons == MONS_ZOMBIE_LARGE || mons == MONS_SKELETON_SMALL
- || mons == MONS_SKELETON_LARGE || mons == MONS_SIMULACRUM_SMALL
- || mons == MONS_SIMULACRUM_LARGE || mons == MONS_SPECTRAL_THING
- || mons == MONS_SLIME_CREATURE || mons == MONS_BALLISTOMYCETE
- || mons == MONS_HYDRA || mons == MONS_PLAYER_GHOST
- || mons == MONS_SHAPESHIFTER || mons == MONS_PANDEMONIUM_DEMON
- || mons == MONS_KILLER_KLOWN || mons == MONS_KRAKEN
- || mons == MONS_KRAKEN_TENTACLE
- || mons == MONS_GLOWING_SHAPESHIFTER);
-}
-
-monster_type _get_misled_monster (monsters *monster)
-{
- monster_type mons = random_monster_at_grid(monster->pos());
- if (_unsuitable_misled_monster(mons))
- mons = random_monster_at_grid(monster->pos());
-
- if (_unsuitable_misled_monster(mons))
- return (MONS_GIANT_BAT);
-
- return mons;
-}
-
-int _update_mislead_monsters(monsters* monster)
-{
- int count = 0;
-
- for (monster_iterator mi; mi; ++mi)
- {
- if (*mi == monster)
- continue;
-
- // Don't affect uniques, named monsters, and monsters with special tiles.
- if (mons_is_unique(mi->type) || !mi->mname.empty()
- || mi->props.exists("monster_tile") || mi->props.exists("mislead_as"))
- {
- continue;
- }
- else
- {
- mi->props["mislead_as"] = short(_get_misled_monster(*mi));
- count++;
- }
- }
-
- return count;
-}
-
-void mons_cast_mislead(monsters *monster)
-{
- // This really only affects the player; it causes confusion when cast on
- // non-player foes, but that is dealt with inside ye-great-Switch-of-Doom.
- if (monster->foe != MHITYOU)
- return;
-
- // Prevents Mislead spam by Mara and co. {due}
- if (you.duration[DUR_MISLED] > 10 && one_chance_in(3))
- return;
-
- if (wearing_amulet(AMU_CLARITY))
- {
- mpr("Your vision blurs momentarily.");
- return;
- }
-
- _update_mislead_monsters(monster);
-
- const int old_value = you.duration[DUR_MISLED];
- you.increase_duration(DUR_MISLED, monster->hit_dice * 12 / 3, 50);
- if (you.duration[DUR_MISLED] > old_value)
- {
- you.check_awaken(500);
-
- if (old_value <= 0)
- {
- mpr("But for a moment, strange images dance in front of your eyes.", MSGCH_WARN);
-#ifdef USE_TILE
- tiles.add_overlay(you.pos(), tileidx_zap(MAGENTA));
- update_screen();
-#else
- flash_view(MAGENTA);
-#endif
- more();
- }
- else
- mpr("You are even more misled!", MSGCH_WARN);
-
- learned_something_new(TUT_YOU_ENCHANTED);
-
- xom_is_stimulated((you.duration[DUR_MISLED] - old_value)
- / BASELINE_DELAY);
- }
-
- return;
-}
-
bool _find_players_ghost ()
{
bool found = false;
diff --git a/crawl-ref/source/mon-place.cc b/crawl-ref/source/mon-place.cc
index 9faa371cb8..3a88d27774 100644
--- a/crawl-ref/source/mon-place.cc
+++ b/crawl-ref/source/mon-place.cc
@@ -24,6 +24,7 @@
#include "lev-pand.h"
#include "makeitem.h"
#include "message.h"
+#include "mislead.h"
#include "mon-behv.h"
#include "mon-gear.h"
#include "mon-iter.h"
@@ -1242,6 +1243,9 @@ static int _place_monster_aux(const mgen_data &mg,
mon->add_ench(ENCH_SLOWLY_DYING);
}
+ if (!crawl_state.arena && you.misled())
+ update_mislead_monster(mon);
+
if (monster_can_submerge(mon, grd(fpos)) && !one_chance_in(5))
mon->add_ench(ENCH_SUBMERGED);