lookaround comments

trying to figure this out
This commit is contained in:
Pasi Kallinen
2021-08-12 19:38:29 +03:00
parent 1335eef674
commit 2748ac746e
+21 -1
View File
@@ -2775,7 +2775,7 @@ dopickup(void)
return pickup(-count); return pickup(-count);
} }
/* stop running if we see something interesting */ /* stop running if we see something interesting next to us */
/* turn around a corner if that is the only way we can proceed */ /* turn around a corner if that is the only way we can proceed */
/* do not turn left or right twice */ /* do not turn left or right twice */
void void
@@ -2799,15 +2799,20 @@ lookaround(void)
return; return;
for (x = u.ux - 1; x <= u.ux + 1; x++) for (x = u.ux - 1; x <= u.ux + 1; x++)
for (y = u.uy - 1; y <= u.uy + 1; y++) { for (y = u.uy - 1; y <= u.uy + 1; y++) {
/* ignore out of bounds, and our own location */
if (!isok(x, y) || (x == u.ux && y == u.uy)) if (!isok(x, y) || (x == u.ux && y == u.uy))
continue; continue;
/* (grid bugs) ignore diagonals */
if (NODIAG(u.umonnum) && x != u.ux && y != u.uy) if (NODIAG(u.umonnum) && x != u.ux && y != u.uy)
continue; continue;
/* can we see a monster there? */
if ((mtmp = m_at(x, y)) != 0 if ((mtmp = m_at(x, y)) != 0
&& M_AP_TYPE(mtmp) != M_AP_FURNITURE && M_AP_TYPE(mtmp) != M_AP_FURNITURE
&& M_AP_TYPE(mtmp) != M_AP_OBJECT && M_AP_TYPE(mtmp) != M_AP_OBJECT
&& mon_visible(mtmp)) { && mon_visible(mtmp)) {
/* running movement and not a tame monster */
/* OR it blocks our move direction and we're not traveling */
if ((g.context.run != 1 && !mtmp->mtame) if ((g.context.run != 1 && !mtmp->mtame)
|| (x == u.ux + u.dx && y == u.uy + u.dy || (x == u.ux + u.dx && y == u.uy + u.dy
&& !g.context.travel)) { && !g.context.travel)) {
@@ -2817,15 +2822,20 @@ lookaround(void)
} }
} }
/* stone is never interesting */
if (levl[x][y].typ == STONE) if (levl[x][y].typ == STONE)
continue; continue;
/* ignore the square we're moving away from */
if (x == u.ux - u.dx && y == u.uy - u.dy) if (x == u.ux - u.dx && y == u.uy - u.dy)
continue; continue;
/* more uninteresting terrain */
if (IS_ROCK(levl[x][y].typ) || levl[x][y].typ == ROOM if (IS_ROCK(levl[x][y].typ) || levl[x][y].typ == ROOM
|| IS_AIR(levl[x][y].typ)) { || IS_AIR(levl[x][y].typ)) {
continue; continue;
} else if (closed_door(x, y) || (mtmp && is_door_mappear(mtmp))) { } else if (closed_door(x, y) || (mtmp && is_door_mappear(mtmp))) {
/* a closed door? */
/* ignore if diagonal */
if (x != u.ux && y != u.uy) if (x != u.ux && y != u.uy)
continue; continue;
if (g.context.run != 1) { if (g.context.run != 1) {
@@ -2833,17 +2843,27 @@ lookaround(void)
You("stop in front of the door."); You("stop in front of the door.");
goto stop; goto stop;
} }
/* we're orthonal to a closed door, consider it a corridor */
goto bcorr; goto bcorr;
} else if (levl[x][y].typ == CORR) { } else if (levl[x][y].typ == CORR) {
/* corridor */
bcorr: bcorr:
if (levl[u.ux][u.uy].typ != ROOM) { if (levl[u.ux][u.uy].typ != ROOM) {
/* running or traveling */
if (g.context.run == 1 || g.context.run == 3 if (g.context.run == 1 || g.context.run == 3
|| g.context.run == 8) { || g.context.run == 8) {
/* distance from x,y to location we're moving to */
i = dist2(x, y, u.ux + u.dx, u.uy + u.dy); i = dist2(x, y, u.ux + u.dx, u.uy + u.dy);
/* ignore if not on or directly adjacent to it */
if (i > 2) if (i > 2)
continue; continue;
/* x,y is (adjacent to) the location we're moving to */
/* if we've seen one corridor, and x,y is not directly
orthogonally next to it, mark noturn */
if (corrct == 1 && dist2(x, y, x0, y0) != 1) if (corrct == 1 && dist2(x, y, x0, y0) != 1)
noturn = 1; noturn = 1;
/* if previous x,y was diagonal, now x,y is orthogonal */
/* (or this is the first time we're here) */
if (i < i0) { if (i < i0) {
i0 = i; i0 = i;
x0 = x; x0 = x;