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:
28
src/sp_lev.c
28
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user