From 3086f1638643dfde1df893c6f7d1d3862ba647cc Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Sat, 13 Apr 2024 15:10:15 +0300 Subject: [PATCH 1/6] Shopkeepers bill you for using their bear trap or land mine --- doc/fixes3-7-0.txt | 1 + include/extern.h | 1 + src/apply.c | 1 + src/shk.c | 17 +++++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 39e1b9329..159ba317b 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1399,6 +1399,7 @@ gold thrown or kicked at a sleeping monster with the 'greedy' attribute gets neglected to report that target monster was awakened in the process hero movement affects the water bubble movement direction pets and peacefuls avoid a location hero just kicked +shopkeepers bill you for using their bear trap or land mine Fixes to 3.7.0-x General Problems Exposed Via git Repository diff --git a/include/extern.h b/include/extern.h index 85ec516c2..113984202 100644 --- a/include/extern.h +++ b/include/extern.h @@ -2847,6 +2847,7 @@ extern void globby_bill_fixup(struct obj *, struct obj *) NONNULLARG12; /*extern void globby_donation(struct obj *, struct obj *); */ extern void credit_report(struct monst *shkp, int idx, boolean silent) NONNULLARG1; +extern void use_unpaid_trapobj(struct obj *, coordxy, coordxy) NONNULLARG1; /* ### shknam.c ### */ diff --git a/src/apply.c b/src/apply.c index 709807ffc..6c18cb039 100644 --- a/src/apply.c +++ b/src/apply.c @@ -2880,6 +2880,7 @@ use_trap(struct obj *otmp) } } You("begin setting %s%s.", shk_your(buf, otmp), trapname(ttyp, FALSE)); + use_unpaid_trapobj(otmp, u.ux, u.uy); set_occupation(set_trap, occutext, 0); return; } diff --git a/src/shk.c b/src/shk.c index 25fd6ebf4..e0b638ce0 100644 --- a/src/shk.c +++ b/src/shk.c @@ -5523,4 +5523,21 @@ globby_bill_fixup(struct obj *obj_absorber, struct obj *obj_absorbed) return; } +/* Shopkeeper bills for use of a land mine or bear trap they own */ +void +use_unpaid_trapobj(struct obj *otmp, coordxy x, coordxy y) +{ + if (otmp->unpaid) { + if (!Deaf) { + struct monst *shkp = find_objowner(otmp, x, y); + + if (shkp && !muteshk(shkp)) { + SetVoice(shkp, 0, 80, 0); + verbalize("You set it, you buy it!"); + } + } + bill_dummy_object(otmp); + } +} + /*shk.c*/ From 3364ac7cdb007a74852a424e13822cc5c8fb720f Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 13 Apr 2024 09:08:14 -0400 Subject: [PATCH 2/6] CHANGE_COLOR:allow #rrggbb hex color specification --- src/coloratt.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/src/coloratt.c b/src/coloratt.c index 762a80bec..2f3b32cdf 100644 --- a/src/coloratt.c +++ b/src/coloratt.c @@ -5,6 +5,8 @@ #include "hack.h" #include +staticfn int32 alt_color_spec(const char *cp); + struct color_names { const char *name; int color; @@ -1067,7 +1069,11 @@ alternative_palette(char *op) coloridx = match_str2clr(c_colorid, TRUE); if (c_colorval && coloridx >= 0 && coloridx < CLR_MAX) { - rgb = rgbstr_to_int32(c_colorval); + if (*c_colorval == '#' || *c_colorval == '\\') { + rgb = alt_color_spec(c_colorval); + } else { + rgb = rgbstr_to_int32(c_colorval); + } if (rgb != -1) { ga.altpalette[coloridx] = (uint32) rgb | NH_ALTPALETTE; /* use COLORVAL(ga.altpalette[coloridx]) to get @@ -1090,6 +1096,48 @@ change_palette(void) } } } + +staticfn int32 +alt_color_spec(const char *cp) +{ + static NEARDATA const char oct[] = "01234567", dec[] = "0123456789"; + /* hexdd[] is defined in decl.c */ + + const char *dp; + int32 cval = -1; + int dcount; + + cval = dcount = 0; /* for decimal, octal, hexadecimal cases */ + while (*cp) { + if (((*cp != '\\') && (*cp != '#')) || !cp[1]) { + /* simple val, or nothing left for \ to escape */ + cval = *cp++; + } else if (*cp != '#' && strchr(dec, cp[1])) { + ++cp; /* move past backslash to first digit */ + do { + cval = (cval * 10) + (*cp - '0'); + } while (*++cp && strchr(dec, *cp) && ++dcount < 3); + } else if (*cp != '#' && (cp[1] == 'o' || cp[1] == 'O') && cp[2] + && strchr(oct, cp[2])) { + cp += 2; /* move past backslash and 'O' */ + do { + cval = (cval * 8) + (*cp - '0'); + } while (*++cp && strchr(oct, *cp) && ++dcount < 8); + } else if (((cp[1] == 'x' || cp[1] == 'X') && cp[2] + && (dp = strchr(hexdd, cp[2])) != 0) + || (cp[0] == '#' && cp[1] + && (dp = strchr(hexdd, cp[1])) != 0)) { + if (*cp == '\\') + cp += 2; /* move past backslash and 'X' */ + else if (*cp == '#') + cp += 1; /* move past '#' */ + do { + cval = (cval * 16) + ((int) (dp - hexdd) / 2); + } while (*++cp && (dp = strchr(hexdd, *cp)) != 0 && ++dcount < 6); + } + } + return cval; +} #endif /* CHANGE_COLOR */ /*coloratt.c*/ From 936096d5e38b5eda8094d21e6f03001682086b6d Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 13 Apr 2024 09:11:27 -0400 Subject: [PATCH 3/6] Windows build fix consoletty.o : error LNK2005: _tty_change_color already defined in wintty.o consoletty.o : error LNK2005: _tty_get_color_string already defined in wintty.o --- sys/windows/consoletty.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/sys/windows/consoletty.c b/sys/windows/consoletty.c index 55f89dee6..0c40e18b3 100644 --- a/sys/windows/consoletty.c +++ b/sys/windows/consoletty.c @@ -2000,21 +2000,6 @@ tty_ibmgraphics_fixup(void) #endif /* VIRTUAL_TERMINAL_SEQUENCES */ } -#ifdef CHANGE_COLOR -#ifdef NO_TERMS -void -tty_change_color(int color UNUSED, long rgb UNUSED, int reverse UNUSED) -{ -} - -char * -tty_get_color_string(void) -{ - return (""); -} -#endif -#endif /* CHANGE_COLOR */ - #ifdef PORT_DEBUG void win32con_debug_keystrokes(void) From c30dbb2caa2dc511083a5e160e445e9b9e4a07cc Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 13 Apr 2024 12:00:37 -0400 Subject: [PATCH 4/6] alt_color_spec follow-up --- src/coloratt.c | 63 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/coloratt.c b/src/coloratt.c index 2f3b32cdf..96bb06294 100644 --- a/src/coloratt.c +++ b/src/coloratt.c @@ -5,8 +5,6 @@ #include "hack.h" #include -staticfn int32 alt_color_spec(const char *cp); - struct color_names { const char *name; int color; @@ -221,6 +219,10 @@ static struct nethack_color colortable[] = { { rgb_color, 154, 138, "white", "#FFFFFF", 255, 255, 255 }, }; +#ifdef CHANGE_COLOR +staticfn int32 alt_color_spec(const char *cp); +#endif + int32 colortable_to_int32(struct nethack_color *cte) { @@ -1069,10 +1071,9 @@ alternative_palette(char *op) coloridx = match_str2clr(c_colorid, TRUE); if (c_colorval && coloridx >= 0 && coloridx < CLR_MAX) { - if (*c_colorval == '#' || *c_colorval == '\\') { + rgb = rgbstr_to_int32(c_colorval); + if (rgb == -1) { rgb = alt_color_spec(c_colorval); - } else { - rgb = rgbstr_to_int32(c_colorval); } if (rgb != -1) { ga.altpalette[coloridx] = (uint32) rgb | NH_ALTPALETTE; @@ -1098,39 +1099,51 @@ change_palette(void) } staticfn int32 -alt_color_spec(const char *cp) +alt_color_spec(const char *str) { static NEARDATA const char oct[] = "01234567", dec[] = "0123456789"; /* hexdd[] is defined in decl.c */ - const char *dp; + const char *dp, *cp = str; int32 cval = -1; int dcount; + boolean hexescape = FALSE, octescape = FALSE; - cval = dcount = 0; /* for decimal, octal, hexadecimal cases */ - while (*cp) { - if (((*cp != '\\') && (*cp != '#')) || !cp[1]) { + dcount = 0; /* for decimal, octal, hexadecimal cases */ + hexescape = + (*cp == '\\' && cp[1] && (cp[1] == 'x' || cp[1] == 'X') && cp[2]); + if (!hexescape) { + octescape = + (*cp == '\\' && cp[1] && (cp[1] == 'o' || cp[1] == 'O') && cp[2]); + } + + if (hexescape || octescape) { + cval = 0; + cp += 2; + } else if (*cp == '#' && cp[1]) { + hexescape = TRUE; + cval = 0; + cp += 1; + } else if (cp[1]) { + cval = 0; + } else if (!cp[1]) { + if (strchr(dec, *cp) != 0) { /* simple val, or nothing left for \ to escape */ - cval = *cp++; - } else if (*cp != '#' && strchr(dec, cp[1])) { - ++cp; /* move past backslash to first digit */ + cval = (*cp - '0'); + } + cp++; + } + + while (*cp) { + if (!hexescape && !octescape && strchr(dec, *cp)) { do { cval = (cval * 10) + (*cp - '0'); - } while (*++cp && strchr(dec, *cp) && ++dcount < 3); - } else if (*cp != '#' && (cp[1] == 'o' || cp[1] == 'O') && cp[2] - && strchr(oct, cp[2])) { - cp += 2; /* move past backslash and 'O' */ + } while (*++cp && strchr(dec, *cp) && ++dcount < 8); + } else if (octescape && strchr(oct, *cp)) { do { cval = (cval * 8) + (*cp - '0'); } while (*++cp && strchr(oct, *cp) && ++dcount < 8); - } else if (((cp[1] == 'x' || cp[1] == 'X') && cp[2] - && (dp = strchr(hexdd, cp[2])) != 0) - || (cp[0] == '#' && cp[1] - && (dp = strchr(hexdd, cp[1])) != 0)) { - if (*cp == '\\') - cp += 2; /* move past backslash and 'X' */ - else if (*cp == '#') - cp += 1; /* move past '#' */ + } else if (hexescape && (dp = strchr(hexdd, *cp)) != 0) { do { cval = (cval * 16) + ((int) (dp - hexdd) / 2); } while (*++cp && (dp = strchr(hexdd, *cp)) != 0 && ++dcount < 6); From 86cb8dba6059fd2048dccc9e6db8ce639253afff Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 13 Apr 2024 12:09:45 -0400 Subject: [PATCH 5/6] use COLORVAL macro in change_palette() --- src/coloratt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coloratt.c b/src/coloratt.c index 96bb06294..ef0407327 100644 --- a/src/coloratt.c +++ b/src/coloratt.c @@ -1092,7 +1092,7 @@ change_palette(void) for (clridx = 0; clridx < CLR_MAX; ++clridx) { if (ga.altpalette[clridx] != 0) { - long rgb = (long) (ga.altpalette[clridx] & ~NH_ALTPALETTE); + long rgb = (long) COLORVAL(ga.altpalette[clridx]); (*windowprocs.win_change_color)(clridx, rgb, 0); } } From f2d0dbcc09dc9de4d20d62d496f5a07e86278d1e Mon Sep 17 00:00:00 2001 From: nhmall Date: Sat, 13 Apr 2024 13:06:38 -0400 Subject: [PATCH 6/6] revise alt_color_spec() so digit count limits work --- src/coloratt.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/coloratt.c b/src/coloratt.c index ef0407327..8e68a469d 100644 --- a/src/coloratt.c +++ b/src/coloratt.c @@ -1106,7 +1106,7 @@ alt_color_spec(const char *str) const char *dp, *cp = str; int32 cval = -1; - int dcount; + int dcount, dlimit = 6; boolean hexescape = FALSE, octescape = FALSE; dcount = 0; /* for decimal, octal, hexadecimal cases */ @@ -1120,33 +1120,36 @@ alt_color_spec(const char *str) if (hexescape || octescape) { cval = 0; cp += 2; + if (octescape) + dlimit = 8; } else if (*cp == '#' && cp[1]) { hexescape = TRUE; cval = 0; cp += 1; } else if (cp[1]) { cval = 0; + dlimit = 8; } else if (!cp[1]) { if (strchr(dec, *cp) != 0) { /* simple val, or nothing left for \ to escape */ cval = (*cp - '0'); } + dlimit = 1; cp++; } while (*cp) { if (!hexescape && !octescape && strchr(dec, *cp)) { - do { - cval = (cval * 10) + (*cp - '0'); - } while (*++cp && strchr(dec, *cp) && ++dcount < 8); + cval = (cval * 10) + (*cp - '0'); } else if (octescape && strchr(oct, *cp)) { - do { - cval = (cval * 8) + (*cp - '0'); - } while (*++cp && strchr(oct, *cp) && ++dcount < 8); + cval = (cval * 8) + (*cp - '0'); } else if (hexescape && (dp = strchr(hexdd, *cp)) != 0) { - do { - cval = (cval * 16) + ((int) (dp - hexdd) / 2); - } while (*++cp && (dp = strchr(hexdd, *cp)) != 0 && ++dcount < 6); + cval = (cval * 16) + ((int) (dp - hexdd) / 2); + } + ++cp; + if (++dcount > dlimit) { + cval = -1; + break; } } return cval;