summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/monplace.cc
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source/monplace.cc')
-rw-r--r--crawl-ref/source/monplace.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/crawl-ref/source/monplace.cc b/crawl-ref/source/monplace.cc
index 8032d753c9..4fd5585a5c 100644
--- a/crawl-ref/source/monplace.cc
+++ b/crawl-ref/source/monplace.cc
@@ -2427,6 +2427,32 @@ int create_monster(mgen_data mg, bool fail_msg)
|| !mons_class_can_pass(montype, grd(mg.pos)))
{
mg.pos = find_newmons_square(montype, mg.pos);
+ // Gods other than Xom will try to avoid placing their monsters
+ // directly in harm's way.
+ if (mg.god != GOD_NO_GOD && mg.god != GOD_XOM)
+ {
+ monsters dummy;
+ dummy.type = mg.cls;
+ dummy.base_monster = mg.base_type;
+ dummy.god = mg.god;
+
+ int tries = 0;
+ while (tries++ < 50
+ && mons_avoids_cloud(&dummy, env.cgrid(mg.pos), NULL, true))
+ {
+ mg.pos = find_newmons_square(montype, mg.pos);
+ }
+ const int cloud_num = env.cgrid(mg.pos);
+ // Don't place friendly god gift in a damaging cloud created by
+ // you if that would anger the god.
+ if (mons_avoids_cloud(&dummy, cloud_num, NULL, true)
+ && mg.behaviour == BEH_FRIENDLY
+ && god_hates_attacking_friend(you.religion, &dummy)
+ && YOU_KILL(env.cloud[cloud_num].killer))
+ {
+ return (-1);
+ }
+ }
}
if (in_bounds(mg.pos))