From 1830b206c733d1b2edda45b8e60a5f9281ac17cc Mon Sep 17 00:00:00 2001 From: Michael Meyer Date: Wed, 21 Sep 2022 19:55:04 -0400 Subject: [PATCH] Prevent hero from falling past end of dungeon Similar story with saved trap door destinations: if a bones file near the end of the dungeon came from a longer dungeon (i.e. with a lower-depth castle) than the one the bones file is loaded into, the trap door destination could be past the dungeon end. Clamp the destination so it won't be lower than the bottom level of the dungeon. --- src/trap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/trap.c b/src/trap.c index b794c4891..193d401c4 100644 --- a/src/trap.c +++ b/src/trap.c @@ -580,15 +580,18 @@ fall_through( if (Is_stronghold(&u.uz)) { find_hell(&dtmp); } else { - int dist = newlevel - dunlev(&u.uz); + int dist; if (t) { dtmp.dnum = t->dst.dnum; - dtmp.dlevel = t->dst.dlevel; + /* don't fall beyond the bottom, in case this came from a bones + file with different dungeon size */ + dtmp.dlevel = min(t->dst.dlevel, bottom); dist = dtmp.dlevel - dunlev(&u.uz); } else { dtmp.dnum = u.uz.dnum; dtmp.dlevel = newlevel; + dist = newlevel - dunlev(&u.uz); } if (dist > 1) You("fall down a %s%sshaft!", dist > 3 ? "very " : "",