From cd9e67a12ae5d44c9b976fc29975310da7bd85ea Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 11 Apr 2015 18:51:03 -0700 Subject: [PATCH 1/2] color of mithril armor From a bug report two years ago, mithril armor should have color HI_SILVER rather than HI_METAL. Tolkien describes mithril as "like silver which never tarnishes". (The bug report had a more precise quote, and a github URL for a patch which I've ignored.) The Amulet of Yendor has material set to MITHRIL but I haven't changed its color. All amulets are HI_METAL, so if any modification is needed for it, change the material rather than the color. Mithril-coats are displayed as cyan both before and after this patch, so it's hard to tell whether any change actually happened. --- doc/fixes35.0 | 1 + src/objects.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/fixes35.0 b/doc/fixes35.0 index 6a3e06d37..4c4754c6b 100644 --- a/doc/fixes35.0 +++ b/doc/fixes35.0 @@ -896,6 +896,7 @@ allow showing legal positions for stinking cloud, jumping and polearms when asked for a location cloned creatures (of any type) don't deathdrop items pudding corpses behave somewhat differently than before +mithril armor should have silver color Platform- and/or Interface-Specific Fixes diff --git a/src/objects.c b/src/objects.c index fc1796244..510fed9e6 100644 --- a/src/objects.c +++ b/src/objects.c @@ -1,4 +1,4 @@ -/* NetHack 3.5 objects.c $NHDT-Date: 1426470348 2015/03/16 01:45:48 $ $NHDT-Branch: derek-farming $:$NHDT-Revision: 1.27 $ */ +/* NetHack 3.5 objects.c $NHDT-Date: 1428802519 2015/04/12 01:35:19 $ $NHDT-Branch: master $:$NHDT-Revision: 1.34 $ */ /* Copyright (c) Mike Threepoint, 1989. */ /* NetHack may be freely redistributed. See license for details. */ @@ -373,9 +373,9 @@ ARMOR("splint mail", (char *)0, ARMOR("banded mail", (char *)0, 1, 0, 1, 0, 72, 5, 350, 90, 4, 1, ARM_SUIT, IRON, HI_METAL), ARMOR("dwarvish mithril-coat", (char *)0, - 1, 0, 0, 0, 10, 1, 150, 240, 4, 2, ARM_SUIT, MITHRIL, HI_METAL), + 1, 0, 0, 0, 10, 1, 150, 240, 4, 2, ARM_SUIT, MITHRIL, HI_SILVER), ARMOR("elven mithril-coat", (char *)0, - 1, 0, 0, 0, 15, 1, 150, 240, 5, 2, ARM_SUIT, MITHRIL, HI_METAL), + 1, 0, 0, 0, 15, 1, 150, 240, 5, 2, ARM_SUIT, MITHRIL, HI_SILVER), ARMOR("chain mail", (char *)0, 1, 0, 0, 0, 72, 5, 300, 75, 5, 1, ARM_SUIT, IRON, HI_METAL), ARMOR("orcish chain mail", "crude chain mail", From 5974ae57004782ae9fde0d07c337098af8cf7fad Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 11 Apr 2015 19:39:59 -0700 Subject: [PATCH 2/2] new pmatch variations Add pmatchi() to perform case-insensitive wildcard matching, and pmatchz() which is also case-insensitive and ignores spaces, dashes, and underscores like the type of matching done during wish parsing. At the moment, neither is being used, although DEBUGFILES handling uses pmatch and needs to be taught to distinguish between case- sensitive and case-insensitive filenames so will eventually use pmatchi when appropriate. --- include/extern.h | 4 ++- src/hacklib.c | 70 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 14 deletions(-) diff --git a/include/extern.h b/include/extern.h index 7192bba42..b3cee6708 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1,4 +1,4 @@ -/* NetHack 3.5 extern.h $NHDT-Date: 1428715841 2015/04/11 01:30:41 $ $NHDT-Branch: master $:$NHDT-Revision: 1.454 $ */ +/* NetHack 3.5 extern.h $NHDT-Date: 1428806395 2015/04/12 02:39:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.455 $ */ /* NetHack 3.5 extern.h $Date: 2013/11/05 00:57:53 $ $Revision: 1.380 $ */ /* Copyright (c) Steve Creps, 1988. */ /* NetHack may be freely redistributed. See license for details. */ @@ -833,6 +833,8 @@ E int FDECL(isqrt, (int)); E int FDECL(distmin, (int,int,int,int)); E boolean FDECL(online2, (int,int,int,int)); E boolean FDECL(pmatch, (const char *,const char *)); +E boolean FDECL(pmatchi, (const char *,const char *)); +E boolean FDECL(pmatchz, (const char *,const char *)); #ifndef STRNCMPI E int FDECL(strncmpi, (const char *,const char *,int)); #endif diff --git a/src/hacklib.c b/src/hacklib.c index ddc122ce8..e0806027f 100644 --- a/src/hacklib.c +++ b/src/hacklib.c @@ -1,15 +1,15 @@ -/* NetHack 3.5 hacklib.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */ +/* NetHack 3.5 hacklib.c $NHDT-Date: 1428806394 2015/04/12 02:39:54 $ $NHDT-Branch: master $:$NHDT-Revision: 1.34 $ */ /* NetHack 3.5 hacklib.c $Date: 2009/05/06 10:46:32 $ $Revision: 1.23 $ */ /* SCCS Id: @(#)hacklib.c 3.5 2007/04/30 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* Copyright (c) Robert Patrick Rankin, 1991 */ /* NetHack may be freely redistributed. See license for details. */ -/* We could include only config.h, except for the overlay definitions... */ -#include "hack.h" +#include "hack.h" /* for config.h+extern.h */ /*= Assorted 'small' utility routines. They're virtually independent of -NetHack, except that rounddiv may call panic(). +NetHack, except that rounddiv may call panic(). setrandom calls one of +srandom(), srand48(), or srand() depending upon configuration. return type routine name argument type(s) boolean digit (char) @@ -40,9 +40,12 @@ NetHack, except that rounddiv may call panic(). int dist2 (int, int, int, int) boolean online2 (int, int) boolean pmatch (const char *, const char *) + boolean pmatchi (const char *, const char *) + boolean pmatchz (const char *, const char *) int strncmpi (const char *, const char *, int) char * strstri (const char *, const char *) - boolean fuzzymatch (const char *,const char *,const char *,boolean) + boolean fuzzymatch (const char *,const char *, + const char *,boolean) void setrandom (void) time_t getnow (void) int getyear (void) @@ -62,6 +65,9 @@ NetHack, except that rounddiv may call panic(). # define Static static #endif +static boolean FDECL(pmatch_internal, (const char *,const char *, + BOOLEAN_P,const char *)); + boolean digit(c) /* is 'c' a digit? */ char c; @@ -465,9 +471,12 @@ online2(x0, y0, x1, y1) /* are two points lined up (on a straight line)? */ return((boolean)(!dy || !dx || (dy == dx) || (dy + dx == 0))); /* (dy == -dx) */ } -boolean -pmatch(patrn, strng) /* match a string against a pattern */ +/* guts of pmatch(), pmatchi(), and pmatchz() */ +static boolean +pmatch_internal(patrn, strng, ci, sk) /* match a string against a pattern */ const char *patrn, *strng; + boolean ci; /* True => case-insensitive, False => case-sensitive */ + const char *sk; /* set of characters to skip */ { char s, p; /* @@ -475,18 +484,53 @@ pmatch(patrn, strng) /* match a string against a pattern */ : any single character. Returns TRUE if 'strng' matches 'patrn'. */ pmatch_top: - s = *strng++; p = *patrn++; /* get next chars and pre-advance */ + if (!sk) { + s = *strng++; p = *patrn++; /* get next chars and pre-advance */ + } else { + /* fuzzy match variant of pmatch; particular characters are ignored */ + do { s = *strng++; } while (index(sk, s)); + do { p = *patrn++; } while (index(sk, p)); + } if (!p) /* end of pattern */ - return((boolean)(s == '\0')); /* matches iff end of string too */ + return (boolean)(s == '\0'); /* matches iff end of string too */ else if (p == '*') /* wildcard reached */ - return((boolean)((!*patrn || pmatch(patrn, strng-1)) ? TRUE : - s ? pmatch(patrn-1, strng) : FALSE)); - else if (p != s && (p != '?' || !s)) /* check single character */ + return (boolean) + ((!*patrn || pmatch_internal(patrn, strng-1, ci, sk)) ? TRUE : + s ? pmatch_internal(patrn-1, strng, ci, sk) : FALSE); + else if ((ci ? lowc(p) != lowc(s) : p != s) /* check single character */ + && (p != '?' || !s)) /* & single-char wildcard */ return FALSE; /* doesn't match */ - else /* return pmatch(patrn, strng); */ + else /* return pmatch_internal(patrn, strng, ci, sk); */ goto pmatch_top; /* optimize tail recursion */ } +/* case-sensitive wildcard match */ +boolean +pmatch(patrn, strng) + const char *patrn, *strng; +{ + return pmatch_internal(patrn, strng, FALSE, (const char *)0); +} + +/* case-insensitive wildcard match */ +boolean +pmatchi(patrn, strng) + const char *patrn, *strng; +{ + return pmatch_internal(patrn, strng, TRUE, (const char *)0); +} + +/* case-insensitive wildcard fuzzymatch */ +boolean +pmatchz(patrn, strng) + const char *patrn, *strng; +{ + /* ignore spaces, tabs (just in case), dashes, and underscores */ + static const char fuzzychars[] = " \t-_"; + + return pmatch_internal(patrn, strng, TRUE, fuzzychars); +} + #ifndef STRNCMPI int strncmpi(s1, s2, n) /* case insensitive counted string comparison */