OK, thanks. This is a failsafe I put in to stop teleports from hanging the game forever if there was no place to go. The case I was looking at was when a badly formed level was created with only a grid for the player, and a disconnected vault. Given your description, it looks like I need to allow the game to search for a bit longer.

__________________
One for the Dark Lord on his dark throne
In the Land of Mordor where the Shadows lie.

I've now hit this bug several times in the nightlies (in fact, several times in a row). You could fix it by instead of (what I assume you do) choosing a random teleport location repeatedly until you find one or time out, iterate the dungeon to build an array of all valid destinations, then randomly select one from there. The first is linear time (if you remove the timeout) with the possibility of an infinite loop, while the second is constant (albeit a moderately large constant) and will never fail with a false negative.

I've now hit this bug several times in the nightlies (in fact, several times in a row). You could fix it by instead of (what I assume you do) choosing a random teleport location repeatedly until you find one or time out, iterate the dungeon to build an array of all valid destinations, then randomly select one from there. The first is linear time (if you remove the timeout) with the possibility of an infinite loop, while the second is constant (albeit a moderately large constant) and will never fail with a false negative.

I was about to suggest the "build-a-list-of-valid-locations" approach too, but I think the issue there might be selecting locations such that they're uniformly distributed (in terms of location in space). There might a way to do that by doing a weighted random selection, though I haven't thought too much about it.

I was about to suggest the "build-a-list-of-valid-locations" approach too, but I think the issue there might be selecting locations such that they're uniformly distributed (in terms of location in space). There might a way to do that by doing a weighted random selection, though I haven't thought too much about it.

For the specific use case of teleportation, you want to send the character a certain distance away, so you'd sort the list of potential destinations by their distance from the character's current position, and then just take the first item off the list. This makes teleportation deterministic, but the dungeon itself is chaotic enough that I doubt it'd make a difference unless you cast it immediately again -- in which case it'd send you right back where you came from, which is arguably a neat feature.

(If you're ever in the situation where you find you need to use teleportation twice in a row, you're in bad shape anyway...)

This makes teleportation deterministic, but the dungeon itself is chaotic enough that I doubt it'd make a difference unless you cast it immediately again -- in which case it'd send you right back where you came from, which is arguably a neat feature.

I've had a few times where I've teleported from one sh1tstorm into another, and only escaped with another teleport. In these situations, you don't want something that sends you back where you came!

__________________
Playing roguelikes on and off since 1984.
rogue, hack, moria, nethack, angband & zangband.

I've had a few times where I've teleported from one sh1tstorm into another, and only escaped with another teleport. In these situations, you don't want something that sends you back where you came!

Unfortunately, if you've played enough times Angband variants, you'll see that teleporting twice almost always brings you back near the location you teleported the first time, ending the life of your character. This is mainly because teleport range is too big (usually 400) and usually ends up choosing squares that are out of bounds. That's why playing a priest has a big advantage: the Portal spell has a much shorter range (100 or so) and will almost always teleport you to a new location.