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).
This commit is contained in:
vultur-cadens
2022-04-23 16:59:15 -07:00
committed by PatR
parent 9054f97b41
commit 3571934c59
12 changed files with 51 additions and 25 deletions

View 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()

View 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()

View 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

View 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")

View 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)

View 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

View 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" });

View 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" });

View 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 = "%" });

View 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 = "%" });

View 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))

View 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;
}