summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/spl-transloc.cc
diff options
context:
space:
mode:
authorNeil Moore <neil@s-z.org>2013-08-16 15:08:26 -0400
committerNeil Moore <neil@s-z.org>2013-08-16 15:08:26 -0400
commit38ee6f98f508e7a18896ab19f563fa143fff28a1 (patch)
tree120b2f832e917df1c003b03f9ceb734f91092fbd /crawl-ref/source/spl-transloc.cc
parent07f05f3c36333c1bf44e05d5e49b2051d7a77e0c (diff)
downloadcrawl-ref-38ee6f98f508e7a18896ab19f563fa143fff28a1.tar.gz
crawl-ref-38ee6f98f508e7a18896ab19f563fa143fff28a1.zip
Give up if we can't find a spot for player teleport (#7472)
If there were no rtele-permitting safe squares within range, a limited-range teleport would go into an infinite loop. Now break the loop after 500 tries. Since all limited-range teleports are currently involuntary, we do not print a message when this happens.
Diffstat (limited to 'crawl-ref/source/spl-transloc.cc')
-rw-r--r--crawl-ref/source/spl-transloc.cc21
1 files changed, 14 insertions, 7 deletions
diff --git a/crawl-ref/source/spl-transloc.cc b/crawl-ref/source/spl-transloc.cc
index b491540218..e8829a94ba 100644
--- a/crawl-ref/source/spl-transloc.cc
+++ b/crawl-ref/source/spl-transloc.cc
@@ -672,15 +672,22 @@ static bool _teleport_player(bool allow_control, bool new_abyss_area,
need_distance_check = success;
}
+ int tries = 500;
do
newpos = random_in_bounds();
- while (_cell_vetoes_teleport(newpos)
- || (newpos - old_pos).abs() > dist_range(range)
- || need_distance_check && (newpos - centre).abs()
- <= dist_range(min(range - 1, 34))
- || testbits(env.pgrid(newpos), FPROP_NO_RTELE_INTO));
-
- if (newpos == old_pos)
+ while (--tries > 0
+ && (_cell_vetoes_teleport(newpos)
+ || (newpos - old_pos).abs() > dist_range(range)
+ || need_distance_check && (newpos - centre).abs()
+ <= dist_range(min(range - 1, 34))
+ || testbits(env.pgrid(newpos), FPROP_NO_RTELE_INTO)));
+
+ // Running out of tries should only happen for limited-range teleports,
+ // which are all involuntary; no message. Return false so it doesn't
+ // count as a random teleport for Xom purposes.
+ if (tries == 0)
+ return false;
+ else if (newpos == old_pos)
mpr("Your surroundings flicker for a moment.");
else if (you.see_cell(newpos))
mpr("Your surroundings seem slightly different.");