MCPcopy Index your code
hub / github.com/NetHack/NetHack / doopen_indir

Function doopen_indir

src/lock.c:779–923  ·  view source on GitHub ↗

try to open a door in direction u.dx/u.dy */

Source from the content-addressed store, hash-verified

777
778/* try to open a door in direction u.dx/u.dy */
779int
780doopen_indir(coordxy x, coordxy y)
781{
782 coord cc;
783 struct rm *door;
784 boolean portcullis;
785 const char *dirprompt;
786 int res = ECMD_OK;
787
788 if (nohands(gy.youmonst.data)) {
789 You_cant("open anything -- you have no hands!");
790 return ECMD_OK;
791 }
792
793 dirprompt = NULL; /* have get_adjacent_loc() -> getdir() use default */
794 if (u.utrap && u.utraptype == TT_PIT && container_at(u.ux, u.uy, FALSE))
795 dirprompt = "Open where? [.>]";
796
797 if (x > 0 && y >= 0) {
798 /* nonzero <x,y> is used when hero in amorphous form tries to
799 flow under a closed door at <x,y>; the test here was using
800 'y > 0' but that would give incorrect results if doors are
801 ever allowed to be placed on the top row of the map */
802 cc.x = x;
803 cc.y = y;
804 } else if (!get_adjacent_loc(dirprompt, (char *) 0, u.ux, u.uy, &cc)) {
805 return ECMD_OK;
806 }
807
808 /* open at yourself/up/down: switch to loot unless there is a closed
809 door here (possible with Passes_walls) and direction isn't 'down' */
810 if (u_at(cc.x, cc.y) && (u.dz > 0 || !closed_door(u.ux, u.uy)))
811 return doloot();
812
813 /* this used to be done prior to get_adjacent_loc() but doing so was
814 incorrect once open at hero's spot became an alternate way to loot */
815 if (u.utrap && u.utraptype == TT_PIT) {
816 You_cant("reach over the edge of the pit.");
817 return ECMD_OK;
818 }
819
820 if (stumble_on_door_mimic(cc.x, cc.y))
821 return ECMD_TIME;
822
823 /* when choosing a direction is impaired, use a turn
824 regardless of whether a door is successfully targeted */
825 if (Confusion || Stunned)
826 res = ECMD_TIME;
827
828 door = &levl[cc.x][cc.y];
829 portcullis = (is_drawbridge_wall(cc.x, cc.y) >= 0);
830 /* this used to be 'if (Blind)' but using a key skips that so we do too */
831 {
832 int oldglyph = door->glyph;
833 schar oldlastseentyp = update_mapseen_for(cc.x, cc.y);
834
835 newsym(cc.x, cc.y);
836 if (door->glyph != oldglyph

Callers 2

test_moveFunction · 0.85
doopenFunction · 0.85

Calls 15

You_cantFunction · 0.85
container_atFunction · 0.85
get_adjacent_locFunction · 0.85
closed_doorFunction · 0.85
dolootFunction · 0.85
stumble_on_door_mimicFunction · 0.85
is_drawbridge_wallFunction · 0.85
update_mapseen_forFunction · 0.85
newsymFunction · 0.85
is_db_wallFunction · 0.85
ThereFunction · 0.85
pline_TheFunction · 0.85

Tested by 1

test_moveFunction · 0.68