From 3571934c59bd985b631e7d86203dd902e933edad Mon Sep 17 00:00:00 2001 From: vultur-cadens Date: Sat, 23 Apr 2022 16:59:15 -0700 Subject: [PATCH] Allow specifying object classes in the object name given to des.object() 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). --- dat/Hea-goal.lua | 2 +- dat/Rog-loca.lua | 2 +- dat/castle.lua | 2 +- dat/medusa-3.lua | 4 ++-- dat/minend-2.lua | 14 +++++++------- dat/minetn-1.lua | 10 +++++----- dat/soko1-1.lua | 2 +- dat/soko1-2.lua | 2 +- dat/soko4-1.lua | 4 ++-- dat/soko4-2.lua | 4 ++-- dat/tower2.lua | 2 +- src/sp_lev.c | 28 +++++++++++++++++++++++++++- 12 files changed, 51 insertions(+), 25 deletions(-) diff --git a/dat/Hea-goal.lua b/dat/Hea-goal.lua index fd0203908..8298cc2e9 100644 --- a/dat/Hea-goal.lua +++ b/dat/Hea-goal.lua @@ -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() diff --git a/dat/Rog-loca.lua b/dat/Rog-loca.lua index fa151dbb2..bd70f7d13 100644 --- a/dat/Rog-loca.lua +++ b/dat/Rog-loca.lua @@ -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() diff --git a/dat/castle.lua b/dat/castle.lua index 9be74a8ae..ff87537eb 100644 --- a/dat/castle.lua +++ b/dat/castle.lua @@ -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 diff --git a/dat/medusa-3.lua b/dat/medusa-3.lua index 7df1fa1ff..c4508044a 100644 --- a/dat/medusa-3.lua +++ b/dat/medusa-3.lua @@ -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") diff --git a/dat/minend-2.lua b/dat/minend-2.lua index 469310d19..a62e67e9b 100644 --- a/dat/minend-2.lua +++ b/dat/minend-2.lua @@ -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) diff --git a/dat/minetn-1.lua b/dat/minetn-1.lua index a1a9e43ed..8c02875dc 100644 --- a/dat/minetn-1.lua +++ b/dat/minetn-1.lua @@ -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 diff --git a/dat/soko1-1.lua b/dat/soko1-1.lua index bedcf13ca..8818c413b 100644 --- a/dat/soko1-1.lua +++ b/dat/soko1-1.lua @@ -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" }); diff --git a/dat/soko1-2.lua b/dat/soko1-2.lua index 8a82b02e9..de9f5a266 100644 --- a/dat/soko1-2.lua +++ b/dat/soko1-2.lua @@ -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" }); diff --git a/dat/soko4-1.lua b/dat/soko4-1.lua index 5629a7a5d..60a8601f5 100644 --- a/dat/soko4-1.lua +++ b/dat/soko4-1.lua @@ -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 = "%" }); diff --git a/dat/soko4-2.lua b/dat/soko4-2.lua index 2cea6235f..7c544628c 100644 --- a/dat/soko4-2.lua +++ b/dat/soko4-2.lua @@ -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 = "%" }); diff --git a/dat/tower2.lua b/dat/tower2.lua index 793257844..a0f670f50 100644 --- a/dat/tower2.lua +++ b/dat/tower2.lua @@ -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)) diff --git a/src/sp_lev.c b/src/sp_lev.c index e9ff29b6d..c31fcae6b 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -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; }