From c429cf55849a89a33db39781945dcc8316f1888f Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 19 Dec 2018 14:52:23 -0800 Subject: [PATCH 1/3] fix github issue #169 - monst vs vibrating square Fixes #169 Monsters should not be afraid of stepping on the vibrating square since it's only a trap for display purposes. [Perhaps they should deliberately avoid it if the hero hasn't seen it yet, but I didn't implement that.] "You see a strange vibration beneath ." was strange when was a wolf's "rear paws" or horse's "rear hooves"--was the vibration magically skipping the front ones? And it sounded naughty when it was a snake's "rear regions". If the creature has no limbs or is floating or flying, just say "beneath "; otherwise, if the part is "rear ", omit "rear ". The message was weird in another way. Caller removes the monster from it's old location and places it on the new one, calls newsym() for the old location to show lack of monster, but then calls mintrap() before newsym() for monster's new location (the trap's location). If pline messages cause buffered map output to be flushed, the monster will be missing during the time the messages are delivered. I fixed that for vibrating square [seetrap()->newsym() before pline() rather than after] but it should probably be fixed in the caller instead. --- doc/fixes36.2 | 1 + src/mon.c | 3 ++- src/trap.c | 32 ++++++++++++++++++++++++-------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/doc/fixes36.2 b/doc/fixes36.2 index d7348a2ee..598527047 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -289,6 +289,7 @@ diluted potion of oil is less effective when filling lamps (adds less fuel) apply fix from grunthack to prevent panic "fakecorr overflow" when vault guard couldn't figure out how to lead the hero from vault to civilization; fixes longstanding bug C343-23 +vibrating square is not really a trap so monsters don't need to avoid it Fixes to Post-3.6.1 Problems that Were Exposed Via git Repository diff --git a/src/mon.c b/src/mon.c index de037e42b..88aaf3dce 100644 --- a/src/mon.c +++ b/src/mon.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 mon.c $NHDT-Date: 1544658160 2018/12/12 23:42:40 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.274 $ */ +/* NetHack 3.6 mon.c $NHDT-Date: 1545259929 2018/12/19 22:52:09 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.275 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Derek S. Ray, 2015. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1476,6 +1476,7 @@ nexttry: /* eels prefer the water, but if there is no water nearby, if ((ttmp->ttyp != RUST_TRAP || mdat == &mons[PM_IRON_GOLEM]) && ttmp->ttyp != STATUE_TRAP + && ttmp->ttyp != VIBRATING_SQUARE && ((!is_pit(ttmp->ttyp) && !is_hole(ttmp->ttyp)) || (!is_flyer(mdat) && !is_floater(mdat) && !is_clinger(mdat)) || Sokoban) diff --git a/src/trap.c b/src/trap.c index d8d4018e7..965c9347e 100644 --- a/src/trap.c +++ b/src/trap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 trap.c $NHDT-Date: 1543515862 2018/11/29 18:24:22 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.312 $ */ +/* NetHack 3.6 trap.c $NHDT-Date: 1545259936 2018/12/19 22:52:16 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.313 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2013. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2691,13 +2691,29 @@ register struct monst *mtmp; break; case VIBRATING_SQUARE: if (see_it && !Blind) { - if (in_sight) - pline("You see a strange vibration beneath %s %s.", - s_suffix(mon_nam(mtmp)), - makeplural(mbodypart(mtmp, FOOT))); - else - pline("You see the ground vibrate in the distance."); - seetrap(trap); + seetrap(trap); /* before messages */ + if (in_sight) { + char buf[BUFSZ], *p, *monnm = mon_nam(mtmp); + + if (nolimbs(mtmp->data) + || is_floater(mtmp->data) || is_flyer(mtmp->data)) { + /* just "beneath " */ + Strcpy(buf, monnm); + } else { + Strcpy(buf, s_suffix(monnm)); + p = eos(strcat(buf, " ")); + Strcpy(p, makeplural(mbodypart(mtmp, FOOT))); + /* avoid "beneath 'rear paws'" or 'rear hooves' */ + (void) strsubst(p, "rear ", ""); + } + You_see("a strange vibration beneath %s.", buf); + } else { + /* notice something (hearing uses a larger threshold + for 'nearby') */ + You_see("the ground vibrate %s.", + (distu(mtmp->mx, mtmp->my) <= 2 * 2) + ? "nearby" : "in the distance"); + } } break; default: From 34b4d80d6babe9896a269f145b01e07f16a0ed08 Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 19 Dec 2018 17:36:14 -0800 Subject: [PATCH 2/3] fix #H2582 - seemingly angry peaceful vault guard Another one from nearly 7 years ago. Hero kicked embedded gold out of a wall while following the guard away from the vault and got "The guard calms down and picks up the gold." and player thought it was odd because the guard was peaceful. It is odd, but guards have an agitation state (0..7) when peaceful and it is always non-zero when this event occurs. Suppress the "calms down" part unless the agitation is close to making the guard turn hostile. [Agitation is set to 5 after that event, so it isn't very calming.] Also, the guard was picking up gold from underneath the hero while two steps away. Move him adjacent (although it doesn't knock other monsters out of the way if there's no room) prior to the message, then back again after. That's how if works for gold that's not at the guard's location and not at the hero's location, although that case does knock another monster out of the way if one is on the gold. --- doc/fixes36.2 | 3 ++ src/vault.c | 129 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 102 insertions(+), 30 deletions(-) diff --git a/doc/fixes36.2 b/doc/fixes36.2 index 598527047..b4437d63a 100644 --- a/doc/fixes36.2 +++ b/doc/fixes36.2 @@ -290,6 +290,9 @@ apply fix from grunthack to prevent panic "fakecorr overflow" when vault guard couldn't figure out how to lead the hero from vault to civilization; fixes longstanding bug C343-23 vibrating square is not really a trap so monsters don't need to avoid it +if hero kicks some embedded gold out of a wall while following vault gaurd + away from vault, don't report "the guard _calms_down_and_ picks up + the gold" unless he's on brink of going ballistic Fixes to Post-3.6.1 Problems that Were Exposed Via git Repository diff --git a/src/vault.c b/src/vault.c index c23f55595..3945f215d 100644 --- a/src/vault.c +++ b/src/vault.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 vault.c $NHDT-Date: 1545217597 2018/12/19 11:06:37 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.58 $ */ +/* NetHack 3.6 vault.c $NHDT-Date: 1545269451 2018/12/20 01:30:51 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.59 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2011. */ /* NetHack may be freely redistributed. See license for details. */ @@ -15,6 +15,7 @@ STATIC_DCL boolean FDECL(find_guard_dest, (struct monst *, xchar *, xchar *)); STATIC_DCL void FDECL(move_gold, (struct obj *, int)); STATIC_DCL void FDECL(wallify_vault, (struct monst *)); STATIC_DCL void FDECL(gd_mv_monaway, (struct monst *, int, int)); +STATIC_OVL void FDECL(gd_pick_corridor_gold, (struct monst *, int, int)); void newegd(mtmp) @@ -604,9 +605,9 @@ struct monst *grd; } STATIC_OVL void -gd_mv_monaway(grd, nx,ny) +gd_mv_monaway(grd, nx, ny) register struct monst *grd; -int nx,ny; +int nx, ny; { if (MON_AT(nx, ny) && !(nx == grd->mx && ny == grd->my)) { if (!Deaf) @@ -616,6 +617,97 @@ int nx,ny; } } +/* have guard pick gold off the floor, possibly moving to the gold's + position before message and back to his current spot after */ +STATIC_OVL void +gd_pick_corridor_gold(grd, goldx, goldy) +struct monst *grd; +int goldx, goldy; /* ox, gold->oy> */ +{ + struct obj *gold; + coord newcc, bestcc; + int gdelta, newdelta, bestdelta, tryct, + guardx = grd->mx, guardy = grd->my; + boolean under_u = (goldx == u.ux && goldy == u.uy), + see_it = cansee(goldx, goldy); + + if (under_u) { + /* Grab the gold from between the hero's feet. + If guard is two or more steps away; bring him closer first. */ + gold = g_at(goldx, goldy); + if (!gold) { + impossible("vault guard: no gold at hero's feet?"); + return; + } + gdelta = distu(guardx, guardy); + if (gdelta > 2 && see_it) { /* skip if player won't see it */ + bestdelta = gdelta; + bestcc.x = (xchar) guardx, bestcc.y = (xchar) guardy; + tryct = 9; + do { + /* pick an available spot nearest the hero and also try + to find the one meeting that criterium which is nearest + the guard's current location */ + if (enexto(&newcc, goldx, goldy, grd->data)) { + if ((newdelta = distu(newcc.x, newcc.y)) < bestdelta + || (newdelta == bestdelta + && dist2(newcc.x, newcc.y, guardx, guardy) + < dist2(bestcc.x, bestcc.y, guardx, guardy))) { + bestdelta = newdelta; + bestcc = newcc; + } + } + } while (--tryct >= 0); + + if (bestdelta < gdelta) { + remove_monster(guardx, guardy); + newsym(guardx, guardy); + place_monster(grd, (int) bestcc.x, (int) bestcc.y); + newsym(grd->mx, grd->my); + } + } + obj_extract_self(gold); + add_to_minv(grd, gold); + newsym(goldx, goldy); + + /* guard is already at gold's location */ + } else if (goldx == guardx && goldy == guardy) { + mpickgold(grd); /* does a newsym */ + + /* gold is at some third spot, neither guard's nor hero's */ + } else { + /* just for insurance... */ + gd_mv_monaway(grd, goldx, goldy); /* make room for guard */ + if (see_it) { /* skip if player won't see the message */ + remove_monster(grd->mx, grd->my); + newsym(grd->mx, grd->my); + place_monster(grd, goldx, goldy); /* sets mx, grd->my> */ + } + mpickgold(grd); /* does a newsym */ + } + + if (see_it) { /* cansee(goldx, goldy) */ + char monnambuf[BUFSZ]; + + Strcpy(monnambuf, Monnam(grd)); + if (!strcmpi(monnambuf, "It")) + Strcpy(monnambuf, "Someone"); + pline("%s%s picks up the gold%s.", monnambuf, + (grd->mpeaceful && EGD(grd)->warncnt > 5) + ? " calms down and" : "", + under_u ? " from beneath you" : ""); + } + + /* if guard was moved to get the gold, move him back */ + if (grd->mx != guardx || grd->my != guardy) { + remove_monster(grd->mx, grd->my); + newsym(grd->mx, grd->my); + place_monster(grd, guardx, guardy); + newsym(guardx, guardy); + } + return; +} + /* * return 1: guard moved, 0: guard didn't, -1: let m_move do it, -2: died */ @@ -774,35 +866,12 @@ register struct monst *grd; m = egrd->fakecorr[fci].fx; n = egrd->fakecorr[fci].fy; goldincorridor = TRUE; + break; } + /* new gold can appear if it was embedded in stone and hero kicks it + (on even via wish and drop) so don't assume hero has been warned */ if (goldincorridor && !egrd->gddone) { - x = grd->mx; - y = grd->my; - if (m == u.ux && n == u.uy) { - struct obj *gold = g_at(m, n); - /* Grab the gold from between the hero's feet. */ - obj_extract_self(gold); - add_to_minv(grd, gold); - newsym(m, n); - } else if (m == x && n == y) { - mpickgold(grd); /* does a newsym */ - } else { - /* just for insurance... */ - gd_mv_monaway(grd, m,n); - remove_monster(grd->mx, grd->my); - newsym(grd->mx, grd->my); - place_monster(grd, m, n); - mpickgold(grd); /* does a newsym */ - } - if (cansee(m, n)) - pline("%s%s picks up the gold.", Monnam(grd), - grd->mpeaceful ? " calms down and" : ""); - if (x != grd->mx || y != grd->my) { - remove_monster(grd->mx, grd->my); - newsym(grd->mx, grd->my); - place_monster(grd, x, y); - newsym(x, y); - } + gd_pick_corridor_gold(grd, m, n); if (!grd->mpeaceful) return -1; egrd->warncnt = 5; From f7dd3b8215b683bbca713ced65aa6aee21015e7b Mon Sep 17 00:00:00 2001 From: PatR Date: Wed, 19 Dec 2018 17:52:49 -0800 Subject: [PATCH 3/3] clang on OSX The Unix Makefile.{src,utl} use the compiler name 'gcc' by default on OSX, and that invokes clang which defines __GNUC__ to deal with gcc extensions. But when invoked via the Xcode IDE, it evidently uses its own name instead, and wasn't defining __GNUC__. tradstdc.h started down the road of duplicating gcc features; switch to pretending to be gcc instead. --- include/tradstdc.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/include/tradstdc.h b/include/tradstdc.h index e6a8f3e8f..468ebdea8 100644 --- a/include/tradstdc.h +++ b/include/tradstdc.h @@ -1,4 +1,4 @@ -/* NetHack 3.6 tradstdc.h $NHDT-Date: 1543371689 2018/11/28 02:21:29 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.32 $ */ +/* NetHack 3.6 tradstdc.h $NHDT-Date: 1545270756 2018/12/20 01:52:36 $ $NHDT-Branch: NetHack-3.6.2-beta01 $:$NHDT-Revision: 1.34 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2006. */ /* NetHack may be freely redistributed. See license for details. */ @@ -390,8 +390,10 @@ typedef genericptr genericptr_t; /* (void *) or (char *) */ #endif #ifdef __clang__ -#define UNUSED __attribute__((unused)) -#define NORETURN __attribute__((noreturn)) +/* clang's gcc emulation is sufficient for nethack's usage */ +#ifndef __GNUC__ +#define __GNUC__ 4 +#endif #endif /*