From 323b7bba2c6a946865deacd845ad8ae54a39c596 Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 18 Apr 2015 17:25:52 +0300 Subject: [PATCH 1/2] Allow wishing for polearm or hammer which gives a random weapon with the matching skill, so a random polearm, or a war hammer, respectively. --- src/objnam.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/objnam.c b/src/objnam.c index 3c5580c0d..afc79662d 100644 --- a/src/objnam.c +++ b/src/objnam.c @@ -10,6 +10,7 @@ #define NUMOBUF 12 STATIC_DCL char *FDECL(strprepend,(char *,const char *)); +STATIC_DCL short FDECL(rnd_otyp_by_wpnskill, (SCHAR_P)); STATIC_DCL boolean FDECL(wishymatch, (const char *,const char *,BOOLEAN_P)); STATIC_DCL char *NDECL(nextobuf); STATIC_DCL void FDECL(releaseobuf, (char *)); @@ -2277,6 +2278,27 @@ struct alt_spellings { { (const char *)0, 0 }, }; +short +rnd_otyp_by_wpnskill(skill) +schar skill; +{ + int i,n = 0; + short otyp; + for (i = bases[WEAPON_CLASS]; i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++) + if (objects[i].oc_skill == skill) { + n++; + otyp = i; + } + if (n > 0) { + n = rn2(n); + for (i = bases[WEAPON_CLASS]; i < NUM_OBJECTS && objects[i].oc_class == WEAPON_CLASS; i++) + if (objects[i].oc_skill == skill) + if (--n < 0) return i; + } + return STRANGE_OBJECT; +} + + /* * Return something wished for. Specifying a null pointer for * the user request string results in a random object. Otherwise, @@ -3024,6 +3046,16 @@ wiztrap: } } + if (!oclass && !typ) { + if (!strncmpi(bp, "polearm", 7)) { + typ = rnd_otyp_by_wpnskill(P_POLEARMS); + goto typfnd; + } else if (!strncmpi(bp, "hammer", 6)) { + typ = rnd_otyp_by_wpnskill(P_HAMMER); + goto typfnd; + } + } + if(!oclass) return((struct obj *)0); any: if(!oclass) oclass = wrpsym[rn2((int)sizeof(wrpsym))]; From 78b012a680c489082a61886ab07ec66cee643d08 Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 18 Apr 2015 15:29:37 -0400 Subject: [PATCH 2/2] prevent a couple of reported array index segfaults Changes to be committed: modified: src/hack.c modified: src/pager.c Don't use glyph_to_cmap as an array index into the defsyms[] array unless it really is a cmap. Recent situation: glyph_to_cmap will return NO_GLYPH for the unknown monster glyph 'I', which is not a valid index for the defsyms[] array. --- src/hack.c | 2 +- src/pager.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/hack.c b/src/hack.c index df437391a..c94363d91 100644 --- a/src/hack.c +++ b/src/hack.c @@ -1363,7 +1363,7 @@ domove() if (boulder) Strcpy(buf, ansimpleoname(boulder)); - else if (solid) + else if (solid && glyph_is_cmap(glyph)) Strcpy(buf, the(defsyms[glyph_to_cmap(glyph)].explanation)); else if (!Underwater) Strcpy(buf, "thin air"); diff --git a/src/pager.c b/src/pager.c index 280cf0a05..e8d7c168b 100644 --- a/src/pager.c +++ b/src/pager.c @@ -273,7 +273,8 @@ lookat(x, y, buf, monbuf) Strcpy(buf, Is_airlevel(&u.uz) ? "cloudy area" : "fog/vapor cloud"); break; default: - Strcpy(buf,defsyms[glyph_to_cmap(glyph)].explanation); + if (glyph_is_cmap(glyph)) + Strcpy(buf,defsyms[glyph_to_cmap(glyph)].explanation); break; }