From 38fa93df7335deca63cde47172979a041d3b9156 Mon Sep 17 00:00:00 2001 From: Patric Mueller Date: Sat, 11 Jan 2020 12:24:02 +0100 Subject: [PATCH] Restrict the teleportation notification to actual teleportations teleds() is used for more than just teleportations, the teleportation message was also given when mounting a steed. Trying out a new bit flags method parameter design pattern. --- include/extern.h | 6 +++--- include/global.h | 2 +- include/hack.h | 5 +++++ src/apply.c | 4 ++-- src/dbridge.c | 2 +- src/mhitu.c | 2 +- src/steed.c | 4 ++-- src/teleport.c | 22 ++++++++++++---------- src/trap.c | 8 ++++---- 9 files changed, 31 insertions(+), 24 deletions(-) diff --git a/include/extern.h b/include/extern.h index da0edbb65..d2c251c11 100644 --- a/include/extern.h +++ b/include/extern.h @@ -144,7 +144,7 @@ E void FDECL(Lift_covet_and_placebc, (int, const char *, int)); #define unplacebc_and_covet_placebc() \ Unplacebc_and_covet_placebc(__FUNCTION__, __LINE__) #define lift_covet_and_placebc(x) \ - Lift_covet_and_placebc(x, __FUNCTION__, __LINE__) + Lift_covet_and_placebc(x, __FUNCTION__, __LINE__) #endif E void FDECL(set_bc, (int)); E void FDECL(move_bc, (int, int, XCHAR_P, XCHAR_P, XCHAR_P, XCHAR_P)); @@ -2530,8 +2530,8 @@ E boolean FDECL(goodpos, (int, int, struct monst *, unsigned)); E boolean FDECL(enexto, (coord *, XCHAR_P, XCHAR_P, struct permonst *)); E boolean FDECL(enexto_core, (coord *, XCHAR_P, XCHAR_P, struct permonst *, unsigned)); -E void FDECL(teleds, (int, int, BOOLEAN_P)); -E boolean FDECL(safe_teleds, (BOOLEAN_P)); +E void FDECL(teleds, (int, int, int)); +E boolean FDECL(safe_teleds, (int)); E boolean FDECL(teleport_pet, (struct monst *, BOOLEAN_P)); E void NDECL(tele); E boolean FDECL(scrolltele, (struct obj *)); diff --git a/include/global.h b/include/global.h index 609d5ec33..35c336e23 100644 --- a/include/global.h +++ b/include/global.h @@ -143,7 +143,7 @@ struct cross_target_s { unsigned long build_time; }; extern struct cross_target_s cross_target; -#if defined(CROSSCOMPILE_TARGET) && !defined(MAKEDEFS_C) +#if defined(CROSSCOMPILE_TARGET) && !defined(MAKEDEFS_C) #define BUILD_DATE cross_target.build_date /* "Wed Apr 1 00:00:01 2020" */ #define COPYRIGHT_BANNER_C cross_target.copyright_banner_c #define NETHACK_GIT_SHA cross_target.git_sha diff --git a/include/hack.h b/include/hack.h index baedf773a..f0f8608bf 100644 --- a/include/hack.h +++ b/include/hack.h @@ -490,6 +490,11 @@ enum bodypart_types { #define MENU_FULL 2 #define MENU_PARTIAL 3 +/* flags to control teleds() */ +#define TELEDS_NO_FLAGS 0 +#define TELEDS_ALLOW_DRAG 1 +#define TELEDS_TELEPORT 2 + /* * Option flags * Each higher number includes the characteristics of the numbers diff --git a/src/apply.c b/src/apply.c index 79da1130d..08b39c31e 100644 --- a/src/apply.c +++ b/src/apply.c @@ -1807,7 +1807,7 @@ int magic; /* 0=Physical, otherwise skill level */ * and usually moves the ball if punished, but does not handle all * the effects of landing on the final position. */ - teleds(cc.x, cc.y, FALSE); + teleds(cc.x, cc.y, TELEDS_NO_FLAGS); nomul(-1); g.multi_reason = "jumping around"; g.nomovemsg = ""; @@ -2755,7 +2755,7 @@ struct obj *obj; if (proficient && rn2(proficient + 2)) { if (!mtmp || enexto(&cc, rx, ry, g.youmonst.data)) { You("yank yourself out of the pit!"); - teleds(cc.x, cc.y, TRUE); + teleds(cc.x, cc.y, TELEDS_ALLOW_DRAG); reset_utrap(TRUE); g.vision_full_recalc = 1; } diff --git a/src/dbridge.c b/src/dbridge.c index 02a54c2d5..ad2b85db8 100644 --- a/src/dbridge.c +++ b/src/dbridge.c @@ -435,7 +435,7 @@ int xkill_flags, how; if (enexto(&xy, etmp->ex, etmp->ey, etmp->edata)) { pline("A %s force teleports you away...", Hallucination ? "normal" : "strange"); - teleds(xy.x, xy.y, FALSE); + teleds(xy.x, xy.y, TELEDS_NO_FLAGS); } /* otherwise on top of the drawbridge is the * only viable spot in the dungeon, so stay there diff --git a/src/mhitu.c b/src/mhitu.c index 172291e6b..677561dca 100644 --- a/src/mhitu.c +++ b/src/mhitu.c @@ -453,7 +453,7 @@ register struct monst *mtmp; if (m_at(cc.x, cc.y)) (void) enexto(&cc, u.ux, u.uy, g.youmonst.data); } - teleds(cc.x, cc.y, TRUE); /* move hero */ + teleds(cc.x, cc.y, TELEDS_ALLOW_DRAG); /* move hero */ set_apparxy(mtmp); newsym(u.ux, u.uy); diff --git a/src/steed.c b/src/steed.c index 5e92adf67..bdd89a13b 100644 --- a/src/steed.c +++ b/src/steed.c @@ -353,7 +353,7 @@ boolean force; /* Quietly force this animal */ g.unweapon = FALSE; u.usteed = mtmp; remove_monster(mtmp->mx, mtmp->my); - teleds(mtmp->mx, mtmp->my, TRUE); + teleds(mtmp->mx, mtmp->my, TELEDS_ALLOW_DRAG); g.context.botl = TRUE; return TRUE; } @@ -645,7 +645,7 @@ int reason; /* Player was thrown off etc. */ * teleds() clears u.utrap */ g.in_steed_dismounting = TRUE; - teleds(cc.x, cc.y, TRUE); + teleds(cc.x, cc.y, TELEDS_ALLOW_DRAG); g.in_steed_dismounting = FALSE; /* Put your steed in your trap */ diff --git a/src/teleport.c b/src/teleport.c index 6707cc9d2..bf2ea075b 100644 --- a/src/teleport.c +++ b/src/teleport.c @@ -277,11 +277,13 @@ boolean trapok; } void -teleds(nux, nuy, allow_drag) -register int nux, nuy; -boolean allow_drag; +teleds(nux, nuy, teleds_flags) +int nux, nuy; +int teleds_flags; { boolean ball_active, ball_still_in_range; + boolean allow_drag = teleds_flags & TELEDS_ALLOW_DRAG; + boolean is_teleport = teleds_flags & TELEDS_TELEPORT; struct monst *vault_guard = vault_occupied(u.urooms) ? findgd() : 0; if (u.utraptype == TT_BURIEDBALL) { @@ -356,7 +358,7 @@ boolean allow_drag; } } - if (flags.verbose) + if (is_teleport && flags.verbose) You("materialize in %s location!", (nux == u.ux0 && nuy == u.uy0) ? "the same" : "a different"); @@ -415,8 +417,8 @@ boolean allow_drag; } boolean -safe_teleds(allow_drag) -boolean allow_drag; +safe_teleds(teleds_flags) +int teleds_flags; { register int nux, nuy, tcnt = 0; @@ -426,7 +428,7 @@ boolean allow_drag; } while (!teleok(nux, nuy, (boolean) (tcnt > 200)) && ++tcnt <= 400); if (tcnt <= 400) { - teleds(nux, nuy, allow_drag); + teleds(nux, nuy, teleds_flags); return TRUE; } else return FALSE; @@ -439,7 +441,7 @@ vault_tele() coord c; if (croom && somexy(croom, &c) && teleok(c.x, c.y, FALSE)) { - teleds(c.x, c.y, FALSE); + teleds(c.x, c.y, TELEDS_TELEPORT); return; } tele(); @@ -529,7 +531,7 @@ struct obj *scroll; /* for scroll, discover it regardless of destination */ if (scroll) learnscroll(scroll); - teleds(cc.x, cc.y, FALSE); + teleds(cc.x, cc.y, TELEDS_TELEPORT); return TRUE; } pline("Sorry..."); @@ -543,7 +545,7 @@ struct obj *scroll; } g.telescroll = scroll; - (void) safe_teleds(FALSE); + (void) safe_teleds(TELEDS_TELEPORT); /* teleds() will leave g.telescroll intact iff random destination is far enough away for scroll discovery to be warranted */ if (g.telescroll) diff --git a/src/trap.c b/src/trap.c index 7eeded57a..9b56ea0bf 100644 --- a/src/trap.c +++ b/src/trap.c @@ -3858,7 +3858,7 @@ drown() You("dump some of your gear to lose weight..."); if (succ) { pline("Pheew! That was close."); - teleds(x, y, TRUE); + teleds(x, y, TELEDS_ALLOW_DRAG); return TRUE; } /* still too much weight */ @@ -3877,7 +3877,7 @@ drown() Strcpy(g.killer.name, pool_of_water); done(DROWNING); /* oops, we're still alive. better get out of the water. */ - if (safe_teleds(TRUE)) + if (safe_teleds(TELEDS_ALLOW_DRAG | TELEDS_TELEPORT)) break; /* successful life-save */ /* nowhere safe to land; repeat drowning loop... */ pline("You're still drowning."); @@ -5348,7 +5348,7 @@ lava_effects() Strcpy(g.killer.name, lava_killer); You("%s...", boil_away ? "boil away" : "burn to a crisp"); done(BURNING); - if (safe_teleds(TRUE)) + if (safe_teleds(TELEDS_ALLOW_DRAG | TELEDS_TELEPORT)) break; /* successful life-save */ /* nowhere safe to land; repeat burning loop */ pline("You're still burning."); @@ -5408,7 +5408,7 @@ sink_into_lava() reset_utrap(TRUE); /* levitation or flight have become unblocked, otherwise Tport */ if (!Levitation && !Flying) - (void) safe_teleds(TRUE); + (void) safe_teleds(TELEDS_ALLOW_DRAG | TELEDS_TELEPORT); } else if (!u.umoved) { /* can't fully turn into slime while in lava, but might not have it be burned away until you've come awfully close */ -- 2.49.0