]> granicus.if.org Git - nethack/commitdiff
Allow specifying object classes in the object name given to des.object()
authorvultur-cadens <cathartes@posteo.net>
Sat, 23 Apr 2022 23:59:15 +0000 (16:59 -0700)
committerPatR <rankin@nethack.org>
Sun, 24 Apr 2022 07:35:25 +0000 (00:35 -0700)
and actually do so in the lua files.

Before this, it was not possible to specify (for example) "scroll of
teleportation" in des.object() because there is actually no object
defined in objects.h named "scroll of teleportation", so
find_objtype() failed to find it.  Instead, one had to request
"teleportation", but that is ambiguous, and find_objtype() would find
the first defined item with that name instead (ring of teleportation).

In cases of ambiguity, I referred to the des files from 3.6.6 (before
the lua conversion).

12 files changed:
dat/Hea-goal.lua
dat/Rog-loca.lua
dat/castle.lua
dat/medusa-3.lua
dat/minend-2.lua
dat/minetn-1.lua
dat/soko1-1.lua
dat/soko1-2.lua
dat/soko4-1.lua
dat/soko4-2.lua
dat/tower2.lua
src/sp_lev.c

index fd02039089054a669f69bf2427c78c09c61ae267..8298cc2e9c5b336dc697a0b1619a2fca3b720ce3 100644 (file)
@@ -32,7 +32,7 @@ des.stair("up", 39,10)
 des.non_diggable(selection.area(00,00,40,11))
 -- Objects
 des.object({ id = "quarterstaff", x=20, y=06, buc="blessed", spe=0, name="The Staff of Aesculapius" })
-des.object("lightning", 20, 06)
+des.object("wand of lightning", 20, 06)
 des.object()
 des.object()
 des.object()
index fa151dbb21d6e6a11ec862033ced510e03bc355a..bd70f7d138a12b76afc5ac0c9198e8731671bb99 100644 (file)
@@ -41,7 +41,7 @@ des.stair("down")
 -- Non diggable walls
 des.non_diggable(selection.area(00,00,75,20))
 -- Objects
-des.object({ id = "teleportation", x=11, y=18, buc="cursed", spe=0 })
+des.object({ id = "scroll of teleportation", x=11, y=18, buc="cursed", spe=0 })
 des.object()
 des.object()
 des.object()
index 9be74a8aea2b5d782e85c83a4277895903e025c9..ff87537eb85e7af511c391aadc74b87d2d4d91f0 100644 (file)
@@ -148,7 +148,7 @@ des.object({ id = "chest", trapped = 0, locked = 1, coord = loc ,
 });
 -- Prevent monsters from eating it.  (@'s never eat objects)
 des.engraving({ coord = loc, type="burn", text="Elbereth" })
-des.object({ id = "scare monster", coord = loc, buc="cursed" })
+des.object({ id = "scroll of scare monster", coord = loc, buc="cursed" })
 -- The treasure of the lord
 des.object("chest",37,08)
 -- Traps
index 7df1fa1ffb0c32e8fa522886c934a229f5a55730..c4508044a357b1a646636271db6f9883ffe078f8 100644 (file)
@@ -93,8 +93,8 @@ des.object({ id = "statue", contents=0 })
 for i=1,8 do
    des.object()
 end
-des.object("blank paper",48,18)
-des.object("blank paper",48,18)
+des.object("scroll of blank paper",48,18)
+des.object("scroll of blank paper",48,18)
 --
 des.trap("rust")
 des.trap("rust")
index 469310d19ebf3ca87a4c67bab120f76f170e41f8..a62e67e9b62881265f4bc405c5953bee89e296c0 100644 (file)
@@ -81,15 +81,15 @@ des.non_diggable(selection.area(53,14,61,14))
 des.engraving({12,03}, "engrave",
              "You are now entering the Gnome King's wine cellar.")
 des.engraving({12,04}, "engrave", "Trespassers will be persecuted!")
-des.object("booze", 10, 07)
-des.object("booze", 10, 07)
+des.object("potion of booze", 10, 07)
+des.object("potion of booze", 10, 07)
 des.object("!", 10, 07)
-des.object("booze", 10, 08)
-des.object("booze", 10, 08)
+des.object("potion of booze", 10, 08)
+des.object("potion of booze", 10, 08)
 des.object("!", 10, 08)
-des.object("booze", 10, 09)
-des.object("booze", 10, 09)
-des.object("object detection", 10, 09)
+des.object("potion of booze", 10, 09)
+des.object("potion of booze", 10, 09)
+des.object("potion of object detection", 10, 09)
 -- Objects
 -- The Treasure chamber...
 des.object("diamond", 69, 04)
index a1a9e43ed80849359218724e9fc2476e60ce49d0..8c02875dca1bd10b39df5c18cb6dff7999eeaf1c 100644 (file)
@@ -107,11 +107,11 @@ des.object({ id = "tallow candle", coord = place[4], quantity = math.random(1,2)
 -- go ahead and leave a lamp next to one corpse to be suggestive
 -- and some empty wands...
 des.object("oil lamp",place[2])
-des.object({ id = "striking", coord = place[1], buc="uncursed", spe=0 })
-des.object({ id = "striking", coord = place[3], buc="uncursed", spe=0 })
-des.object({ id = "striking", coord = place[4], buc="uncursed", spe=0 })
-des.object({ id = "magic missile", coord = place[4], buc="uncursed", spe=0 })
-des.object({ id = "magic missile", coord = place[5], buc="uncursed", spe=0 })
+des.object({ id = "wand of striking", coord = place[1], buc="uncursed", spe=0 })
+des.object({ id = "wand of striking", coord = place[3], buc="uncursed", spe=0 })
+des.object({ id = "wand of striking", coord = place[4], buc="uncursed", spe=0 })
+des.object({ id = "wand of magic missile", coord = place[4], buc="uncursed", spe=0 })
+des.object({ id = "wand of magic missile", coord = place[5], buc="uncursed", spe=0 })
 
 -- the Orcish Army
 
index bedcf13ca05ad15dea2c6bae771b0b5fbd6c837d..8818c413b221b3ebacc1022d17fa5374db0eae1a 100644 (file)
@@ -105,5 +105,5 @@ else
                buc="not-cursed", achievement=1 });
 end
 des.engraving({ coord = pt, type = "burn", text = "Elbereth" });
-des.object({ id = "scare monster", coord = pt, buc = "cursed" });
+des.object({ id = "scroll of scare monster", coord = pt, buc = "cursed" });
 
index 8a82b02e9afd65d86be9039df1f730fd85753ca6..de9f5a26610a3bc33cc731cb88bdcc8ef9026b69 100644 (file)
@@ -107,4 +107,4 @@ else
                buc="not-cursed", achievement=1 });
 end
 des.engraving({ coord = pt, type = "burn", text = "Elbereth" });
-des.object({ id = "scare monster", coord = pt, buc = "cursed" });
+des.object({ id = "scroll of scare monster", coord = pt, buc = "cursed" });
index 5629a7a5d751a736a10baeafedf3d5b148b8e836..60a8601f566fe854bc357e45620f058dc29c4d71 100644 (file)
@@ -84,8 +84,8 @@ des.trap("pit",06,10)
 des.trap("pit",07,10)
 
 -- A little help
-des.object("earth",02,11)
-des.object("earth",03,11)
+des.object("scroll of earth",02,11)
+des.object("scroll of earth",03,11)
 
 -- Random objects
 des.object({ class = "%" });
index 2cea6235f1497a6f5134f27b132a4499366463a9..7c544628c978ba21a516289febd2e97cb7a1927e 100644 (file)
@@ -54,8 +54,8 @@ des.trap("pit",05,08)
 des.trap("pit",06,08)
 
 -- A little help
-des.object("earth",01,09)
-des.object("earth",02,09)
+des.object("scroll of earth",01,09)
+des.object("scroll of earth",02,09)
 
 -- Random objects
 des.object({ class = "%" });
index 7932578447e01da1dd5d2c217f34b807833f16dd..a0f670f506b6a707f56eaf2b2fdb48aea87c818b 100644 (file)
@@ -44,7 +44,7 @@ des.object({ id = "chest", coord = place[6],
 });
 des.object("water walking boots",place[7])
 des.object("crystal plate mail",place[8])
-des.object("invisibility",place[9])
+des.object("spellbook of invisibility",place[9])
 -- Walls in the tower are non diggable
 des.non_diggable(selection.area(00,00,14,10))
 
index e9ff29b6d55142a68d7a2b416849c3956175e272..c31fcae6b67f9b67a03c8dd933d783ffbcc8b4f1 100644 (file)
@@ -3271,11 +3271,37 @@ find_objtype(lua_State *L, const char *s)
     if (s) {
         int i;
         const char *objname;
+        char class = 0;
+
+        /* In objects.h, some item classes are defined without prefixes (such
+         * as "scroll of ") in their names, making some names (such as
+         * "teleportation") ambiguous.  Get the object class if it is
+         * specified, and only return an object of the matching class. */
+        struct {
+            const char *prefix;
+            char class;
+        } class_prefixes[] = {
+            {"ring of ", RING_CLASS},
+            {"potion of ", POTION_CLASS},
+            {"scroll of ", SCROLL_CLASS},
+            {"spellbook of ", SPBOOK_CLASS},
+            {"wand of ", WAND_CLASS},
+            {NULL, 0}
+        };
+        for (i = 0; class_prefixes[i].prefix; i++) {
+            const char *p = class_prefixes[i].prefix;
+            if (!strncmpi(s, p, strlen(p))) {
+                class = class_prefixes[i].class;
+                s = s + strlen(p);
+                break;
+            }
+        }
 
         /* find by object name */
         for (i = 0; i < NUM_OBJECTS; i++) {
             objname = OBJ_NAME(objects[i]);
-            if (objname && !strcmpi(s, objname))
+            if ((!class || class == objects[i].oc_class) &&
+                objname && !strcmpi(s, objname))
                 return i;
         }