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

Function lookaround

src/hack.c:3897–4059  ·  view source on GitHub ↗

stop running if we see something interesting next to us */ turn around a corner if that is the only way we can proceed */ do not turn left or right twice */

Source from the content-addressed store, hash-verified

3895/* turn around a corner if that is the only way we can proceed */
3896/* do not turn left or right twice */
3897void
3898lookaround(void)
3899{
3900 coordxy x, y;
3901 coordxy i, x0 = 0, y0 = 0, m0 = 1, i0 = 9;
3902 int corrct = 0, noturn = 0;
3903 struct monst *mtmp;
3904
3905 /* Grid bugs stop if trying to move diagonal, even if blind. Maybe */
3906 /* they polymorphed while in the middle of a long move. */
3907 if (NODIAG(u.umonnum) && u.dx && u.dy) {
3908 You("cannot move diagonally.");
3909 nomul(0);
3910 return;
3911 }
3912
3913 if (Blind || svc.context.run == 0)
3914 return;
3915 for (x = u.ux - 1; x <= u.ux + 1; x++)
3916 for (y = u.uy - 1; y <= u.uy + 1; y++) {
3917 boolean infront = (x == u.ux + u.dx && y == u.uy + u.dy);
3918
3919 /* ignore out of bounds, and our own location */
3920 if (!isok(x, y) || u_at(x, y))
3921 continue;
3922 /* (grid bugs) ignore diagonals */
3923 if (NODIAG(u.umonnum) && x != u.ux && y != u.uy)
3924 continue;
3925
3926 /* can we see a monster there? */
3927 if ((mtmp = m_at(x, y)) != 0
3928 && M_AP_TYPE(mtmp) != M_AP_FURNITURE
3929 && M_AP_TYPE(mtmp) != M_AP_OBJECT
3930 && mon_visible(mtmp)) {
3931 /* running movement and not a hostile monster */
3932 /* OR it blocks our move direction and we're not traveling */
3933 if ((svc.context.run != 1 && !is_safemon(mtmp))
3934 || (infront && !svc.context.travel)) {
3935 if (flags.mention_walls)
3936 pline_xy(x, y, "%s blocks your path.",
3937 upstart(a_monnam(mtmp)));
3938 goto stop;
3939 }
3940 }
3941
3942 /* stone is never interesting */
3943 if (levl[x][y].typ == STONE)
3944 continue;
3945 /* ignore the square we're moving away from */
3946 if (x == u.ux - u.dx && y == u.uy - u.dy)
3947 continue;
3948
3949 /* stop for traps, sometimes */
3950 if (avoid_moving_on_trap(x, y,
3951 (infront && svc.context.run > 1))) {
3952 if (svc.context.run == 1)
3953 goto bcorr; /* if you must */
3954 if (infront)

Callers 1

allmain.cFile · 0.85

Calls 15

YouFunction · 0.85
nomulFunction · 0.85
isokFunction · 0.85
mon_visibleFunction · 0.85
is_safemonFunction · 0.85
pline_xyFunction · 0.85
upstartFunction · 0.85
a_monnamFunction · 0.85
avoid_moving_on_trapFunction · 0.85
closed_doorFunction · 0.85
set_msg_xyFunction · 0.85
dist2Function · 0.85

Tested by

no test coverage detected