From: Michael Meyer Date: Fri, 16 Jul 2021 12:16:22 +0000 (-0400) Subject: Fix #436: writing type-named scrolls X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a41176d22b33f2d308ba64f52a5716ad01c53efe;p=nethack Fix #436: writing type-named scrolls When using a marker, it is possible to write a scroll based on the type-name assigned to it by the user. Somewhat unintuitively, this system broke down if the assigned name was identical to the real name of a scroll type: trying to write a scroll by its previously-assigned name 'scare mon' or 'id' would be guaranteed to succeed, but this wouldn't be the case if the user-assigned name was 'scare monster' or 'identify'. Revise dowrite(write.c) to prefer a user-assigned type-name to the real name of a scroll that isn't already formally known, while continuing to prefer the real name of an identified scroll to both. Fixes #436 --- diff --git a/src/write.c b/src/write.c index 1614735ea..20c4ba3bd 100644 --- a/src/write.c +++ b/src/write.c @@ -179,8 +179,20 @@ dowrite(struct obj *pen) if (!OBJ_NAME(objects[i])) continue; - if (!strcmpi(OBJ_NAME(objects[i]), nm)) - goto found; + if (!strcmpi(OBJ_NAME(objects[i]), nm)) { + if (objects[i].oc_name_known + /* spellbooks can only be written by_name, so no need to + hold out for a 'better' by_descr match */ + || paper->oclass == SPBOOK_CLASS) { + by_descr = FALSE; + goto found; + } else if (!deferralchance) { + /* save item in case there are no better by_descr matches; + don't increment deferralchance so that the first uname + match will always override this */ + deferred = i; + } + } if (!strcmpi(OBJ_DESCR(objects[i]), nm)) { by_descr = TRUE; goto found; @@ -200,15 +212,17 @@ dowrite(struct obj *pen) * and 2/3 chance to keep previous 50:50 * choice; so on for higher match counts. */ - && !rn2(++deferralchance)) + && !rn2(++deferralchance)) { deferred = i; + /* writing by user-assigned name is same as by description: + fails for books, works for scrolls (having an assigned + type name guarantees presence on discoveries list) */ + by_descr = TRUE; + } } - /* writing by user-assigned name is same as by description: - fails for books, works for scrolls (having an assigned - type name guarantees presence on discoveries list) */ + if (deferred) { i = deferred; - by_descr = TRUE; goto found; }