From ff16502d670ec59e12c4edb383a654d50d7c9f93 Mon Sep 17 00:00:00 2001 From: "nethack.rankin" Date: Sat, 4 Jun 2005 05:25:28 +0000 Subject: [PATCH] floor access A post-3.4.3 change dealing with reaching into pits resulted in "you sit on the air" if you used the #sit command after escaping a pit trap. Change can_reach_floor() so that caller explicitly controls whether being on the brink of a pit is a condition that prevents reaching the floor. This also splits a fairly common message about not being able to reach the floor into a separate routine. There is still oddness here: if you're polymorphed into a flyer, #sit yields "you sit down" followed by "you fly over a pit" (latter occurs when escaping trap activation). A ceiling hider behaves similarly, but the second message is "you escape a pit" and doesn't sound quite as silly. Perhaps #sit should pass TOOKPLUNGE to dotrap(), or maybe there's some better way to handle this? --- include/extern.h | 3 ++- src/apply.c | 9 ++++----- src/dig.c | 15 ++++++++++----- src/do.c | 4 ++-- src/eat.c | 4 ++-- src/engrave.c | 44 +++++++++++++++++++++++++++++--------------- src/hack.c | 4 ++-- src/invent.c | 4 ++-- src/lock.c | 6 +++--- src/pickup.c | 10 +++++----- src/potion.c | 10 +++++++--- src/sit.c | 26 +++++++++++++------------- src/trap.c | 4 ++-- 13 files changed, 83 insertions(+), 60 deletions(-) diff --git a/include/extern.h b/include/extern.h index 2cea07cca6..ded45696ad 100644 --- a/include/extern.h +++ b/include/extern.h @@ -597,7 +597,8 @@ E void FDECL(restore_killers, (int)); E char *FDECL(random_engraving, (char *)); E void FDECL(wipeout_text, (char *,int,unsigned)); -E boolean NDECL(can_reach_floor); +E boolean FDECL(can_reach_floor, (BOOLEAN_P)); +E void FDECL(cant_reach_floor, (int,int,BOOLEAN_P,BOOLEAN_P)); E const char *FDECL(surface, (int,int)); E const char *FDECL(ceiling, (int,int)); E struct engr *FDECL(engr_at, (XCHAR_P,XCHAR_P)); diff --git a/src/apply.c b/src/apply.c index 7f56fac2ce..2cc5b17fa9 100644 --- a/src/apply.c +++ b/src/apply.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)apply.c 3.5 2005/04/13 */ +/* SCCS Id: @(#)apply.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -169,7 +169,7 @@ int rx, ry, *resp; struct obj *corpse = sobj_at(CORPSE, rx, ry), *statue = sobj_at(STATUE, rx, ry); - if (!can_reach_floor()) { /* levitation or unskilled riding */ + if (!can_reach_floor(TRUE)) { /* levitation or unskilled riding */ corpse = 0; /* can't reach corpse on floor */ /* you can't reach tiny statues (even though you can fight tiny monsters while levitating--consistency, what's that?) */ @@ -322,9 +322,8 @@ use_stethoscope(obj) } else if (u.dz) { if (Underwater) You_hear("faint splashing."); - else if (u.dz < 0 || !can_reach_floor()) - You_cant("reach the %s.", - (u.dz > 0) ? surface(u.ux,u.uy) : ceiling(u.ux,u.uy)); + else if (u.dz < 0 || !can_reach_floor(TRUE)) + cant_reach_floor(u.ux, u.uy, (u.dz < 0), TRUE); else if (its_dead(u.ux, u.uy, &res)) ; /* message already given */ else if (Is_stronghold(&u.uz)) diff --git a/src/dig.c b/src/dig.c index 7c47e76958..fa1fdb26e4 100644 --- a/src/dig.c +++ b/src/dig.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)dig.c 3.5 2005/04/13 */ +/* SCCS Id: @(#)dig.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -880,6 +880,7 @@ struct obj *obj; { register int rx, ry; register struct rm *lev; + struct trap *trap; int dig_target; boolean ispick = is_pick(obj); const char *verbing = ispick ? "digging" : "chopping"; @@ -919,8 +920,7 @@ struct obj *obj; dig_target = dig_typ(obj, rx, ry); if (dig_target == DIGTYP_UNDIGGABLE) { /* ACCESSIBLE or POOL */ - struct trap *trap = t_at(rx, ry); - + trap = t_at(rx, ry); if (trap && trap->ttyp == WEB) { if (!trap->tseen) { seetrap(trap); @@ -994,12 +994,17 @@ struct obj *obj; } else if (Is_airlevel(&u.uz) || Is_waterlevel(&u.uz)) { /* it must be air -- water checked above */ You("swing %s through thin air.", yobjnam(obj, (char *)0)); - } else if (!can_reach_floor()) { - You_cant("reach the %s.", surface(u.ux,u.uy)); + } else if (!can_reach_floor(FALSE)) { + cant_reach_floor(u.ux, u.uy, FALSE, FALSE); } else if (is_pool(u.ux, u.uy) || is_lava(u.ux, u.uy)) { /* Monsters which swim also happen not to be able to dig */ You("cannot stay under%s long enough.", is_pool(u.ux, u.uy) ? "water" : " the lava"); + } else if ((trap = t_at(u.ux, u.uy)) != 0 && + uteetering_at_seen_pit(trap)) { + dotrap(trap, FORCEBUNGLE); + /* might escape trap and still be teetering at brink */ + if (!u.utrap) cant_reach_floor(u.ux, u.uy, FALSE, TRUE); } else if (!ispick) { pline("%s merely scratches the %s.", Yobjnam2(obj, (char *)0), surface(u.ux,u.uy)); diff --git a/src/do.c b/src/do.c index d125bd4556..931274accb 100644 --- a/src/do.c +++ b/src/do.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)do.c 3.5 2005/03/28 */ +/* SCCS Id: @(#)do.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -482,7 +482,7 @@ register struct obj *obj; return(1); } #endif - if (!can_reach_floor()) { + if (!can_reach_floor(TRUE)) { if(flags.verbose) You("drop %s.", doname(obj)); #ifndef GOLDOBJ if (obj->oclass != COIN_CLASS || obj == invent) freeinv(obj); diff --git a/src/eat.c b/src/eat.c index 04c93328ad..3d06f201b3 100644 --- a/src/eat.c +++ b/src/eat.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)eat.c 3.5 2005/04/08 */ +/* SCCS Id: @(#)eat.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2515,7 +2515,7 @@ floorfood(verb,corpsecheck) /* get food from floor or pack */ boolean feeding = (!strcmp(verb, "eat")); /* if we can't touch floor objects then use invent food only */ - if (!can_reach_floor() || + if (!can_reach_floor(TRUE) || #ifdef STEED (feeding && u.usteed) || /* can't eat off floor while riding */ #endif diff --git a/src/engrave.c b/src/engrave.c index 388253cbb8..0de15e448f 100644 --- a/src/engrave.c +++ b/src/engrave.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)engrave.c 3.5 2005/04/22 */ +/* SCCS Id: @(#)engrave.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -130,8 +130,10 @@ unsigned seed; /* for semi-controlled randomization */ while (lth && engr[lth-1] == ' ') engr[--lth] = 0; } +/* check whether hero can reach something at ground level */ boolean -can_reach_floor() +can_reach_floor(check_pit) +boolean check_pit; { struct trap *t; @@ -140,8 +142,8 @@ can_reach_floor() /* Restricted/unskilled riders can't reach the floor */ if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) return FALSE; #endif - if ((t = t_at(u.ux, u.uy)) != 0 && uteetering_at_seen_pit(t) && - !Flying) + if (check_pit && (t = t_at(u.ux, u.uy)) != 0 && + uteetering_at_seen_pit(t) && !Flying) return FALSE; return (boolean)((!Levitation || @@ -150,6 +152,18 @@ can_reach_floor() u.umonnum == PM_TRAPPER)); } +/* give a message after caller has determined that hero can't reach */ +void +cant_reach_floor(x, y, up, check_pit) +int x, y; +boolean up, check_pit; +{ + You("can't reach the %s.", + up ? ceiling(x, y) : + (check_pit && can_reach_floor(FALSE)) ? "bottom of the pit" : + surface(x, y)); +} + const char * surface(x, y) register int x, y; @@ -246,7 +260,7 @@ void u_wipe_engr(cnt) register int cnt; { - if (can_reach_floor()) + if (can_reach_floor(TRUE)) wipe_engr_at(u.ux, u.uy, cnt); } @@ -292,7 +306,7 @@ register int x,y; break; case ENGRAVE: case HEADSTONE: - if (!Blind || can_reach_floor()) { + if (!Blind || can_reach_floor(TRUE)) { sensed = 1; pline("%s is engraved here on the %s.", Something, @@ -300,7 +314,7 @@ register int x,y; } break; case BURN: - if (!Blind || can_reach_floor()) { + if (!Blind || can_reach_floor(TRUE)) { sensed = 1; pline("Some text has been %s into the %s here.", is_ice(x,y) ? "melted" : "burned", @@ -471,7 +485,7 @@ doengrave() pline("What would you write? \"Jonah was here\"?"); return(0); } else if (is_whirly(u.ustuck->data)) { - You_cant("reach the %s.", surface(u.ux,u.uy)); + cant_reach_floor(u.ux, u.uy, FALSE, FALSE); return(0); } else jello = TRUE; @@ -517,8 +531,8 @@ doengrave() Your("message dissolves..."); return(0); } - if (otmp->oclass != WAND_CLASS && !can_reach_floor()) { - You_cant("reach the %s!", surface(u.ux,u.uy)); + if (otmp->oclass != WAND_CLASS && !can_reach_floor(TRUE)) { + cant_reach_floor(u.ux, u.uy, FALSE, TRUE); return(0); } if (IS_ALTAR(levl[u.ux][u.uy].typ)) { @@ -754,8 +768,8 @@ doengrave() /* type = ENGR_BLOOD wands */ } } else /* end if zappable */ - if (!can_reach_floor()) { - You_cant("reach the %s!", surface(u.ux,u.uy)); + if (!can_reach_floor(TRUE)) { + cant_reach_floor(u.ux, u.uy, FALSE, TRUE); return(0); } break; @@ -870,8 +884,8 @@ doengrave() } if (!ptext) { /* Early exit for some implements. */ - if (otmp->oclass == WAND_CLASS && !can_reach_floor()) - You_cant("reach the %s!", surface(u.ux,u.uy)); + if (otmp->oclass == WAND_CLASS && !can_reach_floor(TRUE)) + cant_reach_floor(u.ux, u.uy, FALSE, TRUE); return(1); } @@ -921,7 +935,7 @@ doengrave() return(1); } else if ( (type != oep->engr_type) || (c == 'n') ) { - if (!Blind || can_reach_floor()) + if (!Blind || can_reach_floor(TRUE)) You("will overwrite the current message."); eow = TRUE; } diff --git a/src/hack.c b/src/hack.c index b53f23f58b..aa673bea2c 100644 --- a/src/hack.c +++ b/src/hack.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)hack.c 3.5 2004/11/11 */ +/* SCCS Id: @(#)hack.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -1944,7 +1944,7 @@ dopickup() There("is nothing here to pick up."); return 0; } - if (!can_reach_floor()) { + if (!can_reach_floor(TRUE)) { if (traphere && uteetering_at_seen_pit(traphere)) You("cannot reach the bottom of the pit."); #ifdef STEED diff --git a/src/invent.c b/src/invent.c index acc0acf360..5ff39261be 100644 --- a/src/invent.c +++ b/src/invent.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)invent.c 3.5 2005/04/06 */ +/* SCCS Id: @(#)invent.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -2257,7 +2257,7 @@ boolean picked_some; } if (dfeature && !drift && !strcmp(dfeature, surface(u.ux,u.uy))) dfeature = 0; /* ice already identifed */ - if (!can_reach_floor()) { + if (!can_reach_floor(TRUE)) { pline("But you can't reach it!"); return(0); } diff --git a/src/lock.c b/src/lock.c index a9d37f97a7..43e9df0afa 100644 --- a/src/lock.c +++ b/src/lock.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)lock.c 3.5 2000/02/06 */ +/* SCCS Id: @(#)lock.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -240,7 +240,7 @@ pick_lock(pick) /* pick a lock with a given object */ pline(no_longer, "hold the", what); reset_pick(); return 0; - } else if (xlock.box && !can_reach_floor()) { + } else if (xlock.box && !can_reach_floor(TRUE)) { pline(no_longer, "reach the", "lock"); reset_pick(); return 0; @@ -290,7 +290,7 @@ pick_lock(pick) /* pick a lock with a given object */ for(otmp = level.objects[cc.x][cc.y]; otmp; otmp = otmp->nexthere) if (Is_box(otmp)) { ++count; - if (!can_reach_floor()) { + if (!can_reach_floor(TRUE)) { You_cant("reach %s from up here.", the(xname(otmp))); return 0; } diff --git a/src/pickup.c b/src/pickup.c index a115df7bbb..bcea28a95c 100644 --- a/src/pickup.c +++ b/src/pickup.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)pickup.c 3.5 2005/04/06 */ +/* SCCS Id: @(#)pickup.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -413,7 +413,7 @@ int what; /* should be a long */ } /* no pickup if levitating & not on air or water level */ - if (!can_reach_floor()) { + if (!can_reach_floor(TRUE)) { if ((multi && !context.run) || (autopickup && !flags.pickup) || (ttmp && uteetering_at_seen_pit(ttmp))) @@ -1464,13 +1464,13 @@ boolean looting; /* loot vs tip */ { const char *verb = looting ? "loot" : "tip"; - if (!can_reach_floor()) { + if (!can_reach_floor(TRUE)) { #ifdef STEED if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) rider_cant_reach(); /* not skilled enough to reach */ else #endif - You("cannot reach the %s.", surface(x, y)); + cant_reach_floor(x, y, FALSE, TRUE); return FALSE; } else if ((is_pool(x, y) && (looting || !Underwater)) || is_lava(x, y)) { @@ -2591,7 +2591,7 @@ struct obj *box; /* or bag */ if (empty_it) { struct obj *otmp, *nobj; boolean verbose = FALSE, - highdrop = !can_reach_floor(), + highdrop = !can_reach_floor(TRUE), altarizing = IS_ALTAR(levl[u.ux][u.uy].typ), cursed_mbag = (Is_mbag(box) && box->cursed); int held = carried(box); diff --git a/src/potion.c b/src/potion.c index f71035b5ca..f376c1f7af 100644 --- a/src/potion.c +++ b/src/potion.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)potion.c 3.5 2005/04/23 */ +/* SCCS Id: @(#)potion.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -342,7 +342,9 @@ dodrink() return 0; } /* Is there a fountain to drink from here? */ - if (IS_FOUNTAIN(levl[u.ux][u.uy].typ) && can_reach_floor()) { + if (IS_FOUNTAIN(levl[u.ux][u.uy].typ) && + /* not as low as floor level but similar restrictions apply */ + can_reach_floor(FALSE)) { if(yn("Drink from the fountain?") == 'y') { drinkfountain(); return 1; @@ -350,7 +352,9 @@ dodrink() } #ifdef SINKS /* Or a kitchen sink? */ - if (IS_SINK(levl[u.ux][u.uy].typ) && can_reach_floor()) { + if (IS_SINK(levl[u.ux][u.uy].typ) && + /* not as low as floor level but similar restrictions apply */ + can_reach_floor(FALSE)) { if (yn("Drink from the sink?") == 'y') { drinksink(); return 1; diff --git a/src/sit.c b/src/sit.c index 4d80b9a340..8d43472580 100644 --- a/src/sit.c +++ b/src/sit.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)sit.c 3.5 2004/12/21 */ +/* SCCS Id: @(#)sit.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -53,7 +53,7 @@ dosit() if (u.uundetected && is_hider(youmonst.data) && u.umonnum != PM_TRAPPER) u.uundetected = 0; /* no longer on the ceiling */ - if (!can_reach_floor()) { + if (!can_reach_floor(FALSE)) { if (Levitation) You("tumble in place."); else @@ -73,16 +73,15 @@ dosit() if (!(Is_box(obj) || objects[obj->otyp].oc_material == CLOTH)) pline("It's not very comfortable..."); - } else if (trap != 0 || - (u.utrap && (u.utraptype >= TT_LAVA))) { - + } else if (trap != 0 || (u.utrap && (u.utraptype >= TT_LAVA))) { if (u.utrap) { exercise(A_WIS, FALSE); /* you're getting stuck longer */ - if(u.utraptype == TT_BEARTRAP) { - You_cant("sit down with your %s in the bear trap.", body_part(FOOT)); + if (u.utraptype == TT_BEARTRAP) { + You_cant("sit down with your %s in the bear trap.", + body_part(FOOT)); u.utrap++; - } else if(u.utraptype == TT_PIT) { - if(trap && trap->ttyp == SPIKED_PIT) { + } else if (u.utraptype == TT_PIT) { + if (trap && trap->ttyp == SPIKED_PIT) { You("sit down on a spike. Ouch!"); losehp(Half_physical_damage ? rn2(2) : 1, "sitting on an iron spike", KILLED_BY); @@ -90,20 +89,21 @@ dosit() } else You("sit down in the pit."); u.utrap += rn2(5); - } else if(u.utraptype == TT_WEB) { + } else if (u.utraptype == TT_WEB) { You("sit in the spider web and get entangled further!"); u.utrap += rn1(10, 5); - } else if(u.utraptype == TT_LAVA) { + } else if (u.utraptype == TT_LAVA) { /* Must have fire resistance or they'd be dead already */ You("sit in the lava!"); u.utrap += rnd(4); losehp(d(2,10), "sitting in lava", KILLED_BY); /* lava damage */ - } else if(u.utraptype == TT_INFLOOR || u.utraptype == TT_BURIEDBALL) { + } else if (u.utraptype == TT_INFLOOR || + u.utraptype == TT_BURIEDBALL) { You_cant("maneuver to sit!"); u.utrap++; } } else { - You("sit down."); + You("sit down."); dotrap(trap, 0); } } else if(Underwater || Is_waterlevel(&u.uz)) { diff --git a/src/trap.c b/src/trap.c index 3d597ed8d2..87e2b7af32 100644 --- a/src/trap.c +++ b/src/trap.c @@ -1,4 +1,4 @@ -/* SCCS Id: @(#)trap.c 3.5 2005/04/13 */ +/* SCCS Id: @(#)trap.c 3.5 2005/06/02 */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /* NetHack may be freely redistributed. See license for details. */ @@ -3268,7 +3268,7 @@ boolean force_failure; } } /* untrappable traps are located on the ground. */ - if (!can_reach_floor()) { + if (!can_reach_floor(TRUE)) { #ifdef STEED if (u.usteed && P_SKILL(P_RIDING) < P_BASIC) You("aren't skilled enough to reach from %s.",