/** * Make map features known, except wall/lava surrounded by wall/lava */ void cave_known(struct player *p) { int y, x; for (y = 0; y < cave->height; y++) { for (x = 0; x < cave->width; x++) { int d; int xx, yy; int count = 0; /* Check around the grid */ for (d = 0; d < 8; d++) { /* Extract adjacent location */ yy = y + ddy_ddd[d]; xx = x + ddx_ddd[d]; /* Don't count projectable or lava squares */ if (!square_isprojectable(cave, yy, xx) || square_isbright(cave, yy, xx)) ++count; } /* Internal walls not known */ if (count < 8) p->cave->squares[y][x].feat = cave->squares[y][x].feat; } } }
/** * This routine will "darken" all grids in the set passed in. * * In addition, some of these grids will be "unmarked". * * This routine is used (only) by "light_room()" */ static void cave_unlight(struct point_set *ps) { int i; /* Apply flag changes */ for (i = 0; i < ps->n; i++) { int y = ps->pts[i].y; int x = ps->pts[i].x; /* Darken the grid */ if (!square_isbright(cave, y, x)) { sqinfo_off(cave->squares[y][x].info, SQUARE_GLOW); } /* Hack -- Forget "boring" grids */ if (square_isfloor(cave, y, x)) square_forget(cave, y, x); } /* Process the grids */ for (i = 0; i < ps->n; i++) { int y = ps->pts[i].y; int x = ps->pts[i].x; /* Redraw the grid */ square_light_spot(cave, y, x); } }
/** * Light or Darken the town */ void cave_illuminate(struct chunk *c, bool daytime) { int y, x, i; /* Apply light or darkness */ for (y = 0; y < c->height; y++) { for (x = 0; x < c->width; x++) { int d; bool light = false; /* Skip grids with no surrounding floors or stairs */ for (d = 0; d < 9; d++) { /* Extract adjacent (legal) location */ int yy = y + ddy_ddd[d]; int xx = x + ddx_ddd[d]; /* Paranoia */ if (!square_in_bounds_fully(c, yy, xx)) continue; /* Test */ if (square_isfloor(c, yy, xx) || square_isstairs(c, yy, xx)) light = true; } if (!light) continue; /* Only interesting grids at night */ if (daytime || !square_isfloor(c, y, x)) { sqinfo_on(c->squares[y][x].info, SQUARE_GLOW); square_memorize(c, y, x); } else if (!square_isbright(c, y, x)) { sqinfo_off(c->squares[y][x].info, SQUARE_GLOW); square_forget(c, y, x); } } } /* Light shop doorways */ for (y = 0; y < c->height; y++) { for (x = 0; x < c->width; x++) { if (!square_isshop(c, y, x)) continue; for (i = 0; i < 8; i++) { int yy = y + ddy_ddd[i]; int xx = x + ddx_ddd[i]; sqinfo_on(c->squares[yy][xx].info, SQUARE_GLOW); square_memorize(c, yy, xx); } } } /* Fully update the visuals */ player->upkeep->update |= (PU_UPDATE_VIEW | PU_MONSTERS); /* Redraw map, monster list */ player->upkeep->redraw |= (PR_MAP | PR_MONLIST | PR_ITEMLIST); }
/** * Determine if a given grid may be "walked" */ static bool do_cmd_walk_test(int y, int x) { int m_idx = cave->squares[y][x].mon; struct monster *mon = cave_monster(cave, m_idx); /* Allow attack on visible monsters if unafraid */ if (m_idx > 0 && mflag_has(mon->mflag, MFLAG_VISIBLE) && !is_mimicking(mon)) { /* Handle player fear */ if (player_of_has(player, OF_AFRAID)) { /* Extract monster name (or "it") */ char m_name[80]; monster_desc(m_name, sizeof(m_name), mon, MDESC_DEFAULT); /* Message */ msgt(MSG_AFRAID, "You are too afraid to attack %s!", m_name); /* Nope */ return (false); } return (true); } /* If we don't know the grid, allow attempts to walk into it */ if (!square_isknown(cave, y, x)) return true; /* Require open space */ if (!square_ispassable(cave, y, x)) { if (square_isrubble(cave, y, x)) /* Rubble */ msgt(MSG_HITWALL, "There is a pile of rubble in the way!"); else if (square_iscloseddoor(cave, y, x)) /* Door */ return true; else if (square_isbright(cave, y, x)) /* Lava */ msgt(MSG_HITWALL, "The heat of the lava turns you away!"); else /* Wall */ msgt(MSG_HITWALL, "There is a wall in the way!"); /* Cancel repeat */ disturb(player, 0); /* Nope */ return (false); } /* Okay */ return (true); }