From 9d9783568605a5884a39d1830223c31293a945d2 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 16 Mar 2024 16:59:55 +0200 Subject: [PATCH] Minor wishing alias improvement Previously when wishing for "ring of protection from shape shifters", you got a random ring instead of the protection from shape changers, because the string matching alias was "protection from shape shifters" without the object class. Now, we'll check if the wish matched any object class, but not existing object or alias, and try matching the aliases again, but only those of the already matching obj class. Add an alias for the ring of increase accuracy: "ring of accuracy", and tests for it. --- src/objnam.c | 16 ++++++++++++++++ test/testwish.lua | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/src/objnam.c b/src/objnam.c index 617bc1f7a..b2422de54 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -3306,6 +3306,7 @@ static const struct alt_spellings { { "grapnel", GRAPPLING_HOOK }, { "grapple", GRAPPLING_HOOK }, { "protection from shape shifters", RIN_PROTECTION_FROM_SHAPE_CHAN }, + { "accuracy", RIN_INCREASE_ACCURACY }, /* if we ever add other sizes, move this to o_ranges[] with "bag" */ { "box", LARGE_BOX }, /* normally we wouldn't have to worry about unnecessary , but @@ -4746,6 +4747,21 @@ readobjnam_postparse3(struct _readobjnam_data *d) } } + /* got a class, but not specific type; + check alternate spellings of items with matching classes */ + if (d->oclass && !d->typ) { + const struct alt_spellings *as = spellings; + + while (as->sp) { + if (objects[as->ob].oc_class == d->oclass + && wishymatch(d->bp, as->sp, TRUE)) { + d->typ = as->ob; + return 2; /*goto typfnd;*/ + } + as++; + } + } + return 0; } diff --git a/test/testwish.lua b/test/testwish.lua index 2fe5d869b..3220ef9ed 100644 --- a/test/testwish.lua +++ b/test/testwish.lua @@ -60,6 +60,9 @@ local wishtest_objects = { ["blessed fireproof +2 pair of speed boots"] = { otyp_name = "speed boots", oclass = "[", oerodeproof = 1, blessed = 1, spe = 2 }, ["tooled horn"] = { otyp_name = "tooled horn", oclass = "(" }, ["meat ring"] = { otyp_name = "meat ring", oclass = "%" }, + ["cursed +3 ring of increase accuracy"] = { otyp_name = "increase accuracy", oclass = "=", spe = 3, cursed = 1 }, + ["ring of accuracy"] = { otyp_name = "increase accuracy", oclass = "=", spe = 5 }, + ["accuracy"] = { otyp_name = "increase accuracy", oclass = "=" }, ["beartrap"] = { otyp_name = "beartrap", oclass = "(" }, ["bear trap"] = { otyp_name = "beartrap", oclass = "(" }, ["landmine"] = { otyp_name = "land mine", oclass = "(" }, @@ -94,3 +97,4 @@ for str, tbl in pairs(wishtest_objects) do end end end +pline("testwish: OK");