From bc2215268b86ebb6dd8aa96197656e05d4440407 Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Sun, 1 Jun 2003 14:52:04 +0000 Subject: [PATCH] random level teleport fix From the newsgroup: prevent monsters from level teleporting out of the quest into the main dungeon. The player can't do that and monsters weren't supposed to be able to, but from time to time the quest nemesis has seemingly vanished after reading a cursed scroll of teleportation. His disappearance was due to ending up on a random level between the quest entrance and the top of the dungeon. This also fixes an obscure bug that I noticed while trying to reproduce that problem: uncontrolled level teleports by the player in the quest had 80% or thereabouts chance of ending up on the quest home level. All 12-15 main dungeon levels above quest entrance were included in the random range of 1 thru current+3, then any choice which tried to pick one of those was converted to quest level 1. (Monster destination wasn't getting that adjustment.) --- doc/fixes34.2 | 1 + src/teleport.c | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/doc/fixes34.2 b/doc/fixes34.2 index 487aa56af..620e5daaa 100644 --- a/doc/fixes34.2 +++ b/doc/fixes34.2 @@ -83,6 +83,7 @@ correct invalid startup gender selection can no longer untrap floor containers during unskilled riding can no longer easily set land mines and bear traps during unskilled riding refine cmdassist handling for armor vs accessories +prevent monsters from level teleporting out of the quest into the main dungeon Platform- and/or Interface-Specific Fixes diff --git a/src/teleport.c b/src/teleport.c index 503c96a1a..a65731bb1 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)teleport.c 3.4 2002/11/20 */ +/* SCCS Id: @(#)teleport.c 3.4 2003/05/31 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1173,15 +1173,11 @@ register struct obj *obj; int random_teleport_level() { - int nlev, max_depth, min_depth; + int nlev, max_depth, min_depth, + cur_depth = (int)depth(&u.uz); if (!rn2(5) || Is_knox(&u.uz)) - return (int)depth(&u.uz); - - /* Get a random value relative to the current dungeon */ - /* Range is 1 to current+3, current not counting */ - nlev = rnd((int)depth(&u.uz) + 2); - if (nlev >= (int)depth(&u.uz)) nlev++; + return cur_depth; /* What I really want to do is as follows: * -- If in a dungeon that goes down, the new level is to be restricted @@ -1198,11 +1194,18 @@ random_teleport_level() * above; endgame is handled in the caller due to its different * message ("disoriented"). * --KAA + * 3.4.2: explicitly handle quest here too, to fix the problem of + * monsters sometimes level teleporting out of it into main dungeon. */ - min_depth = 1; + min_depth = In_quest(&u.uz) ? dungeons[u.uz.dnum].depth_start : 1; max_depth = dunlevs_in_dungeon(&u.uz) + (dungeons[u.uz.dnum].depth_start - 1); + /* Get a random value relative to the current dungeon */ + /* Range is 1 to current+3, current not counting */ + nlev = rn2(cur_depth + 3 - min_depth) + min_depth; + if (nlev >= cur_depth) nlev++; + if (nlev > max_depth) { nlev = max_depth; /* teleport up if already on bottom */ @@ -1210,9 +1213,9 @@ random_teleport_level() } if (nlev < min_depth) { nlev = min_depth; - if ((int)depth(&u.uz) == min_depth) { - nlev += rnd(3); - if (nlev > max_depth) + if (nlev == cur_depth) { + nlev += rnd(3); + if (nlev > max_depth) nlev = max_depth; } } -- 2.40.0