]> granicus.if.org Git - nethack/commitdiff
Prevent any type of terrain overwrite from replacing stairs/ladders
authorcopperwater <aosdict@gmail.com>
Mon, 28 Sep 2020 16:48:34 +0000 (12:48 -0400)
committerPasi Kallinen <paxed@alt.org>
Mon, 28 Sep 2020 17:00:12 +0000 (20:00 +0300)
Consider the following scenario: There's a level where there's a zone of
des.replace_terrain() between the stairs and some other objective, and
the terrain is something non-walkable like trees. There's a chance that
the path is entirely blocked off by random replace_terrain, so you
make the level set terrain to '.' along a randline (or normal line, or
whatever) between the randomly placed stairs and the other side of the
replace_terrain zone. The problem: this overwrote the stairs with a '.'
as well.

This can be worked around in the lua file by first picking the desired
location of the stairs, then setting the terrain that overlaps with the
stairs, then doing des.stair() after that, but this is awkward and hard
to read.

So this makes it impossible for anything calling SET_TYPLIT (only called
in sp_lev.c) to overwrite stairs. I can't really think of a situation
where a level designer would want to define stairs, then maybe overwrite
them.

include/sp_lev.h

index cf86388e3b299344d82df8c3863378ce6bc06010..ed3e20381ad6288db60ec6433d22ecafd7ee3b7e 100644 (file)
@@ -196,7 +196,8 @@ struct mapfragment {
 #define SET_TYPLIT(x, y, ttyp, llit) \
     {                                                             \
         if ((x) >= 1 && (y) >= 0 && (x) < COLNO && (y) < ROWNO) { \
-            if ((ttyp) < MAX_TYPE)                                \
+            if ((ttyp) < MAX_TYPE && levl[(x)][(y)].typ != STAIRS \
+                && levl[(x)][(y)].typ != LADDER)                  \
                 levl[(x)][(y)].typ = (ttyp);                      \
             if ((ttyp) == LAVAPOOL)                               \
                 levl[(x)][(y)].lit = 1;                           \